summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-asterisk/luasrc/view/asterisk/dialplans.htm
blob: 217fc6e3cbb23634575d6032136be9be60159939 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<%#
LuCI - Lua Configuration Interface
Copyright 2008 Steven Barth <steven@midlink.org>
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

$Id$

-%>

<%+header%>

<%
	local uci = luci.model.uci.cursor_state()
	local ast = require "luci.asterisk"

	function digit_pattern(s,t)
		return "<code style='padding: 2px; border:1px solid #CCCCCC; background-color: #FFFFFF'%s>%s</code>"
			%{ t and " title='" .. t .. "'" or "", s }
	end

	function rowstyle(i)
		return "cbi-rowstyle-%i" %{
			( i % 2 ) == 0 and 2 or 1
		}
	end

	function format_matches(z)
		local html = { }

		if z.localprefix then
			for _, m in ipairs(z.matches) do
				html[#html+1] =
					digit_pattern(z.localprefix, "local prefix") .. " " ..
					digit_pattern(m)
			end
		end

		if #z.intlmatches > 0 then
			for _, i in ipairs(z.intlmatches) do
				for _, m in ipairs(z.matches) do
					html[#html+1] = "%s %s" %{
						digit_pattern("(%s)" % i, "intl. prefix"),
						digit_pattern(m)
					}
				end
			end
		else
			for _, m in ipairs(z.matches) do
				html[#html+1] = digit_pattern(m)
			end
		end

		return table.concat(html, "; ")
	end
%>


<form method="post" action="<%=luci.dispatcher.build_url("admin", "asterisk", "dialplans")%>" enctype="multipart/form-data">
	<div>
		<script type="text/javascript" src="/luci-static/resources/cbi.js"></script>
		<input type="hidden" name="cbi.submit" value="1" />
		<input type="submit" value="Save" class="hidden" />
	</div>

<div class="cbi-map" id="cbi-asterisk">
	<h2><a id="content" name="content">Outgoing Call Routing</a></h2>
	<div class="cbi-map-descr"></div><!-- tblsection -->
<fieldset class="cbi-section" id="cbi-asterisk-sip">
	<!--<legend>Dialplans</legend>-->
	<div class="cbi-section-descr">
		Here you can manage your dial plans which are used to route outgoing calls from your local extensions.
	</div>

	<% for i, plan in pairs(ast.dialplan.plans()) do %>
	<div class="cbi-section-node">
		<table class="cbi-section-table">
			<tr class="cbi-section-table-titles">
				<th style="text-align: left; padding: 3px" class="cbi-section-table-cell">
					<big>Dialplan <em><%=plan.name%></em></big>
				</th>
				<td>
					<a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans')%>?delplan=<%=plan.name%>">
						<img style="border:none" alt="Remove this dialplan" title="Remove this dialplan" src="/luci-static/resources/cbi/remove.gif" />
					</a>
				</td>
			</tr>

			<!-- dialzones -->
			<% local zones_used = { } %>
			<% for i, zone in ipairs(plan.zones) do zones_used[zone.name] = true %>
			<tr class="cbi-section-table-row <%=rowstyle(i)%>">
				<td style="text-align: left; padding: 3px" class="cbi-section-table-cell">
					<strong>&#x2514; Dialzone <em><%=zone.name%></em></strong>
					<p style="padding-left: 1em; margin-bottom:0">
						Description: <%=zone.description%><br />
						Lines:
						<%=ast.tools.hyperlinks(
							zone.trunks, function(v)
								return luci.dispatcher.build_url("admin", "asterisk", "trunks", "%s") % v:lower()
							end
						)%><br />
						Matches:
						<%=format_matches(zone)%>
					</p>
				</td>
				<td style="width:5%" class="cbi-value-field">
					<a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans', 'out', zone.name)%>">
						<img style="border:none" alt="Edit dialzone" title="Edit dialzone" src="/luci-static/resources/cbi/edit.gif" />
					</a>
					<a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans')%>?delzone.<%=plan.name%>=<%=zone.name%>">
						<img style="border:none" alt="Remove from this dialplan" title="Remove from this dialplan" src="/luci-static/resources/cbi/remove.gif" />
					</a>
				</td>
			</tr>
			<% end %>

			<tr class="cbi-section-table-row">
				<td style="text-align: left; padding: 3px" class="cbi-section-table-cell" colspan="2">
					<hr style="margin-bottom:0.5em; border-width:0 0 1px 0" />
					<select style="width:30%" name="addzone.<%=plan.name%>">
						<option value="">-- Add dialzone --</option>
						<% for _, zone in pairs(ast.dialzone.zones()) do %>
							<% if not zones_used[zone.name] then %>
								<option value="<%=zone.name%>"><%=zone.name%> (<%=zone.description%>)</option>
							<% end %>
						<% end %>
					</select>
					<input type="submit" class="cbi-button cbi-button-add" value=" &raquo; " title="Add Zone ..."/>
					&nbsp; &nbsp;
					<a href="<%=luci.dispatcher.build_url('admin/asterisk/dialplans/zones')%>" class="cbi-title-ref">Manage dialzones</a>
				</td>
			</tr>
			<!-- /dialzones -->

		</table>

		<div class="cbi-section-create cbi-tblsection-create"></div>
	</div>
	<br />
	<% end %>

		<div class="cbi-section-node">
			<div class="cbi-section-create cbi-tblsection-create" style="padding: 3px">
				<h3>Create a new dialplan</h3>
				The name is required and must be unique. It may only contain the characters A-Z, a-z, 0-9 and _ .<br />

				<%- if create_error then %>
					<br /><span style="color:red">Invalid name given!</span><br />
				<% end -%>

				<br />
				<input type="text" class="cbi-section-create-name" name="addplan" style="width:200px" />
				<input type="submit" class="cbi-button cbi-button-add" value="Add dialplan" title="Add dialplan"/>
			</div>
		</div>

	</fieldset>
</div>
</form>
<div class="clear"></div>
<%+footer%>