libs/cbi: Some fixes
This commit is contained in:
parent
0a0c7ca2f9
commit
8d9d419f84
4 changed files with 70 additions and 14 deletions
|
@ -246,6 +246,15 @@ function Map.stateget(self, section, option)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Page - A simple node
|
||||||
|
]]--
|
||||||
|
|
||||||
|
Page = class(Node)
|
||||||
|
Page.__init__ = Node.__init__
|
||||||
|
Page.parse = function() end
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
SimpleForm - A Simple non-UCI form
|
SimpleForm - A Simple non-UCI form
|
||||||
]]--
|
]]--
|
||||||
|
@ -265,18 +274,20 @@ function SimpleForm.parse(self, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
local valid = true
|
local valid = true
|
||||||
for i, v in ipairs(self.children) do
|
for k, j in ipairs(self.children) do
|
||||||
|
for i, v in ipairs(j.children) do
|
||||||
valid = valid
|
valid = valid
|
||||||
and (not v.tag_missing or not v.tag_missing[1])
|
and (not v.tag_missing or not v.tag_missing[1])
|
||||||
and (not v.tag_invalid or not v.tag_invalid[1])
|
and (not v.tag_invalid or not v.tag_invalid[1])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local state =
|
local state =
|
||||||
not luci.http.formvalue("cbi.submit") and 0
|
not luci.http.formvalue("cbi.submit") and 0
|
||||||
or valid and 1
|
or valid and 1
|
||||||
or -1
|
or -1
|
||||||
|
|
||||||
self.dorender = self:handle(state, self.data)
|
self.dorender = self:handle(state, self.data) ~= false
|
||||||
end
|
end
|
||||||
|
|
||||||
function SimpleForm.render(self, ...)
|
function SimpleForm.render(self, ...)
|
||||||
|
@ -285,12 +296,33 @@ function SimpleForm.render(self, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Creates a child section
|
function SimpleForm.section(self, class, ...)
|
||||||
|
if instanceof(class, AbstractSection) then
|
||||||
|
local obj = class(self, ...)
|
||||||
|
self:append(obj)
|
||||||
|
return obj
|
||||||
|
else
|
||||||
|
error("class must be a descendent of AbstractSection")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Creates a child field
|
||||||
function SimpleForm.field(self, class, ...)
|
function SimpleForm.field(self, class, ...)
|
||||||
|
local section
|
||||||
|
for k, v in ipairs(self.children) do
|
||||||
|
if instanceof(v, SimpleSection) then
|
||||||
|
section = v
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not section then
|
||||||
|
section = self:section(SimpleSection)
|
||||||
|
end
|
||||||
|
|
||||||
if instanceof(class, AbstractValue) then
|
if instanceof(class, AbstractValue) then
|
||||||
local obj = class(self, ...)
|
local obj = class(self, ...)
|
||||||
obj.track_missing = true
|
obj.track_missing = true
|
||||||
self:append(obj)
|
section:append(obj)
|
||||||
return obj
|
return obj
|
||||||
else
|
else
|
||||||
error("class must be a descendent of AbstractValue")
|
error("class must be a descendent of AbstractValue")
|
||||||
|
@ -439,6 +471,14 @@ function AbstractSection.create(self, section)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
SimpleSection = class(AbstractSection)
|
||||||
|
|
||||||
|
function SimpleSection.__init__(self, form, ...)
|
||||||
|
AbstractSection.__init__(self, form, nil, ...)
|
||||||
|
self.template = "cbi/nullsection"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
NamedSection - A fixed configuration section defined by its name
|
NamedSection - A fixed configuration section defined by its name
|
||||||
|
|
20
libs/cbi/luasrc/view/cbi/nullsection.htm
Normal file
20
libs/cbi/luasrc/view/cbi/nullsection.htm
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<%#
|
||||||
|
LuCI - Lua Configuration Interface
|
||||||
|
Copyright 2008 Steven Barth <steven@midlink.org>
|
||||||
|
Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
|
||||||
|
-%>
|
||||||
|
<fieldset class="cbi-section">
|
||||||
|
<div class="cbi-section-node">
|
||||||
|
<% self:render_children(1, scope or {}) %>
|
||||||
|
</div>
|
||||||
|
<br />
|
||||||
|
</fieldset>
|
|
@ -21,12 +21,7 @@ $Id$
|
||||||
<div class="cbi-map" id="cbi-<%=self.config%>">
|
<div class="cbi-map" id="cbi-<%=self.config%>">
|
||||||
<h1><%=self.title%></h1>
|
<h1><%=self.title%></h1>
|
||||||
<div class="cbi-map-descr"><%=self.description%></div>
|
<div class="cbi-map-descr"><%=self.description%></div>
|
||||||
<fieldset class="cbi-section">
|
<% self:render_children() %>
|
||||||
<div class="cbi-section-node">
|
|
||||||
<% self:render_children(1, scope or {}) %>
|
|
||||||
</div>
|
|
||||||
<br />
|
|
||||||
</fieldset>
|
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
<%- if self.message then %>
|
<%- if self.message then %>
|
||||||
|
|
|
@ -17,6 +17,7 @@ local keyfile = "/etc/dropbear/authorized_keys"
|
||||||
f = SimpleForm("sshkeys", translate("a_s_sshkeys"), translate("a_s_sshkeys1"))
|
f = SimpleForm("sshkeys", translate("a_s_sshkeys"), translate("a_s_sshkeys1"))
|
||||||
|
|
||||||
t = f:field(TextValue, "keys")
|
t = f:field(TextValue, "keys")
|
||||||
|
t.rmempty = true
|
||||||
t.rows = 10
|
t.rows = 10
|
||||||
function t.cfgvalue()
|
function t.cfgvalue()
|
||||||
return luci.fs.readfile(keyfile) or ""
|
return luci.fs.readfile(keyfile) or ""
|
||||||
|
@ -24,7 +25,7 @@ end
|
||||||
|
|
||||||
function f.handle(self, state, data)
|
function f.handle(self, state, data)
|
||||||
if state == FORM_VALID then
|
if state == FORM_VALID then
|
||||||
if (luci.fs.readfile(keyfile) or "") ~= data.keys then
|
if data.keys then
|
||||||
luci.fs.writefile(keyfile, data.keys)
|
luci.fs.writefile(keyfile, data.keys)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue