3ffe6c5eec8ba7eccd42f66ca42beaac62dd3bb4
[project/luci.git] / applications / luci-asterisk / luasrc / view / asterisk / dialplans.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15
16 <%+header%>
17
18 <%
19 local uci = luci.model.uci.cursor_state()
20 local ast = require "luci.asterisk"
21
22 function digit_pattern(s,t)
23 return "<code style='padding: 2px; border:1px solid #CCCCCC; background-color: #FFFFFF'%s>%s</code>"
24 %{ t and " title='" .. t .. "'" or "", s }
25 end
26
27 function rowstyle(i)
28 return "cbi-rowstyle-%i" %{
29 ( i % 2 ) == 0 and 2 or 1
30 }
31 end
32
33 function format_matches(z)
34 local html = { }
35
36 if type(z) ~= "table" then
37 z = { matches = { z } }
38 end
39
40 if z.localprefix then
41 for _, m in ipairs(z.matches) do
42 html[#html+1] =
43 digit_pattern(z.localprefix, "local prefix") .. " " ..
44 digit_pattern(m)
45 end
46 end
47
48 if z.intlmatches and #z.intlmatches > 0 then
49 for _, i in ipairs(z.intlmatches) do
50 for _, m in ipairs(z.matches) do
51 html[#html+1] = "%s %s" %{
52 digit_pattern("(%s)" % i, "intl. prefix"),
53 digit_pattern(m)
54 }
55 end
56 end
57 else
58 for _, m in ipairs(z.matches) do
59 html[#html+1] = digit_pattern(m)
60 end
61 end
62
63 return table.concat(html, "; ")
64 end
65 %>
66
67
68 <form method="post" action="<%=luci.dispatcher.build_url("admin", "asterisk", "dialplans")%>" enctype="multipart/form-data">
69 <div>
70 <script type="text/javascript" src="/luci-static/resources/cbi.js"></script>
71 <input type="hidden" name="cbi.submit" value="1" />
72 <input type="submit" value="Save" class="hidden" />
73 </div>
74
75 <div class="cbi-map" id="cbi-asterisk">
76 <h2><a id="content" name="content">Outgoing Call Routing</a></h2>
77 <div class="cbi-map-descr">
78 Here you can manage your dial plans which are used to route outgoing calls from your local extensions.<br /><br />
79 Related tasks:<br />
80 <a href="<%=luci.dispatcher.build_url('admin/asterisk/dialplans/zones')%>" class="cbi-title-ref">Manage dialzones</a> |
81 <a href="<%=luci.dispatcher.build_url('admin/asterisk/dialplans/zones')%>" class="cbi-title-ref">Manage voicemailboxes</a>
82 </div>
83 <!-- tblsection -->
84 <fieldset class="cbi-section" id="cbi-asterisk-sip">
85 <!--<legend>Dialplans</legend>-->
86 <div class="cbi-section-descr"></div>
87
88 <% for i, plan in pairs(ast.dialplan.plans()) do %>
89 <div class="cbi-section-node">
90 <table class="cbi-section-table">
91 <tr class="cbi-section-table-titles">
92 <th style="text-align: left; padding: 3px" class="cbi-section-table-cell">
93 <big>Dialplan <em><%=plan.name%></em></big>
94 </th>
95 <td>
96 <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans')%>?delplan=<%=plan.name%>">
97 <img style="border:none" alt="Remove this dialplan" title="Remove this dialplan" src="/luci-static/resources/cbi/remove.gif" />
98 </a>
99 </td>
100 </tr>
101
102 <!-- dialzones -->
103 <% local zones_used = { }; local row = 0 %>
104 <% for i, zone in ipairs(plan.zones) do zones_used[zone.name] = true %>
105 <tr class="cbi-section-table-row <%=rowstyle(row)%>">
106 <td style="text-align: left; padding: 3px" class="cbi-section-table-cell">
107 <strong>&#x2514; Dialzone <em><%=zone.name%></em></strong> (<%=zone.description%>)
108 <p style="padding-left: 1em; margin-bottom:0">
109 Lines:
110 <%=ast.tools.hyperlinks(
111 zone.trunks, function(v)
112 return luci.dispatcher.build_url("admin", "asterisk", "trunks", "%s") % v:lower()
113 end
114 )%><br />
115 Matches:
116 <%=format_matches(zone)%>
117 </p>
118 </td>
119 <td style="width:5%" class="cbi-value-field">
120 <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans', 'out', zone.name)%>">
121 <img style="border:none" alt="Edit dialzone" title="Edit dialzone" src="/luci-static/resources/cbi/edit.gif" />
122 </a>
123 <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans')%>?delzone.<%=plan.name%>=<%=zone.name%>">
124 <img style="border:none" alt="Remove from this dialplan" title="Remove from this dialplan" src="/luci-static/resources/cbi/remove.gif" />
125 </a>
126 </td>
127 </tr>
128 <% row = row + 1; end %>
129 <!-- /dialzones -->
130
131 <!-- voicemail -->
132 <% local boxes_used = { } %>
133 <% for ext, box in luci.util.kspairs(plan.voicemailboxes) do boxes_used[box.id] = true %>
134 <tr class="cbi-section-table-row <%=rowstyle(row)%>">
135 <td style="text-align: left; padding: 3px" class="cbi-section-table-cell">
136 <strong>&#x2514; Voicemailbox <em><%=box.id%></em></strong> (<%=box.name%>)
137 <p style="padding-left: 1em; margin-bottom:0">
138 Owner: <%=box.name%> |
139 eMail: <%=#box.email > 0 and box.email or 'n/a'%> |
140 Pager: <%=#box.page > 0 and box.page or 'n/a'%><br />
141 Matches: <%=format_matches(ext)%>
142 </p>
143 </td>
144 <td style="width:5%" class="cbi-value-field">
145 <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans', 'out', box.name)%>">
146 <img style="border:none" alt="Edit dialzone" title="Edit dialzone" src="/luci-static/resources/cbi/edit.gif" />
147 </a>
148 <a href="<%=luci.dispatcher.build_url('admin', 'asterisk', 'dialplans')%>?delvbox.<%=plan.name%>=<%=ext%>">
149 <img style="border:none" alt="Remove from this dialplan" title="Remove from this dialplan" src="/luci-static/resources/cbi/remove.gif" />
150 </a>
151 </td>
152 </tr>
153 <% row = row + 1; end %>
154 <!-- /voicemail -->
155
156 <tr class="cbi-section-table-row">
157 <td style="text-align: left; padding: 3px" class="cbi-section-table-cell" colspan="2">
158 <hr style="margin-bottom:0.5em; border-width:0 0 1px 0" />
159
160 Add Dialzone:<br />
161 <select style="width:30%" name="addzone.<%=plan.name%>">
162 <option value="">-- please select --</option>
163 <% for _, zone in pairs(ast.dialzone.zones()) do %>
164 <% if not zones_used[zone.name] then %>
165 <option value="<%=zone.name%>"><%=zone.name%> (<%=zone.description%>)</option>
166 <% end %>
167 <% end %>
168 </select>
169 <br /><br />
170
171 Add Voicemailbox:<br />
172 <select style="width:20%" name="addvbox.<%=plan.name%>" onchange="this.form['addvboxext.<%=plan.name%>'].value=this.options[this.selectedIndex].value.split('@')[0]">
173 <option value="">-- please select --</option>
174 <% for ext, box in pairs(ast.voicemail.boxes()) do %>
175 <% if not boxes_used[box.id] then %>
176 <option value="<%=box.id%>"><%=box.id%> (<%=box.name%>)</option>
177 <% end %>
178 <% end %>
179 </select>
180 as extension
181 <input type="text" style="width:5%" name="addvboxext.<%=plan.name%>" />
182 <br /><br />
183
184 <input type="submit" class="cbi-button cbi-button-add" value="Add item &raquo;" title="Add item ..."/>
185 </td>
186 </tr>
187
188 </table>
189
190 <div class="cbi-section-create cbi-tblsection-create"></div>
191 </div>
192 <br />
193 <% end %>
194
195 <div class="cbi-section-node">
196 <div class="cbi-section-create cbi-tblsection-create" style="padding: 3px">
197 <h3>Create a new dialplan</h3>
198 The name is required and must be unique. It may only contain the characters A-Z, a-z, 0-9 and _ .<br />
199
200 <%- if create_error then %>
201 <br /><span style="color:red">Invalid name given!</span><br />
202 <% end -%>
203
204 <br />
205 <input type="text" class="cbi-section-create-name" name="addplan" style="width:200px" />
206 <input type="submit" class="cbi-button cbi-button-add" value="Add dialplan" title="Add dialplan"/>
207 </div>
208 </div>
209
210 </fieldset>
211 </div>
212 </form>
213 <div class="clear"></div>
214 <%+footer%>