From 05d3bf06b4ae6f07ed1c55fd1f7b4e97cb0e2d3d Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 15 Jul 2008 17:27:58 +0000 Subject: * luci/libs/cbi: various template cleanups --- libs/cbi/luasrc/cbi.lua | 26 +++++- libs/cbi/luasrc/view/cbi/cell_valuefooter.htm | 8 +- libs/cbi/luasrc/view/cbi/cell_valueheader.htm | 1 + libs/cbi/luasrc/view/cbi/dvalue.htm | 1 + libs/cbi/luasrc/view/cbi/footer.htm | 15 ++-- libs/cbi/luasrc/view/cbi/full_valuefooter.htm | 26 ++++-- libs/cbi/luasrc/view/cbi/full_valueheader.htm | 7 +- libs/cbi/luasrc/view/cbi/fvalue.htm | 4 +- libs/cbi/luasrc/view/cbi/header.htm | 13 +-- libs/cbi/luasrc/view/cbi/lvalue.htm | 21 ++--- libs/cbi/luasrc/view/cbi/map.htm | 13 +-- libs/cbi/luasrc/view/cbi/mvalue.htm | 19 +++-- libs/cbi/luasrc/view/cbi/nsection.htm | 38 +++++---- libs/cbi/luasrc/view/cbi/tblsection.htm | 117 +++++++++++++------------- libs/cbi/luasrc/view/cbi/tsection.htm | 56 ++++++------ libs/cbi/luasrc/view/cbi/ucisection.htm | 40 ++++----- libs/cbi/luasrc/view/cbi/value.htm | 2 +- 17 files changed, 228 insertions(+), 179 deletions(-) (limited to 'libs') diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index 7370a04c46..6123e273b6 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -316,7 +316,7 @@ NamedSection = class(AbstractSection) function NamedSection.__init__(self, map, section, type, ...) AbstractSection.__init__(self, map, type, ...) Node._i18n(self, map.config, section, nil, ...) - + self.template = "cbi/nsection" self.section = section self.addremove = false @@ -378,7 +378,7 @@ function TypedSection.cfgsections(self) function (section) if self:checkscope(section[".name"]) then table.insert(sections, section[".name"]) - end + end end) return sections @@ -554,7 +554,25 @@ function AbstractValue.render(self, s, scope) if not self.optional or self:cfgvalue(s) or self:formcreated(s) then scope = scope or {} scope.section = s - + scope.cbid = "cbid." .. self.config .. + "." .. s .. + "." .. self.option + + scope.ifattr = function(cond,key,val) + if cond then + return string.format( + ' %s="%s"', tostring(key), + tostring( val or scope[key] or self[key] or "" ) + ) + else + return '' + end + end + + scope.attr = function(...) + return scope.ifattr( true, ... ) + end + Node.render(self, scope) end end @@ -731,7 +749,7 @@ function MultiValue.valuelist(self, section) end function MultiValue.validate(self, val) - val = (type(val) == "table") and val or {val} + val = (type(val) == "table") and val or {val} local result diff --git a/libs/cbi/luasrc/view/cbi/cell_valuefooter.htm b/libs/cbi/luasrc/view/cbi/cell_valuefooter.htm index 045866d7b7..fbe266ebe5 100644 --- a/libs/cbi/luasrc/view/cbi/cell_valuefooter.htm +++ b/libs/cbi/luasrc/view/cbi/cell_valuefooter.htm @@ -13,15 +13,15 @@ $Id$ -%> - <%- if self.tag_invalid[section] then -%> + <% if self.tag_invalid[section] then -%>
<%:cbi_invalid%>
- <%- end -%> + <%- end %> -<%- if #self.deps > 0 then -%> +<% if #self.deps > 0 then -%> -<%- end -%> +<%- end %> diff --git a/libs/cbi/luasrc/view/cbi/cell_valueheader.htm b/libs/cbi/luasrc/view/cbi/cell_valueheader.htm index 7b8f0a5d69..ecfeee6d95 100644 --- a/libs/cbi/luasrc/view/cbi/cell_valueheader.htm +++ b/libs/cbi/luasrc/view/cbi/cell_valueheader.htm @@ -12,4 +12,5 @@ You may obtain a copy of the License at $Id$ -%> + "> diff --git a/libs/cbi/luasrc/view/cbi/dvalue.htm b/libs/cbi/luasrc/view/cbi/dvalue.htm index 54555bfcdb..7d22fe0d9d 100644 --- a/libs/cbi/luasrc/view/cbi/dvalue.htm +++ b/libs/cbi/luasrc/view/cbi/dvalue.htm @@ -12,6 +12,7 @@ You may obtain a copy of the License at $Id$ -%> + <%+cbi/valueheader%> <% if self.value then if type(self.value) == "function" then %> diff --git a/libs/cbi/luasrc/view/cbi/footer.htm b/libs/cbi/luasrc/view/cbi/footer.htm index 7e9056aabb..4d21fd1684 100644 --- a/libs/cbi/luasrc/view/cbi/footer.htm +++ b/libs/cbi/luasrc/view/cbi/footer.htm @@ -12,10 +12,11 @@ You may obtain a copy of the License at $Id$ -%> -
- - - -
- -<%+footer%> \ No newline at end of file + +
+ + + +
+ +<%+footer%> diff --git a/libs/cbi/luasrc/view/cbi/full_valuefooter.htm b/libs/cbi/luasrc/view/cbi/full_valuefooter.htm index 2db6bbdb1a..8924beccdf 100644 --- a/libs/cbi/luasrc/view/cbi/full_valuefooter.htm +++ b/libs/cbi/luasrc/view/cbi/full_valuefooter.htm @@ -12,11 +12,21 @@ You may obtain a copy of the License at $Id$ -%> - <% if #self.description > 0 then %>
<%=self.description%>
<% end %> - - <% if self.tag_invalid[section] then %>
<%:cbi_invalid%>
<% end %> - - <% if #self.deps > 0 then %><% end %> + + <% if #self.description > 0 then -%> +
<%=self.description%>
+ <%- end %> + + + <% if self.tag_invalid[section] then -%> +
<%:cbi_invalid%>
+ <%- end %> + + +<% if #self.deps > 0 then -%> + +<%- end %> diff --git a/libs/cbi/luasrc/view/cbi/full_valueheader.htm b/libs/cbi/luasrc/view/cbi/full_valueheader.htm index 40fce65ba9..566e236ed1 100644 --- a/libs/cbi/luasrc/view/cbi/full_valueheader.htm +++ b/libs/cbi/luasrc/view/cbi/full_valueheader.htm @@ -12,6 +12,7 @@ You may obtain a copy of the License at $Id$ -%> -
"> - -
\ No newline at end of file + +
"> + +
diff --git a/libs/cbi/luasrc/view/cbi/fvalue.htm b/libs/cbi/luasrc/view/cbi/fvalue.htm index 1e53f24038..f34550061c 100644 --- a/libs/cbi/luasrc/view/cbi/fvalue.htm +++ b/libs/cbi/luasrc/view/cbi/fvalue.htm @@ -13,5 +13,5 @@ $Id$ -%> <%+cbi/valueheader%> - " name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if self:cfgvalue(section) == self.enabled then %> checked="checked"<% end %> value="1" /> -<%+cbi/valuefooter%> \ No newline at end of file + value="1" /> +<%+cbi/valuefooter%> diff --git a/libs/cbi/luasrc/view/cbi/header.htm b/libs/cbi/luasrc/view/cbi/header.htm index afd2048820..ce5d66d77a 100644 --- a/libs/cbi/luasrc/view/cbi/header.htm +++ b/libs/cbi/luasrc/view/cbi/header.htm @@ -12,10 +12,11 @@ You may obtain a copy of the License at $Id$ -%> + <%+header%> -
"> -
- - - -
+"> +
+ + + +
diff --git a/libs/cbi/luasrc/view/cbi/lvalue.htm b/libs/cbi/luasrc/view/cbi/lvalue.htm index 637151e7b2..cb41f53d13 100644 --- a/libs/cbi/luasrc/view/cbi/lvalue.htm +++ b/libs/cbi/luasrc/view/cbi/lvalue.htm @@ -14,18 +14,19 @@ $Id$ -%> <%+cbi/valueheader%> <% if self.widget == "select" then %> - + <% elseif self.widget == "radio" then - local c = 0; + local c = 0 for i, key in pairs(self.keylist) do - c = c + 1%> - " name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if self:cfgvalue(section) == key then %> checked="checked"<% end %> value="<%=key%>" /> -
+ c = c + 1 +%> + /> + ><%=self.vallist[i]%>
<% if c == self.size then c = 0 %>
<% end end %> <% end %> -<%+cbi/valuefooter%> \ No newline at end of file +<%+cbi/valuefooter%> diff --git a/libs/cbi/luasrc/view/cbi/map.htm b/libs/cbi/luasrc/view/cbi/map.htm index c45f39f08c..e29b4fc746 100644 --- a/libs/cbi/luasrc/view/cbi/map.htm +++ b/libs/cbi/luasrc/view/cbi/map.htm @@ -12,9 +12,10 @@ You may obtain a copy of the License at $Id$ -%> -
-

<%=self.title%>

-
<%=self.description%>
-<% self:render_children() %> -
-
+ +
+

<%=self.title%>

+
<%=self.description%>
+ <%- self:render_children() %> +
+
diff --git a/libs/cbi/luasrc/view/cbi/mvalue.htm b/libs/cbi/luasrc/view/cbi/mvalue.htm index 9580d87f79..092d2290f5 100644 --- a/libs/cbi/luasrc/view/cbi/mvalue.htm +++ b/libs/cbi/luasrc/view/cbi/mvalue.htm @@ -13,21 +13,22 @@ $Id$ -%> <% -local v = self:valuelist(section) +local v = self:valuelist(section) %> <%+cbi/valueheader%> <% if self.widget == "select" then %> - + <% elseif self.widget == "checkbox" then local c = 0; for i, key in pairs(self.keylist) do - c = c + 1%> - " name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if luci.util.contains(v, key) then %> checked="checked"<% end %> value="<%=key%>" /> -
+ c = c + 1 +%> + + ><%=self.vallist[i]%>
<% if c == self.size then c = 0 %>
<% end end %> <% end %> diff --git a/libs/cbi/luasrc/view/cbi/nsection.htm b/libs/cbi/luasrc/view/cbi/nsection.htm index 0153c32cf1..a999e47b57 100644 --- a/libs/cbi/luasrc/view/cbi/nsection.htm +++ b/libs/cbi/luasrc/view/cbi/nsection.htm @@ -12,23 +12,25 @@ You may obtain a copy of the License at $Id$ -%> -<% if self:cfgvalue(self.section) then -section = self.section %> -
-

<%=self.title%>

-
<%=self.description%>
- <% if self.addremove then %>
- -
<% end %> -
-<%+cbi/ucisection%> -
-
-
+ +<% if self:cfgvalue(self.section) then section = self.section %> +
+

<%=self.title%>

+
<%=self.description%>
+ <% if self.addremove then -%> +
+ +
+ <%- end %> +
+ <%+cbi/ucisection%> +
+
+
<% elseif self.addremove then %> -
-

<%=self.title%>

-
<%=self.description%>
- -
+
+

<%=self.title%>

+
<%=self.description%>
+ +
<% end %> diff --git a/libs/cbi/luasrc/view/cbi/tblsection.htm b/libs/cbi/luasrc/view/cbi/tblsection.htm index 367af80b88..6f2029e3bb 100644 --- a/libs/cbi/luasrc/view/cbi/tblsection.htm +++ b/libs/cbi/luasrc/view/cbi/tblsection.htm @@ -12,64 +12,65 @@ You may obtain a copy of the License at $Id$ -%> -
-

<%=self.title%>

-
<%=self.description%>
-
- <%- local count = 0 -%> - - - <%- for i, k in pairs(self.children) do -%> - - <%- count = count + 1; end; if self.addremove then -%> - - <%- count = count + 1; end -%> - - - <%- for i, k in pairs(self.children) do -%> - - <%- end; if self.addremove then -%> - - <%- end -%> - - <%- for i, k in ipairs(self:cfgsections()) do - if not self.anonymous then - -%> - - - - <%- end - section = k - scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" } - -%> - - <%-+cbi/ucisection-%> - <%- if self.addremove then -%> - - <%- end -%> - - <%- end -%> - <%- if self.addremove then -%> - - + + + <%- end -%> +
<%=k.title%> 
<%=k.description%> 

<%=k%>

- -
-
- <% if self.anonymous then %> - - <% else %> - - - <% end %> +
+

<%=self.title%>

+
<%=self.description%>
+
+ <%- local count = 0 -%> + + + <%- for i, k in pairs(self.children) do -%> + + <%- count = count + 1; end; if self.addremove then -%> + + <%- count = count + 1; end -%> + + + <%- for i, k in pairs(self.children) do -%> + + <%- end; if self.addremove then -%> + + <%- end -%> + + <%- for i, k in ipairs(self:cfgsections()) do + if not self.anonymous then + -%> + + + + <%- end + section = k + scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" } + -%> + + <%-+cbi/ucisection-%> + <%- if self.addremove then -%> + + <%- end -%> + + <%- end -%> - <% if self.err_invalid then %> -
<%:cbi_invalid%>
- <% end %> - - - - <%- end -%> -
<%=k.title%> 
<%=k.description%> 

<%=k%>

+ +
+ <%- if self.addremove then -%> +
+
+ <% if self.anonymous then %> + + <% else %> + + + <% end %> + + <% if self.err_invalid then %> +
<%:cbi_invalid%>
+ <% end %>
- +
+
+
diff --git a/libs/cbi/luasrc/view/cbi/tsection.htm b/libs/cbi/luasrc/view/cbi/tsection.htm index 7cc5dd34e3..9f4f2a50d7 100644 --- a/libs/cbi/luasrc/view/cbi/tsection.htm +++ b/libs/cbi/luasrc/view/cbi/tsection.htm @@ -12,28 +12,36 @@ You may obtain a copy of the License at $Id$ -%> -
-

<%=self.title%>

-
<%=self.description%>
-<% for i, k in ipairs(self:cfgsections()) do%> - <% if self.addremove then %>
- -
<% end %> - <% if not self.anonymous then %>

<%=k%>

<% end %> -<% section = k %> -
-<%+cbi/ucisection%> -
-
-<% end %> -<% if self.addremove then %> -
- <% if self.anonymous then %> - - <% else %> - - - <% end %><% if self.err_invalid then %>
<%:cbi_invalid%>
<% end %> -
-<% end %> + +
+

<%=self.title%>

+
<%=self.description%>
+ <% for i, k in ipairs(self:cfgsections()) do -%> + <% if self.addremove then -%> +
+
+ <%- end %> + <% if not self.anonymous then %>

<%=k%>

<% end %> + <% section = k %> +
+ <%+cbi/ucisection%> +
+
+ <%- end %> + + <% if self.addremove then -%> +
+ <% if self.anonymous then -%> + + <%- else -%> + + + <%- end %> + + <% if self.err_invalid then -%> +
<%:cbi_invalid%>
+ <%- end %> +
+ <%- end %> +
diff --git a/libs/cbi/luasrc/view/cbi/ucisection.htm b/libs/cbi/luasrc/view/cbi/ucisection.htm index f6652fb0a2..eb581cab78 100644 --- a/libs/cbi/luasrc/view/cbi/ucisection.htm +++ b/libs/cbi/luasrc/view/cbi/ucisection.htm @@ -12,23 +12,25 @@ You may obtain a copy of the License at $Id$ -%> + <% self:render_children(section, scope or {}) %> - <% if #self.optionals[section] > 0 or self.dynamic then %> -
- <% if self.dynamic then %> - - <% else %> - - - <% end %> - -
- <% end %> \ No newline at end of file + +<% if #self.optionals[section] > 0 or self.dynamic then %> +
+ <% if self.dynamic then %> + + <% else %> + + + <% end %> + +
+<% end %> diff --git a/libs/cbi/luasrc/view/cbi/value.htm b/libs/cbi/luasrc/view/cbi/value.htm index 9bde6bc4ba..5a7339d835 100644 --- a/libs/cbi/luasrc/view/cbi/value.htm +++ b/libs/cbi/luasrc/view/cbi/value.htm @@ -13,5 +13,5 @@ $Id$ -%> <%+cbi/valueheader%> - size="<%=self.size%>" <% end %><% if self.maxlength then %>maxlength="<%=self.maxlength%>" <% end %>name="cbid.<%=self.config.."."..section.."."..self.option%>" id="cbid.<%=self.config.."."..section.."."..self.option%>" value="<%=self:cfgvalue(section)%>" /> + /> <%+cbi/valuefooter%> -- cgit v1.2.3