diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-18 17:05:36 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2016-01-18 17:05:36 +0100 |
commit | b50471787feb9c04b365ff239aee8f39eadc236b (patch) | |
tree | cef8b5577dd9365c2d2de3106772c3f7dd705e93 /modules/luci-base/luasrc/view | |
parent | be8dba57a9824179a6b942e27e7203d0ba921129 (diff) |
luci-base: refactor cbi dependency handling code
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-base/luasrc/view')
7 files changed, 9 insertions, 73 deletions
diff --git a/modules/luci-base/luasrc/view/cbi/cell_valuefooter.htm b/modules/luci-base/luasrc/view/cbi/cell_valuefooter.htm index 220ebd42b..786ee43d1 100644 --- a/modules/luci-base/luasrc/view/cbi/cell_valuefooter.htm +++ b/modules/luci-base/luasrc/view/cbi/cell_valuefooter.htm @@ -1,20 +1,2 @@ </div> -<div id="cbip-<%=self.config.."-"..section.."-"..self.option%>"></div> </td> - -<% 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..d.add%>", { - <%- - for k,v in pairs(d.deps) do - -%> - <%-=string.format('"cbid.%s.%s.%s"', self.config, section, k) .. ":" .. string.format("%q", v)-%> - <%-if next(d.deps, k) then-%>,<%-end-%> - <%- - end - -%> - }, "cbip-<%=self.config.."-"..section.."-"..self.option%>"); - <%- end %> - </script> -<%- end %> diff --git a/modules/luci-base/luasrc/view/cbi/cell_valueheader.htm b/modules/luci-base/luasrc/view/cbi/cell_valueheader.htm index 9e2e145dd..9c9c21814 100644 --- a/modules/luci-base/luasrc/view/cbi/cell_valueheader.htm +++ b/modules/luci-base/luasrc/view/cbi/cell_valueheader.htm @@ -1,2 +1,2 @@ <td class="cbi-value-field<% if self.error and self.error[section] then %> cbi-value-error<% end %>"> -<div id="cbi-<%=self.config.."-"..section.."-"..self.option%>"> +<div id="cbi-<%=self.config.."-"..section.."-"..self.option%>" data-index="<%=self.index%>" data-depends="<%=pcdata(self:deplist2json(section))%>"> diff --git a/modules/luci-base/luasrc/view/cbi/footer.htm b/modules/luci-base/luasrc/view/cbi/footer.htm index 115250a82..42bf98bf2 100644 --- a/modules/luci-base/luasrc/view/cbi/footer.htm +++ b/modules/luci-base/luasrc/view/cbi/footer.htm @@ -19,7 +19,7 @@ <input class="cbi-button cbi-button-reset" type="button" value="<%:Reset%>" onclick="location.href='<%=REQUEST_URI%>'" /> <% end %> - <script type="text/javascript">cbi_d_update();</script> + <script type="text/javascript">cbi_init();</script> </div> <%- end -%> </form> diff --git a/modules/luci-base/luasrc/view/cbi/full_valuefooter.htm b/modules/luci-base/luasrc/view/cbi/full_valuefooter.htm index 4876fbcc9..f78093676 100644 --- a/modules/luci-base/luasrc/view/cbi/full_valuefooter.htm +++ b/modules/luci-base/luasrc/view/cbi/full_valuefooter.htm @@ -11,49 +11,3 @@ </div> <%- end -%> </div> - - -<% if #self.deps > 0 or #self.subdeps > 0 then -%> - <script type="text/javascript" id="cbip-<%=self.config.."-"..section.."-"..self.option%>"> - <% for j, d in ipairs(self.subdeps) do -%> - cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option..d.add%>", { - <%- - for k,v in pairs(d.deps) do - local depk - if k:find("!", 1, true) then - depk = string.format('"%s"', k) - elseif k:find(".", 1, true) then - depk = string.format('"cbid.%s"', k) - else - depk = string.format('"cbid.%s.%s.%s"', self.config, section, k) - end - -%> - <%-= depk .. ":" .. string.format("%q", v)-%> - <%-if next(d.deps, k) then-%>,<%-end-%> - <%- - end - -%> - }, "cbip-<%=self.config.."-"..section.."-"..self.option..d.add%>"); - <%- end %> - <% for j, d in ipairs(self.deps) do -%> - cbi_d_add("cbi-<%=self.config.."-"..section.."-"..self.option..d.add%>", { - <%- - for k,v in pairs(d.deps) do - local depk - if k:find("!", 1, true) then - depk = string.format('"%s"', k) - elseif k:find(".", 1, true) then - depk = string.format('"cbid.%s"', k) - else - depk = string.format('"cbid.%s.%s.%s"', self.config, section, k) - end - -%> - <%-= depk .. ":" .. string.format("%q", v)-%> - <%-if next(d.deps, k) then-%>,<%-end-%> - <%- - end - -%> - }, "cbip-<%=self.config.."-"..section.."-"..self.option..d.add%>"); - <%- end %> - </script> -<%- end %> diff --git a/modules/luci-base/luasrc/view/cbi/full_valueheader.htm b/modules/luci-base/luasrc/view/cbi/full_valueheader.htm index aaf085473..10a554329 100644 --- a/modules/luci-base/luasrc/view/cbi/full_valueheader.htm +++ b/modules/luci-base/luasrc/view/cbi/full_valueheader.htm @@ -1,4 +1,4 @@ -<div class="cbi-value<% if self.error and self.error[section] then %> cbi-value-error<% end %><% if self.last_child then %> cbi-value-last<% end %>" id="cbi-<%=self.config.."-"..section.."-"..self.option%>"> +<div class="cbi-value<% if self.error and self.error[section] then %> cbi-value-error<% end %><% if self.last_child then %> cbi-value-last<% end %>" id="cbi-<%=self.config.."-"..section.."-"..self.option%>" data-index="<%=self.index%>" data-depends="<%=pcdata(self:deplist2json(section))%>"> <%- if self.title and #self.title > 0 then -%> <label class="cbi-value-title"<%= attr("for", cbid) %>> <%- if self.titleref then -%><a title="<%=self.titledesc or translate('Go to relevant configuration page')%>" class="cbi-title-ref" href="<%=self.titleref%>"><%- end -%> diff --git a/modules/luci-base/luasrc/view/cbi/lvalue.htm b/modules/luci-base/luasrc/view/cbi/lvalue.htm index 8cc086db4..9210ae59f 100644 --- a/modules/luci-base/luasrc/view/cbi/lvalue.htm +++ b/modules/luci-base/luasrc/view/cbi/lvalue.htm @@ -2,7 +2,7 @@ <% if self.widget == "select" then %> <select class="cbi-input-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 id="cbi-<%=self.config.."-"..section.."-"..self.option.."-"..key%>"<%= attr("value", key) .. ifattr(tostring(self:cfgvalue(section) or self.default) == key, "selected", "selected") %>><%=striptags(self.vallist[i])%></option> + <option id="cbi-<%=self.config.."-"..section.."-"..self.option.."-"..key%>"<%= attr("value", key) .. ifattr(tostring(self:cfgvalue(section) or self.default) == key, "selected", "selected") .. attr("data-index", i) .. attr("data-depends", self:deplist2json(section, self.deplist[i])) %>><%=striptags(self.vallist[i])%></option> <%- end %> </select> <% elseif self.widget == "radio" then @@ -10,8 +10,8 @@ for i, key in pairs(self.keylist) do c = c + 1 %> - <input class="cbi-input-radio" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)" type="radio"<%= attr("id", cbid..c) .. attr("name", cbid) .. attr("value", key) .. ifattr((self:cfgvalue(section) or self.default) == key, "checked", "checked") %> /> - <label<%= attr("for", cbid..c) %>><%=self.vallist[i]%></label> + <input class="cbi-input-radio" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)" type="radio"<%= attr("id", cbid.."-"..key) .. attr("name", cbid) .. attr("value", key) .. ifattr((self:cfgvalue(section) or self.default) == key, "checked", "checked") .. attr("data-index", i) .. attr("data-depends", self:deplist2json(section, self.deplist[i])) %> /> + <label<%= attr("for", cbid.."-"..key) %>><%=self.vallist[i]%></label> <% if c == self.size then c = 0 %><% if self.orientation == "horizontal" then %> <% else %><br /><% end %> <% end end %> <% end %> diff --git a/modules/luci-base/luasrc/view/cbi/mvalue.htm b/modules/luci-base/luasrc/view/cbi/mvalue.htm index 5d092610e..9118a2238 100644 --- a/modules/luci-base/luasrc/view/cbi/mvalue.htm +++ b/modules/luci-base/luasrc/view/cbi/mvalue.htm @@ -3,7 +3,7 @@ <% if self.widget == "select" then %> <select class="cbi-input-select" multiple="multiple" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)"<%= 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") %>><%=striptags(self.vallist[i])%></option> + <option<%= attr("id", cbid.."-"..key) .. attr("value", key) .. ifattr(luci.util.contains(v, key), "selected", "selected") .. attr("data-index", i) .. attr("data-depends", self:deplist2json(section, self.deplist[i])) %>><%=striptags(self.vallist[i])%></option> <%- end %> </select> <% elseif self.widget == "checkbox" then @@ -11,8 +11,8 @@ for i, key in pairs(self.keylist) do c = c + 1 %> - <input class="cbi-input-checkbox" type="checkbox" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)"<%= 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><% if not self.oneline then %><br /><% else %> <% end %> + <input class="cbi-input-checkbox" type="checkbox" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)"<%= attr("id", cbid.."-"..key) .. attr("name", cbid) .. attr("value", key) .. ifattr(luci.util.contains(v, key), "checked", "checked") .. attr("data-index", i) .. attr("data-depends", self:deplist2json(section, self.deplist[i])) %> /> + <label<%= attr("for", cbid.."-"..key) %>><%=self.vallist[i]%></label><br /> <% if c == self.size then c = 0 %><br /> <% end end %> <% end %> |