summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/view/cbi/dropdown.htm
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-04-01 16:09:41 +0200
committerJo-Philipp Wich <jo@mein.io>2019-07-07 15:36:24 +0200
commit9c7eb1decd82344e22a10e6f5ac36b463d2149f5 (patch)
treea79b11f65288a7bc5d1c7a32a5f95ea57a1e57a3 /modules/luci-base/luasrc/view/cbi/dropdown.htm
parent808b9f36eb60cf4717cbf28b163d7ad2faa7f157 (diff)
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 <jo@mein.io>
Diffstat (limited to 'modules/luci-base/luasrc/view/cbi/dropdown.htm')
-rw-r--r--modules/luci-base/luasrc/view/cbi/dropdown.htm69
1 files changed, 17 insertions, 52 deletions
diff --git a/modules/luci-base/luasrc/view/cbi/dropdown.htm b/modules/luci-base/luasrc/view/cbi/dropdown.htm
index 6f4b89905b..40bd8e9536 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
--%>
-
-<div class="cbi-dropdown"<%=
- attr("name", cbid) ..
- attr("display-items", self.display or self.size or 3) ..
- attr("dropdown-items", self.dropdown or self.display or self.size or 5) ..
- attr("placeholder", self.placeholder or translate("-- please select --")) ..
- ifattr(self.multiple, "multiple", "multiple") ..
- ifattr(self.optional or self.rmempty, "optional", "optional")
-%>>
- <ul>
- <% local i, key; for i, key in pairs(self.keylist) do %>
- <li<%=
- attr("data-index", i) ..
- attr("data-depends", self:deplist2json(section, self.deplist[i])) ..
- attr("data-value", key) ..
- ifattr(selected[key], "selected", "selected")
- %>>
- <%=pcdata(self.vallist[i])%>
- </li>
- <% end %>
- <% if self.custom then %>
- <li>
- <input type="password" style="display:none" />
- <input class="create-item-input" type="text"<%=
- attr("placeholder", self.custom ~= true and
- self.custom or
- (self.multiple and
- translate("Enter custom values") or
- translate("Enter custom value")))
- %> />
- </li>
- <% end %>
- </ul>
-</div>
-
+<div<%=attr("data-ui-widget", luci.util.serialize_json({
+ "Dropdown", self:cfgvalue(section), self:choices(), {
+ id = cbid,
+ name = cbid,
+ sort = self.keylist,
+ multi = self.multiple,
+ datatype = self.datatype,
+ optional = self.optional or self.rmempty,
+ readonly = self.readonly,
+ maxlength = self.maxlength,
+ placeholder = self.placeholder,
+ display_items = self.display or self.size or 3,
+ dropdown_items = self.dropdown or self.display or self.size or 5,
+ custom_placeholder = self.custom or
+ (self.multiple and translate("Enter custom values") or translate("Enter custom value"))
+ }
+}))%>></div>
<%+cbi/valuefooter%>