<%#
LuCI - Lua Configuration Interface
Copyright 2009 Jo-Philipp Wich <xm@subsignal.org>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

$Id$

-%>
<%+cbi/valueheader%>

<%-
	local utl = require "luci.util"
	local net = require "luci.model.network".init()

	local iface
	local ifaces = net:get_interfaces()
	local value = self:formvalue(section)

	if not value or value == "" then
		value = self:cfgvalue(section) or self.default
	end

	local checked = { }

	if value then
		for value in utl.imatch(value) do
			checked[value] = true
		end
	else
		local n = self.network and net:get_network(self.network)
		if n then
			local i
			for _, i in ipairs(n:get_interfaces()) do
				checked[i:name()] = true
			end
		end
	end
-%>

<ul style="margin:0; list-style-type:none">
	<% for _, iface in ipairs(ifaces) do
	     local link = iface:adminlink()
         if (not self.nobridges or not iface:is_bridge()) and iface:name() ~= self.exclude then %>
	<li>
		<input class="cbi-input-<%=self.widget or "radio"%>" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)"<%=
			attr("type", self.widget or "radio") ..
			attr("id", cbid .. "." .. iface:name()) ..
			attr("name", cbid) .. attr("value", iface:name()) ..
			ifattr(checked[iface:name()], "checked", "checked") ..
			ifattr(iface:type() == "wifi" and not iface:is_up(), "disabled", "disabled")
		%> /> &nbsp;
		<label<%=attr("for", cbid .. "." .. iface:name())%>>
			<% if link then -%><a href="<%=link%>"><% end -%>
			<img title="<%=iface:get_type_i18n()%>" style="width:16px; height:16px; vertical-align:middle" src="<%=resource%>/icons/<%=iface:type()%><%=iface:is_up() and "" or "_disabled"%>.png" />
			<% if link then -%></a><% end -%>
			<%=iface:get_i18n()%><% local n = iface:get_network(); if n then %> (<a href="<%=n:adminlink()%>"><%=n:name()%></a>)<% end %>
		</label>
	</li>
	<% end end %>
	<% if not self.nocreate then %>
	<li>
		<input class="cbi-input-<%=self.widget or "radio"%>" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)"<%=
			attr("type", self.widget or "radio") ..
			attr("id", cbid .. "_custom") ..
			attr("name", cbid)
		%> /> &nbsp;
		<label<%=attr("for", cbid .. "_custom")%>>
			<img title="<%:Custom Interface%>" style="width:16px; height:16px; vertical-align:middle" src="<%=resource%>/icons/ethernet_disabled.png" />
			<%:Custom Interface%>:
		</label>
		<input type="text" style="width:50px" onfocus="document.getElementById('<%=cbid%>_custom').checked=true" onblur="var x=document.getElementById('<%=cbid%>_custom'); x.value=this.value; x.checked=true" />
	</li>
	<% end %>
</ul>

<%+cbi/valuefooter%>
