* luci/libs/cbi: various template cleanups
This commit is contained in:
parent
8bb8b7c09c
commit
05d3bf06b4
17 changed files with 228 additions and 179 deletions
|
@ -554,6 +554,24 @@ 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
|
||||
|
|
|
@ -13,15 +13,15 @@ $Id$
|
|||
|
||||
-%>
|
||||
|
||||
<%- if self.tag_invalid[section] then -%>
|
||||
<% if self.tag_invalid[section] then -%>
|
||||
<div class="cbi-error"><%:cbi_invalid%></div>
|
||||
<%- end -%>
|
||||
<%- end %>
|
||||
</td>
|
||||
|
||||
<%- if #self.deps > 0 then -%>
|
||||
<% 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 -%>
|
||||
<%- end %>
|
||||
|
|
|
@ -12,4 +12,5 @@ You may obtain a copy of the License at
|
|||
$Id$
|
||||
|
||||
-%>
|
||||
|
||||
<td class="cbi-value-field" id="cbi-<%=self.config.."-"..section.."-"..self.option%>">
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -12,6 +12,7 @@ You may obtain a copy of the License at
|
|||
$Id$
|
||||
|
||||
-%>
|
||||
|
||||
<div>
|
||||
<input type="submit" value="<%:save%>" />
|
||||
<input type="reset" value="<%:reset%>" />
|
||||
|
|
|
@ -12,11 +12,21 @@ You may obtain a copy of the License at
|
|||
$Id$
|
||||
|
||||
-%>
|
||||
<% if #self.description > 0 then %><div class="cbi-value-description"><%=self.description%></div><% end %>
|
||||
|
||||
<% if #self.description > 0 then -%>
|
||||
<div class="cbi-value-description"><%=self.description%></div>
|
||||
<%- end %>
|
||||
</div>
|
||||
<% if self.tag_invalid[section] then %><div class="cbi-error"><%:cbi_invalid%></div><% end %>
|
||||
|
||||
<% if self.tag_invalid[section] then -%>
|
||||
<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 %>
|
||||
|
||||
<% 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 %>
|
||||
|
|
|
@ -12,6 +12,7 @@ You may obtain a copy of the License at
|
|||
$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>
|
||||
<label class="cbi-value-title"<%= attr("for", cbid) %>><%=self.title%></label>
|
||||
<div class="cbi-value-field">
|
|
@ -13,5 +13,5 @@ $Id$
|
|||
|
||||
-%>
|
||||
<%+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%>
|
|
@ -12,6 +12,7 @@ You may obtain a copy of the License at
|
|||
$Id$
|
||||
|
||||
-%>
|
||||
|
||||
<%+header%>
|
||||
<form method="post" action="<%=luci.http.getenv("REQUEST_URI")%>">
|
||||
<div>
|
||||
|
|
|
@ -14,17 +14,18 @@ $Id$
|
|||
-%>
|
||||
<%+cbi/valueheader%>
|
||||
<% 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 %>>
|
||||
<%for i, key in pairs(self.keylist) do%>
|
||||
<option<% if self:cfgvalue(section) == key then %> selected="selected"<% end %> value="<%=key%>"><%=self.vallist[i]%></option>
|
||||
<% 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 -%>
|
||||
<option<%= attr("value", key) .. ifattr(self:cfgvalue(section) == key, "selected", "selected") %>><%=self.vallist[i]%></option>
|
||||
<%- end %>
|
||||
</select>
|
||||
<% elseif self.widget == "radio" then
|
||||
local c = 0;
|
||||
local c = 0
|
||||
for i, key in pairs(self.keylist) do
|
||||
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 />
|
||||
c = c + 1
|
||||
%>
|
||||
<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 />
|
||||
<% end end %>
|
||||
<% end %>
|
||||
|
|
|
@ -12,9 +12,10 @@ You may obtain a copy of the License at
|
|||
$Id$
|
||||
|
||||
-%>
|
||||
|
||||
<div class="cbi-map" id="cbi-<%=self.config%>">
|
||||
<h1><%=self.title%></h1>
|
||||
<div class="cbi-map-descr"><%=self.description%></div>
|
||||
<% self:render_children() %>
|
||||
<%- self:render_children() %>
|
||||
<br />
|
||||
</div>
|
||||
|
|
|
@ -17,17 +17,18 @@ local v = self:valuelist(section)
|
|||
%>
|
||||
<%+cbi/valueheader%>
|
||||
<% if self.widget == "select" then %>
|
||||
<select multiple="multiple" name="cbid.<%=self.config.."."..section.."."..self.option%>"<% if self.size then %> size="<%=self.size%>"<% end %>>
|
||||
<%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>
|
||||
<% end %>
|
||||
<select multiple="multiple"<%= attr("name", cbid) .. ifattr(self.size, "size") %>>
|
||||
<% for i, key in pairs(self.keylist) do -%>
|
||||
<option<%= attr("value", key) .. ifattr(luci.util.contains(v, key), "selected", "selected") %>><%=self.vallist[i]%></option>
|
||||
<%- end %>
|
||||
</select>
|
||||
<% elseif self.widget == "checkbox" then
|
||||
local c = 0;
|
||||
for i, key in pairs(self.keylist) do
|
||||
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 />
|
||||
c = c + 1
|
||||
%>
|
||||
<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 />
|
||||
<% end end %>
|
||||
<% end %>
|
||||
|
|
|
@ -12,14 +12,16 @@ You may obtain a copy of the License at
|
|||
$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%>">
|
||||
<h2><%=self.title%></h2>
|
||||
<div class="cbi-section-descr"><%=self.description%></div>
|
||||
<% if self.addremove then %><div class="cbi-section-remove right">
|
||||
<% if self.addremove then -%>
|
||||
<div class="cbi-section-remove right">
|
||||
<input type="submit" name="cbi.rns.<%=self.config%>.<%=section%>" value="<%:cbi_del%>" />
|
||||
</div><% end %>
|
||||
</div>
|
||||
<%- end %>
|
||||
<div class="cbi-section-node" id="cbi-<%=self.config%>-<%=section%>">
|
||||
<%+cbi/ucisection%>
|
||||
</div>
|
||||
|
|
|
@ -12,6 +12,7 @@ You may obtain a copy of the License at
|
|||
$Id$
|
||||
|
||||
-%>
|
||||
|
||||
<div class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
|
||||
<h2><%=self.title%></h2>
|
||||
<div class="cbi-section-descr"><%=self.description%></div>
|
||||
|
|
|
@ -12,28 +12,36 @@ You may obtain a copy of the License at
|
|||
$Id$
|
||||
|
||||
-%>
|
||||
|
||||
<div class="cbi-section" id="cbi-<%=self.config%>-<%=self.sectiontype%>">
|
||||
<h2><%=self.title%></h2>
|
||||
<div class="cbi-section-descr"><%=self.description%></div>
|
||||
<% for i, k in ipairs(self:cfgsections()) do%>
|
||||
<% if self.addremove then %><div class="cbi-section-remove right">
|
||||
<% for i, k in ipairs(self:cfgsections()) do -%>
|
||||
<% if self.addremove then -%>
|
||||
<div class="cbi-section-remove right">
|
||||
<input type="submit" name="cbi.rts.<%=self.config%>.<%=k%>" value="<%:cbi_del%>" />
|
||||
</div><% end %>
|
||||
</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 %>
|
||||
<%- end %>
|
||||
|
||||
<% if self.addremove then -%>
|
||||
<div class="cbi-section-create">
|
||||
<% if self.anonymous then %>
|
||||
<% if self.anonymous then -%>
|
||||
<input type="submit" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add%>" />
|
||||
<% else %>
|
||||
<%- 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 %>
|
||||
<%- end %>
|
||||
|
||||
<% if self.err_invalid then -%>
|
||||
<div class="cbi-error"><%:cbi_invalid%></div>
|
||||
<%- end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<%- end %>
|
||||
</div>
|
||||
|
|
|
@ -12,7 +12,9 @@ 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 %>
|
||||
<div class="cbi-optionals">
|
||||
<% if self.dynamic then %>
|
||||
|
|
|
@ -13,5 +13,5 @@ $Id$
|
|||
|
||||
-%>
|
||||
<%+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%>
|
||||
|
|
Loading…
Reference in a new issue