Merge pull request #278 from nmav/ocserv
[project/luci.git] / applications / luci-asterisk / luasrc / model / cbi / asterisk / voicemail.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>
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 local ast = require "luci.asterisk"
16
17 cbimap = Map("asterisk", "Voicemail - Mailboxes")
18
19 voicemail = cbimap:section(TypedSection, "voicemail", "Voicemail Boxes")
20 voicemail.addremove = true
21 voicemail.anonymous = true
22 voicemail.template = "cbi/tblsection"
23
24 context = voicemail:option(ListValue, "context", "Context")
25 context:value("default")
26
27 number = voicemail:option(Value, "number",
28         "Mailbox Number", "Unique mailbox identifier")
29
30 function number.write(self, s, val)
31         if val and #val > 0 then
32                 local old = self:cfgvalue(s)
33                 self.map.uci:foreach("asterisk", "dialplanvoice",
34                         function(v)
35                                 if v.voicebox == old then
36                                         self.map:set(v['.name'], "voicebox", val)
37                                 end
38                         end)
39                 Value.write(self, s, val)
40         end
41 end
42
43
44 voicemail:option(Value, "name", "Ownername", "Human readable display name")
45 voicemail:option(Value, "password", "Password", "Access protection")
46 voicemail:option(Value, "email", "eMail", "Where to send voice messages")
47 voicemail:option(Value, "page", "Pager", "Pager number")
48
49 zone = voicemail:option(ListValue, "zone", "Timezone", "Used time format")
50 zone.titleref = luci.dispatcher.build_url("admin/asterisk/voicemail/settings")
51 cbimap.uci:foreach("asterisk", "voicezone",
52         function(s) zone:value(s['.name']) end)
53
54 function voicemail.remove(self, s)
55         return ast.voicemail.remove(self.map:get(s, "number"), self.map.uci)
56 end
57
58
59 return cbimap