integrations.php 4.98 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
<div class="alvtop_header" id="alv_mainblock"> <?php //card?>
	<center>
		<h3 class="h3 card-body">Интеграции</h3>
		<div class="container" id="integrationsblock">
			<table class="table" id="stats_block_table">
				<thead>
					<tr>
						<th>Интеграция</th>
						<th>Статус</th>
						<th>Действие</th>
					</tr>
				</thead>
				<tbody id="integrations_table_body"></tbody> 
			</table>
		</div>
	</center>

</div>
<script>
var loadAlovoiceStatusLine = function(method,cbk){
	console.log(method+" BEGIN... ");
	$.ajax({
		url: location.origin+location.pathname, 
		dataType: "json",
		data: {
			restmethod:(method) ? method : 'status_integration'
		},
		success: function( result ){
			console.log(method+" RES: " , result);
			if(result.lines){
				result.lines.forEach(function(itg){
					
					if(typeof itg.code !== 'undefined' ){
						$("#"+itg.code).remove();
						$("#integrations_table_body").append(getStatusLineHtml(itg));
					}
				});
			}
			if(typeof result.nextintegration !== 'undefined' ){
				loadAlovoiceStatusLine(result.nextintegration);
			}
			if(typeof cbk !== 'undefined'){
				cbk(result);
			}
		
		}
	});
}

// BX24.callMethod(
   // 'crm.activity.add',
   // {
      // fields:
         // {
            // "OWNER_TYPE_ID": 2,
            // "OWNER_ID": 882,
            // "PROVIDER_ID": 'REST_APP',
            // "PROVIDER_TYPE_ID": 'ecpsign',
            // "SUBJECT": "Документ подписан",
            // "COMPLETED": "Y",
            // "RESPONSIBLE_ID": 1,
            // "DESCRIPTION": "Подписанный документ: Договор (SOFT) PRO-23"
         // }
   // },
   // function(result)
   // {
      // if(result.error())
         // alert("Error: " + result.error());
      // else
      // {
         // alert("Success: " + result.data());
      // }
   // }
// );
// BX24.callMethod(
   // 'crm.activity.add',
   // {
      // fields:
         // {
            // "OWNER_TYPE_ID": 2,
            // "OWNER_ID": 882,
            // "PROVIDER_ID": 'REST_APP',
            // "PROVIDER_TYPE_ID": 'ecpsign',
            // "SUBJECT": "Подписан документ: Договор (SOFT) PRO-23",
            // "COMPLETED": "Y",
            // "RESPONSIBLE_ID": 1,
            // "DESCRIPTION": '[2198]',
         // }
   // },
   // function(result)
   // {
      // if(result.error())
         // console.log("Error: " , result.error());
      // else
      // {
         // console.log("Success: " , result.data());
      // }
   // }
// );


var start_integration = function(code){
	//console.log("integration_on code:" , code);
	loadAloVoiceInfo(
		{"restmethod":"integration_on","code":code},
		function(res){
			console.log("integration_on RES:" , code, res);
			if(res.result && res.result == "success"){
				var iTitle = $('#title_'+code).text();
				$("#"+code).remove();
				var ingHtml = getStatusLineHtml({code:code,title:iTitle,status:'on'});
				console.log("itg HTML:",ingHtml);
				$("#integrations_table_body").append(ingHtml);
			}
		}
	);
	
};

var stop_integration = function(code){
	aloModal({
		label: 'Отключения интеграции',
		body: 'Вы уверены отключить - "'+$('#title_'+code).text()+'"?',
		btn: 'Отключить',
		callback:function(){
			$.ajax({
				url: location.origin+location.pathname, 
				dataType: "json",
				data: {
					restmethod:'integration_off',
					code:code
				},
				success: function( result ){
					console.log("integration_off RES: " , code, result);
					if(result.result && result.result == "success"){
						var iTitle = $('#title_'+code).text();
						$("#"+code).remove();
						var ingHtml = getStatusLineHtml({code:code,title:iTitle,status:'off'});
						console.log("itg HTML:",ingHtml);
						$("#integrations_table_body").append(ingHtml);
					}
				}
			});
		}
	});

	
};

var getStatusLineHtml = function(itg){
	var stCode = (typeof itg.code !== 'undefined' ) ? itg.code : 'Code';
	var stTitle = (typeof itg.title !== 'undefined' ) ? itg.title : 'Title';
	var stStatus = (typeof itg.status !== 'undefined' ) ? itg.status : 'Status';
	
	
	var stText = (stStatus=="off") ? '<span class="badge badge-secondary">Отключён</span>' : '<span class="badge badge-success">Включён</span>';
	
	var stLineHtml = '<tr id="'+stCode+'">';
	stLineHtml += '<td id="title_'+stCode+'">'+stTitle+'</td>';
	stLineHtml += '<td>'+stText+'</td>';
	if(stStatus=="off"){
		stLineHtml += '<td><div onclick="start_integration(\''+stCode+'\');" class="btn btn-success">Вкл</div></td>';
	} else {
		stLineHtml += '<td><div onclick="stop_integration(\''+stCode+'\');" class="btn btn-danger">Выкл</div></td>';
	}
	
	stLineHtml += '</tr>';
	return stLineHtml;
}

var afterLoadPage = function(reload){
	console.log("Integrations page running...");
	loadAlovoiceStatusLine(); //'status_integration'
};


</script>