diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-11-03 17:49:58 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-11-03 17:56:58 +0100 |
commit | 284918bfaf2f6d7e46fb11377bb9a537b35dd58a (patch) | |
tree | 3513e26d15b92f44dc78f607754f1807d1f64c97 /modules/luci-compat/luasrc/view | |
parent | 7a2fefc671ff7b5533620e809a4de07cb3b564a3 (diff) |
treewide: move templates and libraries not used by the core to luci-compat
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-compat/luasrc/view')
4 files changed, 307 insertions, 0 deletions
diff --git a/modules/luci-compat/luasrc/view/cbi/firewall_zonelist.htm b/modules/luci-compat/luasrc/view/cbi/firewall_zonelist.htm new file mode 100644 index 0000000000..7ecec10a8f --- /dev/null +++ b/modules/luci-compat/luasrc/view/cbi/firewall_zonelist.htm @@ -0,0 +1,108 @@ +<%+cbi/valueheader%> + +<%- + local utl = require "luci.util" + local fwm = require "luci.model.firewall".init() + local nwm = require "luci.model.network".init() + + local zone, net, iface + local zones = fwm:get_zones() + local value = self:formvalue(section) + if not value or value == "-" then + value = self:cfgvalue(section) or self.default + end + + local selected = false + local checked = { } + + for value in utl.imatch(value) do + checked[value] = true + end + + if not next(checked) then + checked[""] = true + end +-%> + +<div class="cbi-dropdown" dropdown-items="5" placeholder="<%:-- please select -- %>"<%= + attr("name", cbid) .. + ifattr(self.widget == "checkbox", "multiple", "multiple") .. + ifattr(self.rmempty or self.optional, "optional", "optional") +%>> + <script type="item-template"><!-- + <li data-value="{{value}}"> + <span class="zonebadge" style="background:repeating-linear-gradient(45deg,rgba(204,204,204,0.5),rgba(204,204,204,0.5) 5px,rgba(255,255,255,0.5) 5px,rgba(255,255,255,0.5) 10px)"> + <strong>{{value}}:</strong><em>(<%:create%>)</em> + </span> + </li> + --></script> + <ul> + <% if self.allowlocal then %> + <li data-value=""<%=ifattr(checked[""], "selected", "selected")%>> + <span style="background-color:<%=fwm.zone.get_color()%>" class="zonebadge"> + <strong><%:Device%></strong> + <% if self.allowany and self.allowlocal then -%> + (<%= self.alias ~= "dest" + and translate("output") or translate("input") %>) + <%- end %> + </span> + </li> + <% elseif self.widget ~= "checkbox" and (self.rmempty or self.optional) then %> + <li data-value=""<%=ifattr(checked[""], "selected", "selected")%>> + <span class="zonebadge"> + <em><%:unspecified%></em> + </span> + </li> + <% end %> + <% if self.allowany then %> + <li data-value="*"<%=ifattr(checked["*"], "selected", "selected")%>> + <span style="background-color:<%=fwm.zone.get_color()%>" class="zonebadge"> + <strong><%:Any zone%></strong> + <% if self.allowany and self.allowlocal then %>(<%:forward%>)<% end %> + </span> + </li> + <% end %> + <% + for _, zone in utl.spairs(zones, function(a,b) return (zones[a]:name() < zones[b]:name()) end) do + if zone:name() ~= self.exclude then + selected = selected or (value == zone:name()) + %> + <li<%=attr("data-value", zone:name()) .. ifattr(checked[zone:name()], "selected", "selected")%>> + <span style="background-color:<%=zone:get_color()%>" class="zonebadge"> + <strong><%=zone:name()%>:</strong> + <%- + local zempty = true + for _, net in ipairs(zone:get_networks()) do + net = nwm:get_network(net) + if net then + zempty = false + -%> + <span class="ifacebadge<% if net:name() == self.network then %> ifacebadge-active<% end %>"><%=net:name()%>: + <%- + local nempty = true + for _, iface in ipairs(net:is_bridge() and net:get_interfaces() or { net:get_interface() }) do + nempty = false + %> + <img<%=attr("title", iface:get_i18n())%> src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" /> + <% end %> + <% if nempty then %><em><%:(empty)%></em><% end -%> + </span> + <%- end end -%> + <%- if zempty then %><em><%:(empty)%></em><% end -%> + </span> + </li> + <% end end %> + + <% if self.widget ~= "checkbox" and not self.nocreate then %> + <li data-value="-"> + <span class="zonebadge"> + <em><%:create%>:</em> + <input type="password" style="display:none" /> + <input class="create-item-input" type="text" data-type="and(uciname,maxlength(11))" data-optional="true" /> + </span> + </li> + <% end %> + </ul> +</div> + +<%+cbi/valuefooter%> diff --git a/modules/luci-compat/luasrc/view/cbi/network_ifacelist.htm b/modules/luci-compat/luasrc/view/cbi/network_ifacelist.htm new file mode 100644 index 0000000000..f23e51d18d --- /dev/null +++ b/modules/luci-compat/luasrc/view/cbi/network_ifacelist.htm @@ -0,0 +1,91 @@ +<%+cbi/valueheader%> + +<%- + local utl = require "luci.util" + local net = require "luci.model.network".init() + local cbeid = luci.cbi.FEXIST_PREFIX .. self.config .. "." .. section .. "." .. self.option + + local iface + local ifaces = net:get_interfaces() + local value + + if self.map:formvalue(cbeid) == "1" then + value = self:formvalue(section) or self.default or "" + else + value = self:cfgvalue(section) or self.default + end + + local checked = { } + + if value then + for value in utl.imatch(value) do + for value in utl.imatch(value) do + checked[value] = true + end + end + else + local n = self.network and net:get_network(self.network) + if n then + local a = n:is_alias() + if a then + checked['@' .. a] = true + else + local i + for _, i in ipairs(n:get_interfaces() or { n:get_interface() }) do + checked[i:name()] = true + end + end + end + end +-%> + +<input type="hidden" name="<%=cbeid%>" value="1" /> + +<div class="cbi-dropdown" display-items="10" placeholder="<%:-- please select -- %>"<%= + attr("name", cbid) .. + ifattr(self.widget == "checkbox", "multiple", "multiple") .. + ifattr(self.widget == "checkbox", "optional", "optional") +%>> + <script type="item-template"><!-- + <li data-value="{{value}}"> + <img title="<%:Custom Interface%>: "{{value}}"" src="<%=resource%>/icons/ethernet_disabled.png" /> + <span class="hide-open">{{value}}</span> + <span class="hide-close"><%:Custom Interface%>: "{{value}}"</span> + </li> + --></script> + <ul> + <% for _, iface in ipairs(ifaces) do + if (not self.noaliases or iface:type() ~= "alias") and + (not self.nobridges or not iface:is_bridge()) and + (not self.noinactive or iface:is_up()) and + iface:name() ~= self.exclude + then %> + <li<%= + attr("data-value", iface:name()) .. + ifattr(checked[iface:name()], "selected", "selected") + %>> + <img<%=attr("title", iface:get_i18n())%> src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" /> + <span class="hide-open"><%=pcdata(iface:name())%></span> + <span class="hide-close"> + <%=pcdata(iface:get_i18n())%> + <% local ns = iface:get_networks(); if #ns > 0 then %>( + <%- local i, n; for i, n in ipairs(ns) do -%> + <%-= (i>1) and ', ' -%> + <a href="<%=n:adminlink()%>"><%=n:name()%></a> + <%- end -%> + )<% end %> + </span> + </li> + <% end end %> + <% if not self.nocreate then %> + <li data-value=""> + <img title="<%:Custom Interface%>" src="<%=resource%>/icons/ethernet_disabled.png" /> + <span><%:Custom Interface%>:</span> + <input type="password" style="display:none" /> + <input class="create-item-input" type="text" /> + </li> + <% end %> + </ul> +</div> + +<%+cbi/valuefooter%> diff --git a/modules/luci-compat/luasrc/view/cbi/network_netinfo.htm b/modules/luci-compat/luasrc/view/cbi/network_netinfo.htm new file mode 100644 index 0000000000..4fd84112a4 --- /dev/null +++ b/modules/luci-compat/luasrc/view/cbi/network_netinfo.htm @@ -0,0 +1,27 @@ +<%+cbi/valueheader%> + +<%- + local value = self:formvalue(section) + if not value or value == "-" then + value = self:cfgvalue(section) or self.default + end + + local nwm = require "luci.model.network".init() + local net = nwm:get_network(value) +-%> + +<% if net then %> +<span class="ifacebadge"><%=net:name()%>: + <% + local empty = true + for _, iface in ipairs(net:get_interfaces() or { net:get_interface() }) do + if not iface:is_bridge() then + empty = false + %> + <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" /> + <% end end %> + <% if empty then %><em><%:(no interfaces attached)%></em><% end %> +</span> +<% end %> + +<%+cbi/valuefooter%> diff --git a/modules/luci-compat/luasrc/view/cbi/network_netlist.htm b/modules/luci-compat/luasrc/view/cbi/network_netlist.htm new file mode 100644 index 0000000000..3ee4274a33 --- /dev/null +++ b/modules/luci-compat/luasrc/view/cbi/network_netlist.htm @@ -0,0 +1,81 @@ +<%+cbi/valueheader%> + +<%- + local utl = require "luci.util" + local nwm = require "luci.model.network".init() + + local net, iface + local networks = nwm:get_networks() + local value = self:formvalue(section) + + self.cast = nil + + if not value or value == "-" then + value = self:cfgvalue(section) or self.default + end + + local checked = { } + for value in utl.imatch(value) do + checked[value] = true + end +-%> + +<div class="cbi-dropdown" display-items="10" placeholder="<%:-- please select -- %>"<%= + attr("name", cbid) .. + ifattr(self.widget == "checkbox", "multiple", "multiple") .. + ifattr(self.widget == "checkbox", "optional", "optional") +%>> + <script type="item-template"><!-- + <li data-value="{{value}}"> + <span class="ifacebadge" style="background:repeating-linear-gradient(45deg,rgba(204,204,204,0.5),rgba(204,204,204,0.5) 5px,rgba(255,255,255,0.5) 5px,rgba(255,255,255,0.5) 10px)"> + {{value}}: <em>(<%:create%>)</em> + </span> + </li> + --></script> + <ul> + <% if self.widget ~= "checkbox" then %> + <li data-value=""<%= ifattr(not value, "selected", "selected") %>> + <em><%:unspecified%></em> + </li> + <% end %> + + <% for _, net in ipairs(networks) do + if (net:name() ~= "loopback") and + (net:name() ~= self.exclude) and + (not self.novirtual or not net:is_virtual()) + then %> + <li<%= attr("data-value", net:name()) .. ifattr(checked[net:name()], "selected", "selected") %>> + <span class="ifacebadge"><%=net:name()%>: + <% + local empty = true + for _, iface in ipairs(net:is_bridge() and net:get_interfaces() or { net:get_interface() }) do + if not iface:is_bridge() then + empty = false + -%> + <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" /> + <%- end end %> + <% if empty then %> + <em class="hide-close"><%:(no interfaces attached)%></em> + <em class="hide-open">-</em> + <% end %> + </span> + </li> + <% end end %> + + <% if not self.nocreate then %> + <li data-value="-"<%= ifattr(not value and self.widget ~= "checkbox", "selected", "selected") %>> + <em> + <%- if self.widget == "checkbox" then -%> + <%:create:%> + <%- else -%> + <%:unspecified -or- create:%> + <%- end -%> + </em> + <input style="display:none" type="password" /> + <input class="create-item-input" type="text" /> + </li> + <% end %> + </ul> +</div> + +<%+cbi/valuefooter%> |