protocols/core: remove uneeded requires from luci.tools.proto
[project/luci.git] / protocols / core / luasrc / tools / proto.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2012 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 ]]--
13
14 module("luci.tools.proto", package.seeall)
15
16 function opt_macaddr(s, ifc, ...)
17 local v = luci.cbi.Value
18 local o = s:taboption("advanced", v, "macaddr", ...)
19
20 o.placeholder = ifc and ifc:mac()
21 o.datatype = "macaddr"
22
23 function o.cfgvalue(self, section)
24 local w = ifc and ifc:get_wifinet()
25 if w then
26 return w:get("macaddr")
27 else
28 return v.cfgvalue(self, section)
29 end
30 end
31
32 function o.write(self, section, value)
33 local w = ifc and ifc:get_wifinet()
34 if w then
35 w:set("macaddr", value)
36 elseif value then
37 v.write(self, section, value)
38 else
39 v.remove(self, section)
40 end
41 end
42
43 function o.remove(self, section)
44 self:write(self, section, nil)
45 end
46 end