<!--// $Id$ //-->

{css}

<form method="GET" action="?m=netdevedit" name="connectnode" id="connectnode-form">
</form>

{$lastonline_limit=ConfigHelper::getConfig('phpui.lastonline_limit')}

{tab_container id="netdevipbox"}

	{tab_header content_id="devicenodes"}
		{tab_header_cell icon="lms-ui-icon-node"}
			<strong>{if empty($netcomplist)}{$netcomplist=array()}{/if}{t a=$netcomplist|@count}Connected nodes ($a):{/t}</strong>
		{/tab_header_cell}
	{/tab_header}

	{tab_contents id="devicenodes"}

		{tab_table}

			{if $netcomplist}
			<div class="lms-ui-tab-table-row header">
				<div class="lms-ui-tab-table-wrapper col-8">
					<div class="lms-ui-tab-table-wrapper name-owner-nodeid-ownerid col-4">
						<div class="lms-ui-tab-table-wrapper name-owner col-2">
							<div class="lms-ui-tab-table-column name">
								<i class="lms-ui-icon-node"></i> <strong>{trans("Name:")}</strong>
								/ <i class="lms-ui-icon-location"></i> {trans("Location:")}
							</div>
							<div class="lms-ui-tab-table-column owner">
								<i class="lms-ui-icon-customer"></i> {trans("Owner:")}
							</div>
						</div>
						<div class="lms-ui-tab-table-wrapper nodeid-ownerid col-2">
							<div class="lms-ui-tab-table-column nodeid">
								{trans("Node ID:")}
							</div>
							<div class="lms-ui-tab-table-column ownerid">
								{trans("Customer ID:")}
							</div>
						</div>
					</div>
					<div class="lms-ui-tab-table-wrapper link-taken-ports-network col-4">
						<div class="lms-ui-tab-table-wrapper link col-2">
							<div class="lms-ui-tab-table-column link-tech">
								{trans("Link technology:")}
							</div>
							<div class="lms-ui-tab-table-column link-speed">
								{trans("Link speed:")}
							</div>
						</div>
						<div class="lms-ui-tab-table-wrapper taken-ports-network col-2">
							<div class="lms-ui-tab-table-column taken-ports">
								<i class="lms-ui-icon-plug"></i> {trans("Port")}:
							</div>
							<div class="lms-ui-tab-table-column network">
								<i class="lms-ui-icon-ipnetwork"></i> {trans("Network")} / {trans("IP address:")}
							</div>
						</div>
					</div>
				</div>

				<div class="lms-ui-tab-table-column buttons">
					&nbsp;
				</div>
			</div>
			{/if}

			{foreach $netcomplist as $node}
			<div class="lms-ui-tab-table-row">
				<div class="lms-ui-tab-table-wrapper col-8">
					<div class="lms-ui-tab-table-wrapper name-owner-nodeid-ownerid col-4">
						<div class="lms-ui-tab-table-wrapper name-owner col-2">
							<div class="lms-ui-tab-table-column name" data-target-url="?m=nodeinfo&id={$node.id}">
								{if $node.lastonline}
									{if ($smarty.now-$node.lastonline) > $lastonline_limit}
										<i class="lms-ui-icon-nodeoff" {tip a=$node.lastonlinedate text="Last online: \$a"}></i>
									{else}
										<i class="lms-ui-icon-nodeon" {tip a="on-line" text="Last online: \$a"}></i>
									{/if}
								{else}
									<i class="lms-ui-icon-nodeunk"></i>
								{/if}
								<strong>{$node.name}</strong>
								{if $node.location}
									/ <i class="lms-ui-icon-location"></i>
									{$node.location}{if $node.borough_name} ({$node.state_name} / {$node.district_name} / {$_BOROUGHTYPES[$node.borough_type]} {$node.borough_name}){/if}
								{else}
									-
								{/if}
							</div>
							<div class="lms-ui-tab-table-column owner" data-target-url="?m=nodeinfo&id={$node.id}">
								<i class="lms-ui-icon-customer"></i>
								<A href="?m=customerinfo&id={$node.ownerid}"
									class="lms-ui-hint-rollover"
									data-url="?m=customerinfoshort&id={$node.ownerid}"
									>{$node.owner}</A>
							</div>
						</div>
						<div class="lms-ui-tab-table-wrapper nodeid-ownerid col-2">
							<div class="lms-ui-tab-table-column nodeid" data-target-url="?m=nodeinfo&id={$node.id}">
								({$node.id|string_format:"%04d"})
							</div>
							<div class="lms-ui-tab-table-column ownerid blend" data-target-url="?m=nodeinfo&id={$node.id}">
								({$node.ownerid|string_format:"%04d"})
							</div>
						</div>
					</div>
					<div class="lms-ui-tab-table-wrapper link-taken-ports-network col-4">
						<div class="lms-ui-tab-table-wrapper link col-2">
							<div class="lms-ui-tab-table-column link-tech" id="node-link-tech-{$node.id}" data-target-url="?m=nodeinfo&id={$node.id}">
								{if $node.linktechnology}{$_LINKTECHNOLOGIES[$node.linktype][$node.linktechnology]}{else}-{/if}
								{if $node.linktype == $smarty.const.LINKTYPE_WIRELESS && $node.radiosector} ({$node.radiosector}){/if}
							</div>
							<div class="lms-ui-tab-table-column link-speed" id="node-link-speed-{$node.id}" data-target-url="?m=nodeinfo&id={$node.id}">
								{if $node.linkspeed}{$_LINKSPEEDS[$node.linkspeed]}{else}-{/if}
							</div>
						</div>
						<div class="lms-ui-tab-table-wrapper taken-ports-network col-2">
							<div class="lms-ui-tab-table-column taken-ports">
								<span id="node-link-port-{$node.id}" class="node-link-port"
									data-netdev="{$netdev.id}" data-node="{$node.id}">
									<i class="{if $node.linktype == $smarty.const.LINKTYPE_WIRELESS}lms-ui-icon-wireless{elseif $node.linktype == $smarty.const.LINKTYPE_FIBER}lms-ui-icon-fiber{else}lms-ui-icon-wired{/if}"
											{tip trigger="node-link-port-{$node.id}"
												text="<span class=\"nobr\">{trans("Link type:")} {$_LINKTYPES[$node.linktype]}<br>{if $node.linktype == $smarty.const.LINKTYPE_WIRELESS && $node.radiosector}{trans("Radio sector:")} {$node.radiosector}<br>{/if}{if $node.linktechnology}{trans("Link technology:")} {$_LINKTECHNOLOGIES[$node.linktype][$node.linktechnology]}<br>{/if}{trans("Link speed:")} {$_LINKSPEEDS[$node.linkspeed]}</span>"}>
									</i>
								</span>
								<span id="node-link-srcport-{$node.id}">
									[{if $node.port}{$node.port}{else}-{/if}]
								</span>
							</div>
							<div class="lms-ui-tab-table-column network" data-target-url="?m=nodeinfo&id={$node.id}">
								<i class="lms-ui-icon-ipnetwork"></i> {$node.netname} / {$node.ip}
								{if $node.ip_pub != "0.0.0.0"} ({$node.ip_pub}){/if}
							</div>
						</div>
					</div>
				</div>

				<div class="lms-ui-tab-table-column buttons">
					{button type="link" class="disconnectnode" href="?m=netdevedit&action=disconnectnode&id={$netdev.id}&nodeid={$node.id}" icon="delete" tip="Delete connection"}
				</div>
			</div>
			{foreachelse}

			<div class="lms-ui-tab-empty-table">
				{trans("No such connected nodes.")}
			</div>
			{/foreach}

		{/tab_table}

		{tab_button_panel}
			{tab_buttons}
				{if $netdev.ports == $netdev.takenports}
					<strong>{trans("All ports in that device are in use.")}</strong>
				{elseif $nodelist == NULL}
					<strong>{trans("No such nodes to connection.")}</strong>
				{else}
					<INPUT TYPE="HIDDEN" NAME="m" VALUE="netdevedit" form="connectnode-form">
					<INPUT TYPE="HIDDEN" NAME="id" VALUE="{$netdev.id}" form="connectnode-form">
					<INPUT TYPE="HIDDEN" NAME="action" VALUE="connectnode" form="connectnode-form">

					<strong>{trans("Connect")}:</strong>
					<span class="nobr">
						{trans("Node:")}
						<SELECT NAME="nodeid" style="width: 300px" {tip class="lms-ui-advanced-select-test" trigger="linknode" text="Select node, which you want to connect to device"}
								form="connectnode-form">
							{foreach $nodelist as $node}
								<OPTION VALUE="{$node.id}"{if $connectnode.id == $node.id} selected{/if}>{$node.name} ({$node.ip})</OPTION>
							{/foreach}
						</SELECT>
						<a href="#" onclick="return nodeChooseWin(document.connectnode.elements['nodeid']);" {tip trigger="netdev" text="Search node"}>&raquo;&raquo;&raquo;</A>&nbsp;
					</span>

					<label class="nobr">
						{trans("Dest. port")}:
						<INPUT type="text" name="port" id="port"
								value="{if $connectnode.port}{$connectnode.port}{/if}" size="2" {tip text="Enter port number in device (optional)" trigger="port"}
								form="connectnode-form">
					</label>
					<SELECT NAME="radiosector" id="devnodesradiosector"
							{tip trigger="devnodesradiosector" text="Select radio sector"}{if $nodelinktype != 1} style="display: none;"{/if}
							form="connectnode-form">
						<OPTION value="0">{trans("— none —")}</OPTION>
						{foreach $netdev.radiosectors as $radiosector}
							<OPTION value="{$radiosector.id}"{if $radiosector.id == $nodelinkradiosector} selected{/if}>{$radiosector.name}</OPTION>
						{/foreach}
					</SELECT>
					<select name="linktype" id="devnodeslinktype" {tip trigger="devnodeslinktype" text="Select link type"}
							onchange="change_nodelinktype(this.options[this.selectedIndex].value)"
							form="connectnode-form">
						{foreach $_LINKTECHNOLOGIES as $linktype => $linktech}
							<option value="{$linktype}"{if $linktype == $nodelinktype} selected{/if}>{$_LINKTYPES[$linktype]}</option>
						{/foreach}
					</select>
					{if !isset($nodelinktype)}{$devnodeslinktype = 0}{else}{$devnodeslinktype = $nodelinktype}{/if}
					<SELECT NAME="linktechnology" id="devnodeslinktechnology"
							{tip trigger="devnodeslinktechnology" text="Select link technology"} onchange="change_nodelinktechnology()"
							form="connectnode-form">
						<OPTION value="0">{trans("— unknown —")}</OPTION>
						{foreach $_LINKTECHNOLOGIES[$devnodeslinktype] as $linktechnologyidx => $linktechnology}
							<OPTION value="{$linktechnologyidx}"{if $linktechnologyidx == $nodelinktechnology} selected{/if}>{$linktechnology}</OPTION>
						{/foreach}
					</SELECT>
					<SELECT NAME="linkspeed" id="devnodeslinkspeed" {tip trigger="devnodeslinkspeed" test="Select link speed"}
							form="connectnode-form">
						{foreach $_LINKSPEEDS as $key => $item}
							<OPTION value="{$key}"{if $key==$nodelinkspeed || (!$nodelinkspeed && $key==100000)} selected{/if}>{$item}</OPTION>
						{/foreach}
					</SELECT>
					{button icon="save" onclick="javascript:document.connectnode.submit();" label="Connect"}
				{/if}
			{/tab_buttons}
		{/tab_button_panel}

	{/tab_contents}

{/tab_container}

<SCRIPT>

	function change_nodelinktype(linktype) {
		linktype = parseInt(linktype);
		var options = xjx.$('devnodeslinktechnology').options;
		while (options.length)
			options.remove(0);
		options.add(new Option('{trans("— unknown —")}', 0));
		switch (linktype) {
			case 0:
				{foreach $_LINKTECHNOLOGIES[0] as $linktechnologyidx => $linktechnology}
				options.add(new Option('{$linktechnology}', {$linktechnologyidx}));
				{/foreach}
				break;
			case 1:
				{foreach $_LINKTECHNOLOGIES[1] as $linktechnologyidx => $linktechnology}
				options.add(new Option('{$linktechnology}', {$linktechnologyidx}));
				{/foreach}
				break;
			case 2:
				{foreach $_LINKTECHNOLOGIES[2] as $linktechnologyidx => $linktechnology}
				options.add(new Option('{$linktechnology}', {$linktechnologyidx}));
				{/foreach}
				break;
		}
		xjx.$('devnodesradiosector').style.display = (linktype == 1 ? '' : 'none');
		xajax_getRadioSectorsForNetdev('radio_sectors_received_for_node', {$netdev.id});
	}

	function change_nodelinktechnology() {
		linktechnology = parseInt(xjx.$('devnodeslinktechnology').options[xjx.$('devnodeslinktechnology').selectedIndex].value);
		var linktype = xjx.$('devnodeslinktype').value;
		if (linktype != 1)
			return;
		xjx.$('devnodesradiosector').disabled = true;
		xajax_getRadioSectorsForNetdev('radio_sectors_received_for_node', {$netdev.id}, linktechnology);
	}

	function radio_sectors_received_for_node(radiosectors) {
		var options = xjx.$('devnodesradiosector').options;
		var oldvalue = options[xjx.$('devnodesradiosector').selectedIndex].value;
		while (options.length)
			options.remove(0);
		options.add(new Option('{trans("none")}', 0));
		if (radiosectors !== null) {
			radiosectors.forEach(function(elem) {
				var option = new Option(elem.name, elem.id);
				if (elem.id == oldvalue)
					option.selected = true;
				options.add(option);
			});
		}
		xjx.$('devnodesradiosector').disabled = false;
	}

	$('.disconnectnode').click(function() {
		confirmDialog($t("Are you sure, you want to delete that connection?"), this).done(function() {
			location.href = $(this).attr('href');
		});
		return false;
	});

</SCRIPT>
