Merge pull request #1827 from Ansuel/luci-map
[project/luci.git] / applications / luci-app-asterisk / luasrc / view / asterisk / dialzones.htm
1 <%#
2 Copyright 2008 Steven Barth <steven@midlink.org>
3 Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
4 Licensed to the public under the Apache License 2.0.
5 -%>
6
7 <%+header%>
8
9 <%
10 local uci = luci.model.uci.cursor_state()
11 local ast = require("luci.asterisk")
12
13 function digit_pattern(s)
14 return "<code style='padding: 2px; border:1px solid #CCCCCC; background-color: #FFFFFF'>%s</code>" % s
15 end
16
17 function rowstyle(i)
18 return "cbi-rowstyle-%i" %{
19 ( i % 2 ) == 0 and 2 or 1
20 }
21 end
22
23 local function find_trunks()
24 local t = { }
25
26 uci:foreach("asterisk", "sip",
27 function(s)
28 if uci:get_bool("asterisk", s['.name'], "provider") then
29 t[#t+1] = {
30 "SIP/%s" % s['.name'],
31 "SIP: %s" % s['.name']
32 }
33 end
34 end)
35
36 uci:foreach("asterisk", "iax",
37 function(s)
38 t[#t+1] = {
39 "IAX/%s" % s['.name'],
40 "IAX: %s" % s.extension or s['.name']
41 }
42 end)
43
44 return t
45 end
46
47 %>
48
49
50 <form method="post" action="<%=url('admin/asterisk/dialplans/zones')%>" enctype="multipart/form-data">
51 <div>
52 <script type="text/javascript" src="/luci-static/resources/cbi.js"></script>
53 <input type="hidden" name="cbi.submit" value="1" />
54 <input type="submit" value="Save" class="hidden" />
55 </div>
56
57 <div class="cbi-map" id="cbi-asterisk">
58 <h2 name="content">Dial Zone Management</h2>
59 <div class="cbi-map-descr">
60 <a href="<%=url("admin/asterisk/dialplans")%>" class="cbi-title-ref">Back to dialplan overview</a><br /><br />
61 Here you can manage your dial zones. The zones are used to route outgoing calls to the destination.
62 Each zone groups multiple trunks and number matches to represent a logical destination. Zones can
63 also be used to enforce certain dial restrictions on selected extensions.
64 </div>
65
66 <!-- tblsection -->
67 <fieldset class="cbi-section" id="cbi-asterisk-sip">
68 <div class="cbi-section-node">
69 <div class="table cbi-section-table">
70 <div class="tr cbi-section-table-titles">
71 <div style="text-align: left; padding: 3px" class="th cbi-section-table-cell" colspan="6">
72 <h3>Dialzone Overview</h3>
73 </div>
74 </div>
75
76 <div class="tr cbi-section-table-descr">
77 <div style="width: 5%; text-align:right" class="th cbi-section-table-cell">Name</div>
78 <div style="width: 5%; text-align:right" class="th cbi-section-table-cell">Prepend</div>
79 <div style="width: 20%; text-align:left" class="th cbi-section-table-cell">- Match</div>
80 <div style="text-align:left" class="th cbi-section-table-cell">Trunk</div>
81 <div style="width: 35%; text-align:left" class="th cbi-section-table-cell">Description</div>
82 <div style="width: 4%; text-align:left" class="th cbi-section-table-cell"></div>
83 </div>
84
85 <% for i, rule in pairs(ast.dialzone.zones()) do %>
86 <div class="tr cbi-section-table-row <%=rowstyle(i)%>">
87 <div style="text-align:right" class="td cbi-value-field">
88 <%=rule.name%>
89 </div>
90 <div style="text-align:right" class="td cbi-value-field">
91 <% for _ in ipairs(rule.matches) do %>
92 <%=rule.addprefix and digit_pattern(rule.addprefix)%>&#160;<br />
93 <% end %>
94 </div>
95 <div style="text-align:left" class="td cbi-value-field">
96 <% for _, m in ipairs(rule.matches) do %>
97 <%=rule.localprefix and "%s " % digit_pattern(rule.localprefix)%>
98 <%=digit_pattern(m)%><br />
99 <% end %>
100 </div>
101 <div style="text-align:left" class="td cbi-value-field">
102 <%=ast.tools.hyperlinks(
103 rule.trunks, function(v)
104 return luci.dispatcher.build_url("admin", "asterisk", "trunks", "%s") % v:lower()
105 end
106 )%>
107 </div>
108 <div style="text-align:left" class="td cbi-value-field">
109 <%=rule.description or rule.name%>
110 </div>
111 <div style="text-align:left" class="td cbi-value-field">
112 <a href="<%=url('admin/asterisk/dialplans/out', rule.name)%>">
113 <img style="border:none" alt="Edit entry" title="Edit entry" src="/luci-static/resources/cbi/edit.gif" />
114 </a>
115 <a href="<%=url('admin/asterisk/dialplans/zones')%>?delzone=<%=rule.name%>">
116 <img style="border:none" alt="Delete entry" title="Delete entry" src="/luci-static/resources/cbi/remove.gif" />
117 </a>
118 </div>
119 </div>
120 <% end %>
121 </div>
122 <div class="cbi-section-create cbi-tblsection-create"></div>
123 </div>
124 <br />
125
126 <div class="cbi-section-node">
127 <div class="cbi-section-create cbi-tblsection-create" style="padding: 3px">
128 <h3>Create a new dialzone</h3>
129 The name is required and must be unique. It may only contain the characters A-Z, a-z, 0-9 and _ .<br />
130 You can specifiy multiple number matches by separating them with spaces.<br />
131
132 <%- if create_error then %>
133 <br /><span style="color:red">Invalid name given!</span><br />
134 <% end -%>
135
136 <div class="table">
137 <div class="tr">
138 <div class="td" style="padding:3px">
139 <label for="create1">1) Name</label><br />
140 <input type="text" class="cbi-section-create-name" id="create1" name="newzone_name" style="width:200px" />
141 <br /><br />
142
143 <label for="create2">2) Number Match</label><br />
144 <input type="text" class="cbi-section-create-name" id="create2" name="newzone_match" style="width:200px" />
145 </div>
146 <div class="td" style="padding:3px">
147 <label for="create3">3) Trunks</label><br />
148 <select class="cbi-input-select" multiple="multiple" id="create3" name="newzone_uses" size="4" style="width:200px">
149 <% for i, t in ipairs(find_trunks()) do %>
150 <option value="<%=t[1]%>"><%=t[2]%></option>
151 <% end %>
152 </select>
153 </div>
154 </div>
155 </div>
156 <br />
157
158 <input type="submit" class="cbi-button cbi-button-add" name="newzone" value="Add entry" title="Add entry"/>
159 </div>
160 </div>
161 </fieldset>
162 </div>
163 </form>
164 <div class="clear"></div>
165 <%+footer%>