<?php namespace AloVoice; ?>
<style>
	.alv_table_lines .nowrp {
		white-space: nowrap;
	}
	.loadingline{
		display:none;
	}
</style>
<center>
	<h3 class="h3 card-body">Внутренние номера</h3> 
	<div class="loadingline"></div>
	<!---a href="#" onClick="addNewTrunk()" id="trunk_add_button" class="btn btn-primary title_line_button"><i class="fa fa-arrow-down"></i>  + Добавить </a--->
</center>
<br/>

<table class="table" id="stats_block_table">
	<thead>
		<tr id="alvtrunks_table_header"></tr>
	</thead>
	<tbody id="alvtrunks_table_body"> </tbody> 
</table>

<script>

var afterLoadPage = function(){
	var isHeadered = false;
	var peersUpdate = function(){
	
		//if(updatingTm == true){ return; }
		loadAloVoiceInfo("alovoice_peers_list",function(res){
			console.log("AloVoice Peers RES:",res);

			if(!isHeadered){
				if(typeof res.headers != 'undefined' ){
					isHeadered = true;
					$("#alvtrunks_table_header").html('');
					
					$.each( res.headers, function( key, value ) {					
						console.log("Each Header:",key, value);
						$("#alvtrunks_table_header").append('<th id="hd_'+key+'">'+value+'</th>');
					});
				}
			}
			
			if(typeof res.datas != 'undefined' ){
				$("#alvtrunks_table_body").html('');
				$.each( res.datas, function( tkey, peer ) {
					console.log("Each peer:",peer);
					var lineHTML = '<tr class="alv_table_lines" id="trk_line_'+peer.id+'">'
					$.each( res.headers, function( hkey, value ) {
						lineHTML += '<td>'+peer[hkey]+'</td>'
					});
					lineHTML += '</tr>';
					
					
					/*let status = (peer.status == 'Off') ? '<span class="off_tg_status badge badge-secondary">Выключен</span>' : '<span class="active_tg_status badge badge-success">'+peer.status+'</span>';
					var lineHTML = '<tr class="alv_table_lines" id="trk_line_'+peer.id+'" data-device="'+peer.type+'" data-numcode="'+peer.name+'">'
						+'<td class="nowrp" > <span>'+trunk.id+'</span></td>'
						+'<td class="nowrp" > <b>'+trunk.name+'</b></td>'
						+'<td class="nowrp" >'+trunk.type +'</td>'
						+'<td>'+trunk.number+'</td>'
						+'<td>'+trunk.maxchannels+'</td>'
						+'<td>'+status+'</td>'
						+'<td class="nowrp" ><a href="#" onClick="updateOneTrunk(\''+trunk.id+'\');"><i class="fa fa-money"></i> Проверить</a></td>'
						+'';*/
					
					$("#alvtrunks_table_body").append(lineHTML);
				});
			}
			
			//setTimeout(donglesUpdate,100000);
		}); 
	}
	
	peersUpdate();
};

</script>