self.template = "cbi/map"
end
+function Map.parse(self)
+ self.ucidata = ffluci.model.uci.show(self.config)
+ if not self.ucidata then
+ error("Unable to read UCI data: " .. self.config)
+ else
+ self.ucidata = self.ucidata[self.config]
+ end
+ Node.parse(self)
+end
+
+function Map.render(self)
+ self.ucidata = ffluci.model.uci.show(self.config)
+ if not self.ucidata then
+ error("Unable to read UCI data: " .. self.config)
+ else
+ self.ucidata = self.ucidata[self.config]
+ end
+ Node.render(self)
+end
+
function Map.section(self, class, ...)
if instanceof(class, AbstractSection) then
local obj = class(...)
end
end
-function Map.read(self)
- self.ucidata = self.ucidata or ffluci.model.uci.show(self.config)[self.config]
- return self.ucidata
-end
-
--[[
AbstractSection
]]--
self.valid = nil
end
+function TypedSection.parse(self)
+ for k, v in pairs(self:ucisections()) do
+ for i, node in ipairs(self.children) do
+ node.section = k
+ node:parse()
+ end
+ end
+end
+
function TypedSection.render_children(self, section)
for k, node in ipairs(self.children) do
node.section = section
function TypedSection.ucisections(self)
local sections = {}
- for k, v in pairs(self.map:read()) do
+ for k, v in pairs(self.map.ucidata) do
if v[".type"] == self.sectiontype then
sections[k] = v
end
self.default = nil
end
-
function AbstractValue.formvalue(self)
- local key = "uci."..self.map.config.."."..self.section.."."..self.option
+ local key = "cbid."..self.map.config.."."..self.section.."."..self.option
return ffluci.http.formvalue(key)
end
+function AbstractValue.parse(self)
+ local fvalue = self:validate(self:formvalue())
+ if fvalue and not (fvalue == self:ucivalue()) then
+ self:write(fvalue)
+ end
+end
+
function AbstractValue.ucivalue(self)
- return self.map:read()[self.section][self.option]
+ return self.map.ucidata[self.section][self.option]
end
function AbstractValue.validate(self, value)
end
function AbstractValue.write(self, value)
- ffluci.model.uci.set(self.config, self.section, self.option, value)
+ return ffluci.model.uci.set(self.config, self.section, self.option, value)
end
function error500(message)
ffluci.http.status(500, "Internal Server Error")
- if not pcall(ffluci.template.render, "error500") then
+ if not pcall(ffluci.template.render, "error500", {message=message}) then
ffluci.http.textheader()
print(message)
end
i18n.loadc(request.module)
- stat, map = pcall(cbi.load, path)
+ local stat, map = pcall(cbi.load, path)
if stat then
+ local stat, err = pcall(map.parse, map)
+ if not stat then
+ disp.error500(err)
+ return
+ end
tmpl.render("cbi/header")
map:render()
tmpl.render("cbi/footer")
return
end
- stat, map = pcall(cbi.load, path)
+ local stat, map = pcall(cbi.load, path)
if stat then
+ local stat, err = pcall(map.parse, map)
+ if not stat then
+ disp.error500(err)
+ return
+ end
tmpl.render("cbi/header")
map:render()
tmpl.render("cbi/footer")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
-<link rel="stylesheet" type="text/css" href="<%=media%>/cascade.css" />
-<link rel="stylesheet" type="text/css" href="<%=media%>/css/<%=req.category%>_<%=req.module%>.css" />
-<title>FFLuCI</title>
-<% if addheaders then write(addheaders) end %>
+ <link rel="stylesheet" type="text/css" href="<%=media%>/cascade.css" />
+ <link rel="stylesheet" type="text/css" href="<%=media%>/css/<%=req.category%>_<%=req.module%>.css" />
+ <link rel="stylesheet" type="text/css" href="<%=media%>/css/<%=req.category%>_<%=req.module%>/<%=req.action%>.css" />
+ <title>FFLuCI</title>
</head>
<body>
<div id="header">