Globally reduce copyright headers
[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 <xm@leipzig.freifunk.net>
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="<%=luci.dispatcher.build_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><a id="content" name="content">Dial Zone Management</a></h2>
59         <div class="cbi-map-descr">
60                 <a href="<%=luci.dispatcher.build_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                         <table class="cbi-section-table">
70                                 <tr class="cbi-section-table-titles">
71                                         <th style="text-align: left; padding: 3px" class="cbi-section-table-cell" colspan="6">
72                                                 <h3>Dialzone Overview</h3>
73                                         </th>
74                                 </tr>
75
76                                 <tr class="cbi-section-table-descr">
77                                         <th style="width: 5%; text-align:right" class="cbi-section-table-cell">Name</th>
78                                         <th style="width: 5%; text-align:right" class="cbi-section-table-cell">Prepend</th>
79                                         <th style="width: 20%; text-align:left" class="cbi-section-table-cell">- Match</th>
80                                         <th style="text-align:left" class="cbi-section-table-cell">Trunk</th>
81                                         <th style="width: 35%; text-align:left" class="cbi-section-table-cell">Description</th>
82                                         <th style="width: 4%; text-align:left" class="cbi-section-table-cell"></th>
83                                 </tr>
84
85                                 <% for i, rule in pairs(ast.dialzone.zones()) do %>
86                                 <tr class="cbi-section-table-row <%=rowstyle(i)%>">
87                                         <td style="text-align:right" class="cbi-value-field">
88                                                 <%=rule.name%>
89                                         </td>
90                                         <td style="text-align:right" class="cbi-value-field">
91                                                 <% for _ in ipairs(rule.matches) do %>
92                                                         <%=rule.addprefix and digit_pattern(rule.addprefix)%>&#160;<br />
93                                                 <% end %>
94                                         </td>
95                                         <td style="text-align:left" class="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                                         </td>
101                                         <td style="text-align:left" class="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                                         </td>
108                                         <td style="text-align:left" class="cbi-value-field">
109                                                 <%=rule.description or rule.name%>
110                                         </td>
111                                         <td style="text-align:left" class="cbi-value-field">
112                                                 <a href="<%=luci.dispatcher.build_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="<%=luci.dispatcher.build_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                                         </td>
119                                 </tr>
120                                 <% end %>
121                         </table>
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                                 <table>
137                                         <tr>
138                                                 <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                                                 </td>
146                                                 <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                                                 </td>
154                                         </tr>
155                                 </table>
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%>