summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/ffluci/cbi.lua52
-rw-r--r--src/ffluci/http.lua1
-rw-r--r--src/ffluci/view/cbi/lvalue.htm11
-rw-r--r--src/ffluci/view/cbi/map.htm8
-rw-r--r--src/ffluci/view/cbi/nsection.htm8
-rw-r--r--src/ffluci/view/cbi/tsection.htm13
-rw-r--r--src/ffluci/view/cbi/value.htm7
7 files changed, 75 insertions, 25 deletions
diff --git a/src/ffluci/cbi.lua b/src/ffluci/cbi.lua
index a346dd7072..149c1d70fa 100644
--- a/src/ffluci/cbi.lua
+++ b/src/ffluci/cbi.lua
@@ -27,6 +27,8 @@ limitations under the License.
module("ffluci.cbi", package.seeall)
require("ffluci.template")
require("ffluci.util")
+require("ffluci.http")
+require("ffluci.model.uci")
local Template = ffluci.template.Template
local class = ffluci.util.class
local instanceof = ffluci.util.instanceof
@@ -46,8 +48,14 @@ function Node.append(self, obj)
table.insert(self.children, obj)
end
+function Node.parse(self)
+ for k, child in ipairs(self.children) do
+ child:parse()
+ end
+end
+
function Node.render(self)
- ffluci.template.render(self.template, self)
+ ffluci.template.render(self.template)
end
@@ -64,15 +72,20 @@ end
function Map.section(self, class, ...)
if instanceof(class, AbstractSection) then
- local obj = class(...)
- obj.map = self.config
- table.insert(self.children, obj)
+ local obj = class(...)
+ obj.map = self
+ obj.config = self.config
+ self:append(obj)
return obj
else
error("class must be a descendent of AbstractSection")
end
end
+function Map.read(self)
+ self.ucidata = self.ucidata or ffluci.model.uci.show(self.config)
+ return self.ucidata
+end
--[[
AbstractSection
@@ -86,9 +99,10 @@ end
function AbstractSection.option(self, class, ...)
if instanceof(class, AbstractValue) then
- local obj = class(...)
- obj.map = self.map
- table.insert(self.children, obj)
+ local obj = class(...)
+ obj.map = self.map
+ obj.config = self.config
+ self:append(obj)
return obj
else
error("class must be a descendent of AbstractValue")
@@ -137,7 +151,7 @@ end
--[[
AbstractValue - An abstract Value Type
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
default: The default value
]]--
@@ -151,7 +165,25 @@ function AbstractValue.__init__(self, option, ...)
self.depends = nil
self.default = nil
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
@@ -178,7 +210,7 @@ ListValue = class(AbstractValue)
function ListValue.__init__(self, ...)
AbstractValue.__init__(self, ...)
- self.template = "cbi/value"
+ self.template = "cbi/lvalue"
self.list = {}
end
diff --git a/src/ffluci/http.lua b/src/ffluci/http.lua
index 5e177195e1..bf94105734 100644
--- a/src/ffluci/http.lua
+++ b/src/ffluci/http.lua
@@ -54,6 +54,7 @@ function request_redirect(category, module, action)
redirect(pattern:format(category, module, action))
end
+
-- Gets form value from key
function formvalue(key, default)
local c = formvalues()
diff --git a/src/ffluci/view/cbi/lvalue.htm b/src/ffluci/view/cbi/lvalue.htm
new file mode 100644
index 0000000000..b7db0def96
--- /dev/null
+++ b/src/ffluci/view/cbi/lvalue.htm
@@ -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> \ No newline at end of file
diff --git a/src/ffluci/view/cbi/map.htm b/src/ffluci/view/cbi/map.htm
index 918e455d75..e4f493bd09 100644
--- a/src/ffluci/view/cbi/map.htm
+++ b/src/ffluci/view/cbi/map.htm
@@ -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")%>">
-<h1><%=title%></h1>
-<div class="cbi-map-descr"><%=description%></div>
-<% for k, node in ipairs(children) do node:render() end %>
+<h1><%=self.title%></h1>
+<div class="cbi-map-descr"><%=self.description%></div>
+<% for k, node in ipairs(self.children) do node:render() end %>
</form>
</div>
diff --git a/src/ffluci/view/cbi/nsection.htm b/src/ffluci/view/cbi/nsection.htm
index 4a47c7dad4..4607a872cc 100644
--- a/src/ffluci/view/cbi/nsection.htm
+++ b/src/ffluci/view/cbi/nsection.htm
@@ -1,5 +1,5 @@
-<div class="cbi-nsection" id="cbi-<%=map.config%>-<%=sectiontype%>-<%=section%>">
-<h2><%=title%></h2>
-<div class="cbi-nsection-descr"><%=description%></div>
-<% for k, node in ipairs(children) do node:render() end %>
+<div class="cbi-nsection" id="cbi-<%=self.map.config%>-<%=self.sectiontype%>-<%=self.section%>">
+<h2><%=self.title%></h2>
+<div class="cbi-nsection-descr"><%=self.description%></div>
+<% for k, node in ipairs(self.children) do node:render() end %>
</div>
diff --git a/src/ffluci/view/cbi/tsection.htm b/src/ffluci/view/cbi/tsection.htm
index 2c25500f8a..420bfd14a8 100644
--- a/src/ffluci/view/cbi/tsection.htm
+++ b/src/ffluci/view/cbi/tsection.htm
@@ -1,6 +1,5 @@
<%
-require("ffluci.model.uci")
-local allsections = ffluci.model.uci.show(map)
+local allsections = self.map:read()
local sections = {}
for k, v in pairs(allsections) do
if v[".type"] == sectiontype then
@@ -8,12 +7,12 @@ for k, v in pairs(allsections) do
end
end
%>
-<div class="cbi-tsection" id="cbi-<%=map%>-<%=sectiontype%>">
-<h2><%=title%></h2>
-<div class="cbi-tsection-descr"><%=description%></div>
+<div class="cbi-tsection" id="cbi-<%=self.map.config%>-<%=self.sectiontype%>">
+<h2><%=self.title%></h2>
+<div class="cbi-tsection-descr"><%=self.description%></div>
<% for k, v in pairs(sections) do %>
-<div class="cbi-tsection-node" id="cbi-<%=map%>-<%=k%>">
-<% for k, node in ipairs(children) do
+<div class="cbi-tsection-node" id="cbi-<%=self.map.config%>-<%=k%>">
+<% for k, node in ipairs(self.children) do
node.section = k
node:render(k)
end %>
diff --git a/src/ffluci/view/cbi/value.htm b/src/ffluci/view/cbi/value.htm
new file mode 100644
index 0000000000..a39010ac8d
--- /dev/null
+++ b/src/ffluci/view/cbi/value.htm
@@ -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> \ No newline at end of file