* luci/libs/cbi: various template cleanups

This commit is contained in:
Jo-Philipp Wich 2008-07-15 17:27:58 +00:00
parent 8bb8b7c09c
commit 05d3bf06b4
17 changed files with 228 additions and 179 deletions

View file

@ -316,7 +316,7 @@ NamedSection = class(AbstractSection)
function NamedSection.__init__(self, map, section, type, ...) function NamedSection.__init__(self, map, section, type, ...)
AbstractSection.__init__(self, map, type, ...) AbstractSection.__init__(self, map, type, ...)
Node._i18n(self, map.config, section, nil, ...) Node._i18n(self, map.config, section, nil, ...)
self.template = "cbi/nsection" self.template = "cbi/nsection"
self.section = section self.section = section
self.addremove = false self.addremove = false
@ -378,7 +378,7 @@ function TypedSection.cfgsections(self)
function (section) function (section)
if self:checkscope(section[".name"]) then if self:checkscope(section[".name"]) then
table.insert(sections, section[".name"]) table.insert(sections, section[".name"])
end end
end) end)
return sections 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 if not self.optional or self:cfgvalue(s) or self:formcreated(s) then
scope = scope or {} scope = scope or {}
scope.section = s 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) Node.render(self, scope)
end end
end end
@ -731,7 +749,7 @@ function MultiValue.valuelist(self, section)
end end
function MultiValue.validate(self, val) function MultiValue.validate(self, val)
val = (type(val) == "table") and val or {val} val = (type(val) == "table") and val or {val}
local result local result

View file

@ -13,15 +13,15 @@ $Id$
-%> -%>
<%- if self.tag_invalid[section] then -%> <% if self.tag_invalid[section] then -%>
<div class="cbi-error"><%:cbi_invalid%></div> <div class="cbi-error"><%:cbi_invalid%></div>
<%- end -%> <%- end %>
</td> </td>
<%- if #self.deps > 0 then -%> <% if #self.deps > 0 then -%>
<script type="text/javascript"> <script type="text/javascript">
<% for j, d in ipairs(self.deps) do -%> <% for j, d in ipairs(self.deps) do -%>
cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>"); cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>");
<%- end %> <%- end %>
</script> </script>
<%- end -%> <%- end %>

View file

@ -12,4 +12,5 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<td class="cbi-value-field" id="cbi-<%=self.config.."-"..section.."-"..self.option%>"> <td class="cbi-value-field" id="cbi-<%=self.config.."-"..section.."-"..self.option%>">

View file

@ -12,6 +12,7 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<%+cbi/valueheader%> <%+cbi/valueheader%>
<% if self.value then <% if self.value then
if type(self.value) == "function" then %> if type(self.value) == "function" then %>

View file

@ -12,10 +12,11 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<div>
<input type="submit" value="<%:save%>" /> <div>
<input type="reset" value="<%:reset%>" /> <input type="submit" value="<%:save%>" />
<script type="text/javascript">cbi_d_init();</script> <input type="reset" value="<%:reset%>" />
</div> <script type="text/javascript">cbi_d_init();</script>
</form> </div>
<%+footer%> </form>
<%+footer%>

View file

@ -12,11 +12,21 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<% if #self.description > 0 then %><div class="cbi-value-description"><%=self.description%></div><% end %>
</div> <% if #self.description > 0 then -%>
<% if self.tag_invalid[section] then %><div class="cbi-error"><%:cbi_invalid%></div><% end %> <div class="cbi-value-description"><%=self.description%></div>
</div> <%- end %>
<% if #self.deps > 0 then %><script type="text/javascript"> </div>
<% for j, d in ipairs(self.deps) do %>cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>");
<% end %> <% if self.tag_invalid[section] then -%>
</script><% end %> <div class="cbi-error"><%:cbi_invalid%></div>
<%- end %>
</div>
<% if #self.deps > 0 then -%>
<script type="text/javascript">
<% for j, d in ipairs(self.deps) do -%>
cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>");
<%- end %>
</script>
<%- end %>

View file

@ -12,6 +12,7 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<div class="cbi-value" id="cbi-<%=self.config.."-"..section.."-"..self.option%>">
<label for="cbid.<%=self.config.."."..section.."."..self.option%>" class="cbi-value-title"><%=self.title%></label> <div class="cbi-value" id="cbi-<%=self.config.."-"..section.."-"..self.option%>">
<div class="cbi-value-field"> <label class="cbi-value-title"<%= attr("for", cbid) %>><%=self.title%></label>
<div class="cbi-value-field">

View file

@ -13,5 +13,5 @@ $Id$
-%> -%>
<%+cbi/valueheader%> <%+cbi/valueheader%>
<input onchange="cbi_d_update(this.id)" type="checkbox" id="cbid.<%=self.config.."."..section.."."..self.option%>" name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if self:cfgvalue(section) == self.enabled then %> checked="checked"<% end %> value="1" /> <input onchange="cbi_d_update(this.id)" type="checkbox"<%= attr("id", cbid) .. attr("name", cbid) .. ifattr(self:cfgvalue(section) == self.enabled, "checked", "checked") %> value="1" />
<%+cbi/valuefooter%> <%+cbi/valuefooter%>

View file

@ -12,10 +12,11 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<%+header%> <%+header%>
<form method="post" action="<%=luci.http.getenv("REQUEST_URI")%>"> <form method="post" action="<%=luci.http.getenv("REQUEST_URI")%>">
<div> <div>
<script type="text/javascript" src="<%=resource%>/cbi.js"></script> <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
<input type="hidden" name="cbi.submit" value="1" /> <input type="hidden" name="cbi.submit" value="1" />
<input type="submit" value="<%:save%>" class="hidden" /> <input type="submit" value="<%:save%>" class="hidden" />
</div> </div>

View file

@ -14,18 +14,19 @@ $Id$
-%> -%>
<%+cbi/valueheader%> <%+cbi/valueheader%>
<% if self.widget == "select" then %> <% if self.widget == "select" then %>
<select onchange="cbi_d_update(this.id)" id="cbid.<%=self.config.."."..section.."."..self.option%>" name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if self.size then %> size="<%=self.size%>"<% end %>> <select onchange="cbi_d_update(this.id)"<%= attr("id", cbid) .. attr("name", cbid) .. ifattr(self.size, "size") %>>
<%for i, key in pairs(self.keylist) do%> <% for i, key in pairs(self.keylist) do -%>
<option<% if self:cfgvalue(section) == key then %> selected="selected"<% end %> value="<%=key%>"><%=self.vallist[i]%></option> <option<%= attr("value", key) .. ifattr(self:cfgvalue(section) == key, "selected", "selected") %>><%=self.vallist[i]%></option>
<% end %> <%- end %>
</select> </select>
<% elseif self.widget == "radio" then <% elseif self.widget == "radio" then
local c = 0; local c = 0
for i, key in pairs(self.keylist) do for i, key in pairs(self.keylist) do
c = c + 1%> c = c + 1
<input type="radio" id="cbid.<%=self.config.."."..section.."."..self.option%>" name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if self:cfgvalue(section) == key then %> checked="checked"<% end %> value="<%=key%>" /> %>
<label for="cbid.<%=self.config.."."..section.."."..self.option%>"><%=self.vallist[i]%></label><br /> <input type="radio"<%= attr("id", cbid..c) .. attr("name", cbid) .. attr("value", key) .. ifattr(self:cfgvalue(section) == key, "checked", "checked") %> />
<label<%= attr("for", cbid..c) %>><%=self.vallist[i]%></label><br />
<% if c == self.size then c = 0 %><br /> <% if c == self.size then c = 0 %><br />
<% end end %> <% end end %>
<% end %> <% end %>
<%+cbi/valuefooter%> <%+cbi/valuefooter%>

View file

@ -12,9 +12,10 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<div class="cbi-map" id="cbi-<%=self.config%>">
<h1><%=self.title%></h1> <div class="cbi-map" id="cbi-<%=self.config%>">
<div class="cbi-map-descr"><%=self.description%></div> <h1><%=self.title%></h1>
<% self:render_children() %> <div class="cbi-map-descr"><%=self.description%></div>
<br /> <%- self:render_children() %>
</div> <br />
</div>

View file

@ -13,21 +13,22 @@ $Id$
-%> -%>
<% <%
local v = self:valuelist(section) local v = self:valuelist(section)
%> %>
<%+cbi/valueheader%> <%+cbi/valueheader%>
<% if self.widget == "select" then %> <% if self.widget == "select" then %>
<select multiple="multiple" name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if self.size then %> size="<%=self.size%>"<% end %>> <select multiple="multiple"<%= attr("name", cbid) .. ifattr(self.size, "size") %>>
<%for i, key in pairs(self.keylist) do %> <% for i, key in pairs(self.keylist) do -%>
<option<% if luci.util.contains(v, key) then %> selected="selected"<% end %> value="<%=key%>"><%=self.vallist[i]%></option> <option<%= attr("value", key) .. ifattr(luci.util.contains(v, key), "selected", "selected") %>><%=self.vallist[i]%></option>
<% end %> <%- end %>
</select> </select>
<% elseif self.widget == "checkbox" then <% elseif self.widget == "checkbox" then
local c = 0; local c = 0;
for i, key in pairs(self.keylist) do for i, key in pairs(self.keylist) do
c = c + 1%> c = c + 1
<input type="checkbox" id="cbid.<%=self.config.."."..section.."."..self.option.."."..i%>" name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if luci.util.contains(v, key) then %> checked="checked"<% end %> value="<%=key%>" /> %>
<label for="cbid.<%=self.config.."."..section.."."..self.option.."."..i%>"><%=self.vallist[i]%></label><br /> <input type="checkbox"<%= attr("id", cbid..c) .. attr("name", cbid) .. attr("value", key) .. ifattr(luci.util.contains(v, key), "checked", "checked") />
<label<%= attr("for", cbid..c) %>><%=self.vallist[i]%></label><br />
<% if c == self.size then c = 0 %><br /> <% if c == self.size then c = 0 %><br />
<% end end %> <% end end %>
<% end %> <% end %>

View file

@ -12,23 +12,25 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<% if self:cfgvalue(self.section) then
section = self.section %> <% if self:cfgvalue(self.section) then section = self.section %>
<div class="cbi-section" id="cbi-<%=self.config%>-<%=section%>"> <div class="cbi-section" id="cbi-<%=self.config%>-<%=section%>">
<h2><%=self.title%></h2> <h2><%=self.title%></h2>
<div class="cbi-section-descr"><%=self.description%></div> <div class="cbi-section-descr"><%=self.description%></div>
<% if self.addremove then %><div class="cbi-section-remove right"> <% if self.addremove then -%>
<input type="submit" name="cbi.rns.<%=self.config%>.<%=section%>" value="<%:cbi_del%>" /> <div class="cbi-section-remove right">
</div><% end %> <input type="submit" name="cbi.rns.<%=self.config%>.<%=section%>" value="<%:cbi_del%>" />
<div class="cbi-section-node" id="cbi-<%=self.config%>-<%=section%>"> </div>
<%+cbi/ucisection%> <%- end %>
</div> <div class="cbi-section-node" id="cbi-<%=self.config%>-<%=section%>">
<br /> <%+cbi/ucisection%>
</div> </div>
<br />
</div>
<% elseif self.addremove then %> <% elseif self.addremove then %>
<div class="cbi-section" id="cbi-<%=self.config%>-<%=self.section%>"> <div class="cbi-section" id="cbi-<%=self.config%>-<%=self.section%>">
<h2><%=self.title%></h2> <h2><%=self.title%></h2>
<div class="cbi-section-descr"><%=self.description%></div> <div class="cbi-section-descr"><%=self.description%></div>
<input type="submit" name="cbi.cns.<%=self.config%>.<%=self.section%>" value="<%:cbi_add%>" /> <input type="submit" name="cbi.cns.<%=self.config%>.<%=self.section%>" value="<%:cbi_add%>" />
</div> </div>
<% end %> <% end %>

View file

@ -12,64 +12,65 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<div class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
<h2><%=self.title%></h2>
<div class="cbi-section-descr"><%=self.description%></div>
<div class="cbi-section-node">
<%- local count = 0 -%>
<table class="cbi-section-table">
<tr class="cbi-section-table-titles">
<%- for i, k in pairs(self.children) do -%>
<th class="cbi-section-table-cell"><%=k.title%></th>
<%- count = count + 1; end; if self.addremove then -%>
<th class="cbi-section-table-cell">&nbsp;</th>
<%- count = count + 1; end -%>
</tr>
<tr class="cbi-section-table-descr">
<%- for i, k in pairs(self.children) do -%>
<th class="cbi-section-table-cell"><%=k.description%></th>
<%- end; if self.addremove then -%>
<th class="cbi-section-table-cell">&nbsp;</th>
<%- end -%>
</tr>
<%- for i, k in ipairs(self:cfgsections()) do
if not self.anonymous then
-%>
<tr class="cbi-section-table-title">
<th colspan="<%=count%>"><h3><%=k%></h3></th>
</tr>
<%- end
section = k
scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
-%>
<tr class="cbi-section-table-row" id="cbi-<%=self.config%>-<%=section%>">
<%-+cbi/ucisection-%>
<%- if self.addremove then -%>
<td class="cbi-section-table-cell">
<input type="submit" name="cbi.rts.<%=self.config%>.<%=k%>" value="X" />
</td>
<%- end -%>
</tr>
<%- end -%>
<%- if self.addremove then -%> <div class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
<tr class="cbi-section-table-row"> <h2><%=self.title%></h2>
<td colspan="<%=count%>" class="cbi-section-table-optionals"> <div class="cbi-section-descr"><%=self.description%></div>
<div class="cbi-section-create"> <div class="cbi-section-node">
<% if self.anonymous then %> <%- local count = 0 -%>
<input type="submit" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add%>" /> <table class="cbi-section-table">
<% else %> <tr class="cbi-section-table-titles">
<input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" /> <%- for i, k in pairs(self.children) do -%>
<input type="submit" value="<%:cbi_add%>" /> <th class="cbi-section-table-cell"><%=k.title%></th>
<% end %> <%- count = count + 1; end; if self.addremove then -%>
<th class="cbi-section-table-cell">&nbsp;</th>
<%- count = count + 1; end -%>
</tr>
<tr class="cbi-section-table-descr">
<%- for i, k in pairs(self.children) do -%>
<th class="cbi-section-table-cell"><%=k.description%></th>
<%- end; if self.addremove then -%>
<th class="cbi-section-table-cell">&nbsp;</th>
<%- end -%>
</tr>
<%- for i, k in ipairs(self:cfgsections()) do
if not self.anonymous then
-%>
<tr class="cbi-section-table-title">
<th colspan="<%=count%>"><h3><%=k%></h3></th>
</tr>
<%- end
section = k
scope = { valueheader = "cbi/cell_valueheader", valuefooter = "cbi/cell_valuefooter" }
-%>
<tr class="cbi-section-table-row" id="cbi-<%=self.config%>-<%=section%>">
<%-+cbi/ucisection-%>
<%- if self.addremove then -%>
<td class="cbi-section-table-cell">
<input type="submit" name="cbi.rts.<%=self.config%>.<%=k%>" value="X" />
</td>
<%- end -%>
</tr>
<%- end -%>
<% if self.err_invalid then %> <%- if self.addremove then -%>
<div class="cbi-error"><%:cbi_invalid%></div> <tr class="cbi-section-table-row">
<% end %> <td colspan="<%=count%>" class="cbi-section-table-optionals">
</div> <div class="cbi-section-create">
</td> <% if self.anonymous then %>
</tr> <input type="submit" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add%>" />
<%- end -%> <% else %>
</table> <input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
<input type="submit" value="<%:cbi_add%>" />
<% end %>
<% if self.err_invalid then %>
<div class="cbi-error"><%:cbi_invalid%></div>
<% end %>
</div> </div>
</div> </td>
</tr>
<%- end -%>
</table>
</div>
</div>

View file

@ -12,28 +12,36 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<div class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
<h2><%=self.title%></h2> <div class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
<div class="cbi-section-descr"><%=self.description%></div> <h2><%=self.title%></h2>
<% for i, k in ipairs(self:cfgsections()) do%> <div class="cbi-section-descr"><%=self.description%></div>
<% if self.addremove then %><div class="cbi-section-remove right"> <% for i, k in ipairs(self:cfgsections()) do -%>
<input type="submit" name="cbi.rts.<%=self.config%>.<%=k%>" value="<%:cbi_del%>" /> <% if self.addremove then -%>
</div><% end %> <div class="cbi-section-remove right">
<% if not self.anonymous then %><h3><%=k%></h3><% end %> <input type="submit" name="cbi.rts.<%=self.config%>.<%=k%>" value="<%:cbi_del%>" />
<% section = k %>
<div class="cbi-section-node" id="cbi-<%=self.config%>-<%=section%>">
<%+cbi/ucisection%>
</div>
<br />
<% end %>
<% if self.addremove then %>
<div class="cbi-section-create">
<% if self.anonymous then %>
<input type="submit" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add%>" />
<% else %>
<input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
<input type="submit" value="<%:cbi_add%>" />
<% end %><% if self.err_invalid then %><div class="cbi-error"><%:cbi_invalid%></div><% end %>
</div>
<% end %>
</div> </div>
<%- end %>
<% if not self.anonymous then %><h3><%=k%></h3><% end %>
<% section = k %>
<div class="cbi-section-node" id="cbi-<%=self.config%>-<%=section%>">
<%+cbi/ucisection%>
</div>
<br />
<%- end %>
<% if self.addremove then -%>
<div class="cbi-section-create">
<% if self.anonymous then -%>
<input type="submit" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add%>" />
<%- else -%>
<input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
<input type="submit" value="<%:cbi_add%>" />
<%- end %>
<% if self.err_invalid then -%>
<div class="cbi-error"><%:cbi_invalid%></div>
<%- end %>
</div>
<%- end %>
</div>

View file

@ -12,23 +12,25 @@ You may obtain a copy of the License at
$Id$ $Id$
-%> -%>
<% self:render_children(section, scope or {}) %> <% self:render_children(section, scope or {}) %>
<% if #self.optionals[section] > 0 or self.dynamic then %>
<div class="cbi-optionals"> <% if #self.optionals[section] > 0 or self.dynamic then %>
<% if self.dynamic then %> <div class="cbi-optionals">
<input type="text" name="cbi.opt.<%=self.config%>.<%=section%>" /> <% if self.dynamic then %>
<% else %> <input type="text" name="cbi.opt.<%=self.config%>.<%=section%>" />
<select name="cbi.opt.<%=self.config%>.<%=section%>"> <% else %>
<option><%:cbi_addopt%></option> <select name="cbi.opt.<%=self.config%>.<%=section%>">
<% for key, val in pairs(self.optionals[section]) do %> <option><%:cbi_addopt%></option>
<option id="cbi-<%=self.config.."-"..section.."-"..val.option%>" value="<%=val.option%>"><%=val.title%></option> <% for key, val in pairs(self.optionals[section]) do %>
<% end %> <option id="cbi-<%=self.config.."-"..section.."-"..val.option%>" value="<%=val.option%>"><%=val.title%></option>
</select> <% end %>
<script type="text/javascript"><% for key, val in pairs(self.optionals[section]) do %> </select>
<% if #val.deps > 0 then %><% for j, d in ipairs(val.deps) do %>cbi_d_add("cbi-<%=self.config.."-"..section.."-"..val.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>"); <script type="text/javascript"><% for key, val in pairs(self.optionals[section]) do %>
<% end %><% end %> <% if #val.deps > 0 then %><% for j, d in ipairs(val.deps) do %>cbi_d_add("cbi-<%=self.config.."-"..section.."-"..val.option%>", "cbid.<%=self.config.."."..section.."."..d.field%>", "<%=d.value%>");
<% end %></script> <% end %><% end %>
<% end %> <% end %></script>
<input type="submit" value="<%:add%>" /> <% end %>
</div> <input type="submit" value="<%:add%>" />
<% end %> </div>
<% end %>

View file

@ -13,5 +13,5 @@ $Id$
-%> -%>
<%+cbi/valueheader%> <%+cbi/valueheader%>
<input type="text" onchange="cbi_d_update(this.id)" <% if self.size then %>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)%>" /> <input type="text" onchange="cbi_d_update(this.id)"<%= attr("name", cbid) .. attr("id", cbid) .. attr("value", self:cfgvalue(section)) .. ifattr(self.size, "size") .. ifattr(self.maxlength, "maxlength") %> />
<%+cbi/valuefooter%> <%+cbi/valuefooter%>