Merge pull request #1709 from dibdot/get_interface-fix
[project/luci.git] / modules / luci-base / luasrc / tools / proto.lua
1 -- Copyright 2012 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 module("luci.tools.proto", package.seeall)
5
6 function opt_macaddr(s, ifc, ...)
7         local v = luci.cbi.Value
8         local o = s:taboption("advanced", v, "macaddr", ...)
9
10         o.placeholder = ifc and ifc:mac()
11         o.datatype    = "macaddr"
12
13         function o.cfgvalue(self, section)
14                 local w = ifc and ifc:get_wifinet()
15                 if w then
16                         return w:get("macaddr")
17                 else
18                         return v.cfgvalue(self, section)
19                 end
20         end
21
22         function o.write(self, section, value)
23                 local w = ifc and ifc:get_wifinet()
24                 if w then
25                         w:set("macaddr", value)
26                 elseif value then
27                         v.write(self, section, value)
28                 else
29                         v.remove(self, section)
30                 end
31         end
32
33         function o.remove(self, section)
34                 self:write(section, nil)
35         end
36 end