From: Jo-Philipp Wich Date: Mon, 1 Apr 2019 14:09:41 +0000 (+0200) Subject: luci-base: switch from server side to client side widget markup X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=9c7eb1decd82344e22a10e6f5ac36b463d2149f5;p=oweals%2Fluci.git luci-base: switch from server side to client side widget markup Do not render standard widgets like checkboxes, select boxes, text input fields etc. on the server side anymore but utilize the ui.js primitives instead. This avoids logic duplication between server side cbi templates and JS widgets in the future. Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-base/luasrc/cbi.lua b/modules/luci-base/luasrc/cbi.lua index 971830fe8..450e41391 100644 --- a/modules/luci-base/luasrc/cbi.lua +++ b/modules/luci-base/luasrc/cbi.lua @@ -1347,6 +1347,18 @@ function AbstractValue.deplist2json(self, section, deplist) return util.serialize_json(deps) end +-- Serialize choices +function AbstractValue.choices(self) + if type(self.keylist) == "table" and #self.keylist > 0 then + local i, k, v = nil, nil, {} + for i, k in ipairs(self.keylist) do + v[k] = self.vallist[i] or k + end + return v + end + return nil +end + -- Generates the unique CBID function AbstractValue.cbid(self, section) return "cbid."..self.map.config.."."..section.."."..self.option diff --git a/modules/luci-base/luasrc/view/cbi/dropdown.htm b/modules/luci-base/luasrc/view/cbi/dropdown.htm index 6f4b89905..40bd8e953 100644 --- a/modules/luci-base/luasrc/view/cbi/dropdown.htm +++ b/modules/luci-base/luasrc/view/cbi/dropdown.htm @@ -1,54 +1,19 @@ <%+cbi/valueheader%> - -<%- - local selected = { } - - if self.multiple then - local val - for val in luci.util.imatch(self:cfgvalue(section)) do - selected[val] = true - end - else - selected[self:cfgvalue(section)] = true - end - - if not next(selected) and self.default then - selected[self.default] = true - end --%> - -
> -
    - <% local i, key; for i, key in pairs(self.keylist) do %> - > - <%=pcdata(self.vallist[i])%> - - <% end %> - <% if self.custom then %> -
  • - - /> -
  • - <% end %> -
-
- +> <%+cbi/valuefooter%> diff --git a/modules/luci-base/luasrc/view/cbi/dynlist.htm b/modules/luci-base/luasrc/view/cbi/dynlist.htm index fa7dbdb41..d50328d79 100644 --- a/modules/luci-base/luasrc/view/cbi/dynlist.htm +++ b/modules/luci-base/luasrc/view/cbi/dynlist.htm @@ -1,13 +1,12 @@ <%+cbi/valueheader%> -> +> <%+cbi/valuefooter%> diff --git a/modules/luci-base/luasrc/view/cbi/fvalue.htm b/modules/luci-base/luasrc/view/cbi/fvalue.htm index 197d03cf3..7f975b95e 100644 --- a/modules/luci-base/luasrc/view/cbi/fvalue.htm +++ b/modules/luci-base/luasrc/view/cbi/fvalue.htm @@ -1,10 +1,12 @@ <%+cbi/valueheader%> - /> - /> - > +> <%+cbi/valuefooter%> diff --git a/modules/luci-base/luasrc/view/cbi/lvalue.htm b/modules/luci-base/luasrc/view/cbi/lvalue.htm index 34d02eeca..e07648835 100644 --- a/modules/luci-base/luasrc/view/cbi/lvalue.htm +++ b/modules/luci-base/luasrc/view/cbi/lvalue.htm @@ -1,43 +1,14 @@ -<% - local i, key - local br = self.orientation == "horizontal" and ' ' or '
' -%> - <%+cbi/valueheader%> -<% if self.widget == "select" then %> - -<% elseif self.widget == "radio" then %> -
- <% for i, key in pairs(self.keylist) do %> - > - /> - > - <%=pcdata(self.vallist[i])%> - - <% if i == self.size then write(br) end %> - <% end %> -
-<% end %> +> <%+cbi/valuefooter%> diff --git a/modules/luci-base/luasrc/view/cbi/mvalue.htm b/modules/luci-base/luasrc/view/cbi/mvalue.htm index db17450d2..4974a4ed2 100644 --- a/modules/luci-base/luasrc/view/cbi/mvalue.htm +++ b/modules/luci-base/luasrc/view/cbi/mvalue.htm @@ -1,43 +1,16 @@ -<% - local i, key - local v = self:valuelist(section) or {} --%> - <%+cbi/valueheader%> -<% if self.widget == "select" then %> - -<% elseif self.widget == "checkbox" then %> -
- <% for i, key in pairs(self.keylist) do %> - > - /> - > - <%=pcdata(self.vallist[i])%> - - <% if self.size and (i % self.size) == 0 then write('
') end %> - <% end %> -
-<% end %> +> <%+cbi/valuefooter%> diff --git a/modules/luci-base/luasrc/view/cbi/value.htm b/modules/luci-base/luasrc/view/cbi/value.htm index 144853fd9..6060310b1 100644 --- a/modules/luci-base/luasrc/view/cbi/value.htm +++ b/modules/luci-base/luasrc/view/cbi/value.htm @@ -1,26 +1,35 @@ <%+cbi/valueheader%> - <%- if self.password then -%> - /> - <%- end -%> - 0, "data-choices", { self.keylist, self.vallist }) - %> /> - <%- if self.password then -%> - - <% end %> + +<% local choices = self:choices() + if choices then %> + > +<% else %> + > +<% end %> + <%+cbi/valuefooter%>