summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc/view/cbi/ucisection.htm
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2016-02-10 18:11:49 +0100
committerJo-Philipp Wich <jow@openwrt.org>2016-02-10 18:11:49 +0100
commit6d126649f01ac817149d4f36324c161bb1a4650b (patch)
treeb941064af6f43c20b6a8bd2a7bc7b97f859fadce /modules/luci-base/luasrc/view/cbi/ucisection.htm
parent4990ec831c7190946106d5073c02ad85616c04b8 (diff)
luci-base: cbi: further refactoring
Eliminate more inline scripts in favor to global initialization, use a global object for sharing fixed strings instead of passing them to each invocation. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules/luci-base/luasrc/view/cbi/ucisection.htm')
-rw-r--r--modules/luci-base/luasrc/view/cbi/ucisection.htm41
1 files changed, 18 insertions, 23 deletions
diff --git a/modules/luci-base/luasrc/view/cbi/ucisection.htm b/modules/luci-base/luasrc/view/cbi/ucisection.htm
index ba0cc53e87..2cb1e75d0e 100644
--- a/modules/luci-base/luasrc/view/cbi/ucisection.htm
+++ b/modules/luci-base/luasrc/view/cbi/ucisection.htm
@@ -32,30 +32,25 @@
<% if self.optionals[section] and #self.optionals[section] > 0 or self.dynamic then %>
<div class="cbi-optionals" data-index="<%=#self.children + 1%>">
- <% if self.dynamic then %>
- <input type="text" id="cbi.opt.<%=self.config%>.<%=section%>" name="cbi.opt.<%=self.config%>.<%=section%>" />
- <% if self.optionals[section] and #self.optionals[section] > 0 then %>
- <script type="text/javascript">
- cbi_combobox_init('cbi.opt.<%=self.config%>.<%=section%>', {
- <%-
- for i, val in pairs(self.optionals[section]) do
- -%>
- <%-=string.format("%q", val.option) .. ":" .. string.format("%q", striptags(val.title))-%>
- <%-if next(self.optionals[section], i) then-%>,<%-end-%>
- <%-
- end
- -%>
- }, '', '<%-: -- custom -- -%>');
- </script>
- <% end %>
+ <%
+ if self.dynamic then
+ local keys, vals, name, opt = { }, { }
+ for name, opt in pairs(self.optionals[section]) do
+ keys[#keys+1] = name
+ vals[#vals+1] = opt.title
+ end
+ %>
+ <input type="text" id="cbi.opt.<%=self.config%>.<%=section%>" name="cbi.opt.<%=self.config%>.<%=section%>" data-type="uciname" data-optional="true"<%=
+ ifattr(#keys > 0, "data-choices", luci.util.json_encode({keys, vals}))
+ %> />
<% else %>
- <select id="cbi.opt.<%=self.config%>.<%=section%>" name="cbi.opt.<%=self.config%>.<%=section%>" data-optionals="true">
- <option><%: -- Additional Field -- %></option>
- <% for key, val in pairs(self.optionals[section]) do -%>
- <option id="cbi-<%=self.config.."-"..section.."-"..val.option%>" value="<%=val.option%>" data-index="<%=val.index%>" data-depends="<%=pcdata(val:deplist2json(section))%>"><%=striptags(val.title)%></option>
- <%- end %>
- </select>
- <% end %>
+ <select id="cbi.opt.<%=self.config%>.<%=section%>" name="cbi.opt.<%=self.config%>.<%=section%>" data-optionals="true">
+ <option><%: -- Additional Field -- %></option>
+ <% for key, val in pairs(self.optionals[section]) do -%>
+ <option id="cbi-<%=self.config.."-"..section.."-"..val.option%>" value="<%=val.option%>" data-index="<%=val.index%>" data-depends="<%=pcdata(val:deplist2json(section))%>"><%=striptags(val.title)%></option>
+ <%- end %>
+ </select>
+ <% end %>
<input type="submit" class="cbi-button cbi-button-fieldadd" value="<%:Add%>" />
</div>
<% end %>