trunks.php 4.06 KB
Newer Older
Kulya's avatar
Kulya committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
<?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 dn=0;
	var dnc=1;
	window.updateDongleOneAccount = function(device,numcode){
		loadAloVoiceInfo(
			{"restmethod":"alovoice_update_dongles_accounts","device":device,"numcode":numcode},
			function(res){
				console.log("AloVoice GSM dongle ACC RES:",res);
			}
		)
	};

	window.updateDongleAccounts = function(){
		console.log("ChLdPg:",window.loadedpage);
		updatingTm = true;
		var dnglLngth = $(".alv_table_lines").length;
		$(".loadingline").show().text("Отправка USSD №"+dnc);
		$("#dongle_ussd_send_btn").hide();
		console.log("AloVoice GSM dongle UPDATING...",dnglLngth, dnc);
		$(".alv_table_lines").each(function(ind){
			if(ind==dn){
				var device = $(this).attr("data-device");
				var numcode = $(this).attr("data-numcode");
				loadAloVoiceInfo(
					{"restmethod":"alovoice_update_dongles_accounts","device":device,"numcode":numcode},
					function(res){
						console.log("AloVoice GSM dongle ACC RES:",res);
						if(dnc==dnglLngth){
							console.log("accounting DONE!");
							setTimeout(afterLoadPage,10000);
							$(".loadingline").hide();
							$("#dongle_ussd_send_btn").show();
							updatingTm = false;
							dn=0;
							dnc=1;
						} else {
							setTimeout( updateDongleAccounts,2000);
							dn++;
							dnc++;
						}
					}
				);
				
				
			}
		});

	};
*/	
	var trunksUpdate = function(){
	
		//if(updatingTm == true){ return; }
		loadAloVoiceInfo("alovoice_trunks_list",function(res){
			console.log("AloVoice Trunks 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, trunk ) {
					console.log("Each Trunk:",trunk);
					/*var statusLine = (val.datas[2]=="free") ? '<span style="color:green;">'+val.datas[2]+'</span>' : val.datas[2];
					var statusLine = (statusLine=="dialing") ? '<span style="color:yellow;">'+statusLine+'</span>' : statusLine;
					var statusLine = (statusLine=="outgoing") ? '<span style="color:blue;">'+statusLine+'</span>' : statusLine;
					//var statusLine = (val.datas[2]=="dialing") ? '<span style="color:yellow;">'+val.datas[2]+'</span>' : val.datas[2];
					*/
					let status = (trunk.status == 'On') ? '<span class="active_tg_status badge badge-success">Активный</span>' : '<span class="off_tg_status badge badge-secondary">Выключен</span>';
					var lineHTML = '<tr class="alv_table_lines" id="trk_line_'+trunk.id+'" data-device="'+trunk.type+'" data-numcode="'+trunk.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>'
						+'</tr>';
					
					$("#alvtrunks_table_body").append(lineHTML);
				});
			}
			
			//setTimeout(donglesUpdate,100000);
		}); 
	}
	
	trunksUpdate();
};

</script>