luci-base: view: make checkboxes and radio buttons styleable
[project/luci.git] / modules / luci-base / luasrc / view / cbi / network_netlist.htm
1 <%+cbi/valueheader%>
2
3 <%-
4         local utl = require "luci.util"
5         local nwm = require "luci.model.network".init()
6
7         local net, iface
8         local networks = nwm:get_networks()
9         local value = self:formvalue(section)
10
11         self.cast = nil
12
13         if not value or value == "-" then
14                 value = self:cfgvalue(section) or self.default
15         end
16
17         local checked = { }
18         for value in utl.imatch(value) do
19                 checked[value] = true
20         end
21 -%>
22
23 <ul style="margin:0; list-style-type:none; text-align:left">
24         <% for _, net in ipairs(networks) do
25                if (net:name() ~= "loopback") and
26                       (net:name() ~= self.exclude) and
27                       (not self.novirtual or not net:is_virtual())
28                    then %>
29         <li style="padding:0.25em 0">
30                 <input class="cbi-input-<%=self.widget or "radio"%>" data-update="click change"<%=
31                         attr("type", self.widget or "radio") ..
32                         attr("id", cbid .. "." .. net:name()) ..
33                         attr("name", cbid) .. attr("value", net:name()) ..
34                         ifattr(checked[net:name()], "checked", "checked")
35                 %> /> &#160;
36                 <label<%=attr("for", cbid .. "." .. net:name())%>>
37                         <span class="ifacebadge"><%=net:name()%>:
38                                 <%
39                                         local empty = true
40                                         for _, iface in ipairs(net:is_bridge() and net:get_interfaces() or { net:get_interface() }) do
41                                                 if not iface:is_bridge() then
42                                                         empty = false
43                                  %>
44                                         <img<%=attr("title", iface:get_i18n())%> style="width:16px; height:16px; vertical-align:middle" src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" />
45                                 <% end end %>
46                                 <% if empty then %><em><%:(no interfaces attached)%></em><% end %>
47                         </span>
48                 </label>
49         </li>
50         <% end end %>
51
52         <% if not self.nocreate then %>
53         <li style="padding:0.25em 0">
54                 <input class="cbi-input-<%=self.widget or "radio"%>" data-update="click change"<%=attr("type", self.widget or "radio") .. attr("id", cbid .. "_new") .. attr("name", cbid) .. attr("value", "-") .. ifattr(not value and self.widget ~= "checkbox", "checked", "checked")%> /> &#160;
55                 <%- if not self.widget or self.widget == "checkbox" or self.widget == "radio" then -%>
56                         <label<%=attr("for", cbid .. "_new")%>></label>
57                 <%- end -%>
58                 <div style="padding:0.5em; display:inline">
59                         <label<%=attr("for", cbid .. "_new")%>><em>
60                                 <%- if self.widget == "checkbox" then -%>
61                                         <%:create:%>
62                                 <%- else -%>
63                                         <%:unspecified -or- create:%>
64                                 <%- end -%>&#160;</em></label>
65                         <input style="display:none" type="password" />
66                         <input style="width:6em" type="text"<%=attr("name", cbid .. ".newnet")%> onfocus="document.getElementById('<%=cbid%>_new').checked=true" />
67                 </div>
68         </li>
69         <% elseif self.widget ~= "checkbox" and self.unspecified then %>
70         <li style="padding:0.25em 0">
71                 <input class="cbi-input-<%=self.widget or "radio"%>" data-update="click change"<%=
72                         attr("type", self.widget or "radio") ..
73                         attr("id", cbid .. "_uns") ..
74                         attr("name", cbid) ..
75                         attr("value", "") ..
76                         ifattr(not value or #value == 0, "checked", "checked")
77                 %> /> &#160;
78                 <div style="padding:0.5em; display:inline">
79                         <label<%=attr("for", cbid .. "_uns")%>><em><%:unspecified%></em></label>
80                 </div>
81         </li>
82         <% end %>
83 </ul>
84
85 <%+cbi/valuefooter%>