* CBI updates
This commit is contained in:
parent
e8b87fffb9
commit
e9461f898c
7 changed files with 75 additions and 25 deletions
|
@ -27,6 +27,8 @@ limitations under the License.
|
||||||
module("ffluci.cbi", package.seeall)
|
module("ffluci.cbi", package.seeall)
|
||||||
require("ffluci.template")
|
require("ffluci.template")
|
||||||
require("ffluci.util")
|
require("ffluci.util")
|
||||||
|
require("ffluci.http")
|
||||||
|
require("ffluci.model.uci")
|
||||||
local Template = ffluci.template.Template
|
local Template = ffluci.template.Template
|
||||||
local class = ffluci.util.class
|
local class = ffluci.util.class
|
||||||
local instanceof = ffluci.util.instanceof
|
local instanceof = ffluci.util.instanceof
|
||||||
|
@ -46,8 +48,14 @@ function Node.append(self, obj)
|
||||||
table.insert(self.children, obj)
|
table.insert(self.children, obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Node.parse(self)
|
||||||
|
for k, child in ipairs(self.children) do
|
||||||
|
child:parse()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Node.render(self)
|
function Node.render(self)
|
||||||
ffluci.template.render(self.template, self)
|
ffluci.template.render(self.template)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,14 +73,19 @@ end
|
||||||
function Map.section(self, class, ...)
|
function Map.section(self, class, ...)
|
||||||
if instanceof(class, AbstractSection) then
|
if instanceof(class, AbstractSection) then
|
||||||
local obj = class(...)
|
local obj = class(...)
|
||||||
obj.map = self.config
|
obj.map = self
|
||||||
table.insert(self.children, obj)
|
obj.config = self.config
|
||||||
|
self:append(obj)
|
||||||
return obj
|
return obj
|
||||||
else
|
else
|
||||||
error("class must be a descendent of AbstractSection")
|
error("class must be a descendent of AbstractSection")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Map.read(self)
|
||||||
|
self.ucidata = self.ucidata or ffluci.model.uci.show(self.config)
|
||||||
|
return self.ucidata
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
AbstractSection
|
AbstractSection
|
||||||
|
@ -88,7 +101,8 @@ function AbstractSection.option(self, class, ...)
|
||||||
if instanceof(class, AbstractValue) then
|
if instanceof(class, AbstractValue) then
|
||||||
local obj = class(...)
|
local obj = class(...)
|
||||||
obj.map = self.map
|
obj.map = self.map
|
||||||
table.insert(self.children, obj)
|
obj.config = self.config
|
||||||
|
self:append(obj)
|
||||||
return obj
|
return obj
|
||||||
else
|
else
|
||||||
error("class must be a descendent of AbstractValue")
|
error("class must be a descendent of AbstractValue")
|
||||||
|
@ -137,7 +151,7 @@ end
|
||||||
--[[
|
--[[
|
||||||
AbstractValue - An abstract Value Type
|
AbstractValue - An abstract Value Type
|
||||||
null: Value can be empty
|
null: Value can be empty
|
||||||
valid: A function returning nil if invalid
|
valid: A function returning the value if it is valid otherwise nil
|
||||||
depends: A table of option => value pairs of which one must be true
|
depends: A table of option => value pairs of which one must be true
|
||||||
default: The default value
|
default: The default value
|
||||||
]]--
|
]]--
|
||||||
|
@ -153,6 +167,24 @@ function AbstractValue.__init__(self, option, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function AbstractValue.formvalue(self)
|
||||||
|
local key = "uci."..self.map.config.."."..self.section.."."..self.option
|
||||||
|
return ffluci.http.formvalue(key)
|
||||||
|
end
|
||||||
|
|
||||||
|
function AbstractValue.ucivalue(self)
|
||||||
|
return self.map.read()[self.section][self.option]
|
||||||
|
end
|
||||||
|
|
||||||
|
function AbstractValue.validate(self, value)
|
||||||
|
return ffluci.util.validate(value, nil, nil, self.valid)
|
||||||
|
end
|
||||||
|
|
||||||
|
function AbstractValue.write(self, value)
|
||||||
|
ffluci.model.uci.set(self.config, self.section, self.option, value)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Value - A one-line value
|
Value - A one-line value
|
||||||
maxlength: The maximum length
|
maxlength: The maximum length
|
||||||
|
@ -178,7 +210,7 @@ ListValue = class(AbstractValue)
|
||||||
|
|
||||||
function ListValue.__init__(self, ...)
|
function ListValue.__init__(self, ...)
|
||||||
AbstractValue.__init__(self, ...)
|
AbstractValue.__init__(self, ...)
|
||||||
self.template = "cbi/value"
|
self.template = "cbi/lvalue"
|
||||||
|
|
||||||
self.list = {}
|
self.list = {}
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,6 +54,7 @@ function request_redirect(category, module, action)
|
||||||
redirect(pattern:format(category, module, action))
|
redirect(pattern:format(category, module, action))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Gets form value from key
|
-- Gets form value from key
|
||||||
function formvalue(key, default)
|
function formvalue(key, default)
|
||||||
local c = formvalues()
|
local c = formvalues()
|
||||||
|
|
11
src/ffluci/view/cbi/lvalue.htm
Normal file
11
src/ffluci/view/cbi/lvalue.htm
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<div class="cbi-lvalue">
|
||||||
|
<div class="cbi-lvalue-title"><%=self.title%></div>
|
||||||
|
<div class="cbi-lvalue-field">
|
||||||
|
<select name="<%=self.map.config.."."..self.section.."."..self.option%>">
|
||||||
|
<%for k, v in self.list do%>
|
||||||
|
<option value="<%=k%>"><%=v%></option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="cbi-value-description"><%=self.description%></div>
|
||||||
|
</div>
|
|
@ -1,7 +1,7 @@
|
||||||
<div class="cbi-map" id="cbi-<%=config%>">
|
<div class="cbi-map" id="cbi-<%=self.config%>">
|
||||||
<form method="post" action="<%=os.getenv("REQUEST_URI")%>">
|
<form method="post" action="<%=os.getenv("REQUEST_URI")%>">
|
||||||
<h1><%=title%></h1>
|
<h1><%=self.title%></h1>
|
||||||
<div class="cbi-map-descr"><%=description%></div>
|
<div class="cbi-map-descr"><%=self.description%></div>
|
||||||
<% for k, node in ipairs(children) do node:render() end %>
|
<% for k, node in ipairs(self.children) do node:render() end %>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<div class="cbi-nsection" id="cbi-<%=map.config%>-<%=sectiontype%>-<%=section%>">
|
<div class="cbi-nsection" id="cbi-<%=self.map.config%>-<%=self.sectiontype%>-<%=self.section%>">
|
||||||
<h2><%=title%></h2>
|
<h2><%=self.title%></h2>
|
||||||
<div class="cbi-nsection-descr"><%=description%></div>
|
<div class="cbi-nsection-descr"><%=self.description%></div>
|
||||||
<% for k, node in ipairs(children) do node:render() end %>
|
<% for k, node in ipairs(self.children) do node:render() end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<%
|
<%
|
||||||
require("ffluci.model.uci")
|
local allsections = self.map:read()
|
||||||
local allsections = ffluci.model.uci.show(map)
|
|
||||||
local sections = {}
|
local sections = {}
|
||||||
for k, v in pairs(allsections) do
|
for k, v in pairs(allsections) do
|
||||||
if v[".type"] == sectiontype then
|
if v[".type"] == sectiontype then
|
||||||
|
@ -8,12 +7,12 @@ for k, v in pairs(allsections) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
%>
|
%>
|
||||||
<div class="cbi-tsection" id="cbi-<%=map%>-<%=sectiontype%>">
|
<div class="cbi-tsection" id="cbi-<%=self.map.config%>-<%=self.sectiontype%>">
|
||||||
<h2><%=title%></h2>
|
<h2><%=self.title%></h2>
|
||||||
<div class="cbi-tsection-descr"><%=description%></div>
|
<div class="cbi-tsection-descr"><%=self.description%></div>
|
||||||
<% for k, v in pairs(sections) do %>
|
<% for k, v in pairs(sections) do %>
|
||||||
<div class="cbi-tsection-node" id="cbi-<%=map%>-<%=k%>">
|
<div class="cbi-tsection-node" id="cbi-<%=self.map.config%>-<%=k%>">
|
||||||
<% for k, node in ipairs(children) do
|
<% for k, node in ipairs(self.children) do
|
||||||
node.section = k
|
node.section = k
|
||||||
node:render(k)
|
node:render(k)
|
||||||
end %>
|
end %>
|
||||||
|
|
7
src/ffluci/view/cbi/value.htm
Normal file
7
src/ffluci/view/cbi/value.htm
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<div class="cbi-value">
|
||||||
|
<div class="cbi-value-title"><%=self.title%></div>
|
||||||
|
<div class="cbi-value-field">
|
||||||
|
<input type="text" name="<%=self.map.config.."."..self.section.."."..self.option%>" value="<%=self:ucivalue()%>" />
|
||||||
|
</div>
|
||||||
|
<div class="cbi-value-description"><%=self.description%></div>
|
||||||
|
</div>
|
Loading…
Reference in a new issue