From 8d9d419f846cb76dc8671ed1a75baa7103a6b39d Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Fri, 15 Aug 2008 09:22:45 +0000 Subject: [PATCH] libs/cbi: Some fixes --- libs/cbi/luasrc/cbi.lua | 54 ++++++++++++++++--- libs/cbi/luasrc/view/cbi/nullsection.htm | 20 +++++++ libs/cbi/luasrc/view/cbi/simpleform.htm | 7 +-- .../luasrc/model/cbi/admin_system/sshkeys.lua | 3 +- 4 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 libs/cbi/luasrc/view/cbi/nullsection.htm diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index 9996c8418d..ecc910a139 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -246,6 +246,15 @@ function Map.stateget(self, section, option) end +--[[ +Page - A simple node +]]-- + +Page = class(Node) +Page.__init__ = Node.__init__ +Page.parse = function() end + + --[[ SimpleForm - A Simple non-UCI form ]]-- @@ -265,10 +274,12 @@ function SimpleForm.parse(self, ...) end local valid = true - for i, v in ipairs(self.children) do - valid = valid - and (not v.tag_missing or not v.tag_missing[1]) - and (not v.tag_invalid or not v.tag_invalid[1]) + for k, j in ipairs(self.children) do + for i, v in ipairs(j.children) do + valid = valid + and (not v.tag_missing or not v.tag_missing[1]) + and (not v.tag_invalid or not v.tag_invalid[1]) + end end local state = @@ -276,7 +287,7 @@ function SimpleForm.parse(self, ...) or valid and 1 or -1 - self.dorender = self:handle(state, self.data) + self.dorender = self:handle(state, self.data) ~= false end function SimpleForm.render(self, ...) @@ -285,12 +296,33 @@ function SimpleForm.render(self, ...) 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, ...) + 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 local obj = class(self, ...) obj.track_missing = true - self:append(obj) + section:append(obj) return obj else error("class must be a descendent of AbstractValue") @@ -439,6 +471,14 @@ function AbstractSection.create(self, section) 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 diff --git a/libs/cbi/luasrc/view/cbi/nullsection.htm b/libs/cbi/luasrc/view/cbi/nullsection.htm new file mode 100644 index 0000000000..b01a6a9f58 --- /dev/null +++ b/libs/cbi/luasrc/view/cbi/nullsection.htm @@ -0,0 +1,20 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008 Steven Barth +Copyright 2008 Jo-Philipp Wich + +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$ + +-%> +
+
+ <% self:render_children(1, scope or {}) %> +
+
+
\ No newline at end of file diff --git a/libs/cbi/luasrc/view/cbi/simpleform.htm b/libs/cbi/luasrc/view/cbi/simpleform.htm index d2ae401c92..0b22701971 100644 --- a/libs/cbi/luasrc/view/cbi/simpleform.htm +++ b/libs/cbi/luasrc/view/cbi/simpleform.htm @@ -21,12 +21,7 @@ $Id$

<%=self.title%>

<%=self.description%>
-
-
- <% self:render_children(1, scope or {}) %> -
-
-
+ <% self:render_children() %>
<%- if self.message then %> diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua b/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua index a204d420fc..1c5569ccd4 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_system/sshkeys.lua @@ -17,6 +17,7 @@ local keyfile = "/etc/dropbear/authorized_keys" f = SimpleForm("sshkeys", translate("a_s_sshkeys"), translate("a_s_sshkeys1")) t = f:field(TextValue, "keys") +t.rmempty = true t.rows = 10 function t.cfgvalue() return luci.fs.readfile(keyfile) or "" @@ -24,7 +25,7 @@ end function f.handle(self, state, data) if state == FORM_VALID then - if (luci.fs.readfile(keyfile) or "") ~= data.keys then + if data.keys then luci.fs.writefile(keyfile, data.keys) end end -- 2.30.2