<%@page contentType="text/html; charset=UTF-8"%>
	<div id="cc" class="easyui-layout" data-options="fit:true" style="width:100%;height:100%;">
		<div data-options="region:'east'" style="width: 200px;">
			<table id="inr"></table>
		</div>
		<div data-options="region:'west'" style="width: 200px;">
			<table id="notr"></table>
		</div>
		<div data-options="region:'center'">
		   <div style="border:1px solid #c0c0c0;height:100%;overflow:hidden;">
			<div align="center" style="padding: 30px 0px;">
				<a href="javascript:leftAll()" class="easyui-linkbutton"
					style="width: 50px;">&gt;&gt;</a>
			</div>
			<div align="center" style="padding: 30px 0px;">
				<a href="javascript:leftOne()" class="easyui-linkbutton"
					style="width: 50px;">&gt;</a>
			</div>
			<div align="center" style="padding: 30px 0px;">
				<a href="javascript:rightOne()" class="easyui-linkbutton"
					style="width: 50px;">&lt;</a>
			</div>
			<div align="center" style="padding: 30px 0px;">
				<a href="javascript:rightAll()" class="easyui-linkbutton"
					style="width: 50px;">&lt;&lt;</a>
			</div>
			</div>
		</div>
		<!--  <div data-options="region:'south'" style="padding:5px;background:#fafafa;width:500px;border:1px solid #ccc;text-align:right">
			<a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-save" onclick="addToPush()">推送</a>
		</div>  -->
	</div>
<SCRIPT type="text/javascript">
tbreload('${param.uuid}');
function tbreload(userid){
	current_user_id = userid;
	$.sendPost ('jwAppsPushDataData_listAllPushApp', {FIELD_PUSH_DATA_ID:userid,FIELD_TYPE:'${param.type}'}, function(v_pushapp){
		$.sendPost ('jwAppsCommonData_listSysUserAll', {FIELD_EMDEPART:"A",FIELD_ISPUSH:"1"}, function(v_webservice){
			var v_notr = [];
			if(v_webservice.rowSet!=null && v_pushapp.rowSet!=null && v_webservice.rowSet.length>0 && v_pushapp.rowSet.length>0){
			  $.each(v_webservice.rowSet, function(i,n){
				var i = 0;
				$.each(v_pushapp.rowSet, function(j,m){
					if(m.CLIENT_CODE == n.CODE){
						i=0;
						return false;
					}else{
						i++;
					}
				});
				if(i >0){
					v_notr.push(n);
				}
			  });
			}else{
				v_notr = v_webservice.rowSet;
			}
			$('#notr').datagrid({    
			     data:v_notr,
			     singleSelect:true, //是否多选
			   	 columns:[
		            [{field:'CODE',title:'编号',hidden:'true'},
		             {field:'EMNAME',title:'未选应用',width:190,align:'center'}
		             ]
		           ]
			 });
			$('#inr').datagrid({    
			     data:v_pushapp.rowSet,
			     singleSelect:true, //是否多选
		   		columns:[
	            [{field:'UUID',title:'编号',hidden:'true'},
	             {field:'CLIENT_CODE_NAME',title:'已选应用',width:190,align:'center'}
	             ]
           ]
			 });
		}, function(data){
			alert("失败");
		}, "json");
	}, function(data){
		alert("失败");
	}, "json");
}

function leftAll(){
	var v_webservice = $("#notr").datagrid("getRows");;
	var v_entity = {};
	$.each(v_webservice, function(i,n){
		v_entity.FIELD_TYPE = '${param.type}';
		v_entity.FIELD_PUSH_DATA_ID = current_user_id;
		v_entity.FIELD_CLIENT_CODE = n.CODE;
		$.sendPost ('jwAppsPushDataAct_insertPushApp', v_entity, function(v_result){
				tbreload(current_user_id);
			}, function(data){
				alert("失败");
			}, "json");
	});
	
}
function leftOne(){
	var row = $("#notr").datagrid('getSelected');
	if(row == null || row == ""){
		$.messager.alert('提示',"请选择需同步数据的应用!");
		return;
	}
	var v_entity = {};
	v_entity.FIELD_TYPE = '${param.type}';
	v_entity.FIELD_PUSH_DATA_ID = current_user_id;
	v_entity.FIELD_CLIENT_CODE = row.CODE;
	$.sendPost ('jwAppsPushDataAct_insertPushApp', v_entity, function(v_result){
		tbreload(current_user_id);
	}, function(data){
		alert("失败");
	}, "json");
	
}
function rightOne(){
	var row = $("#inr").datagrid('getSelected');
	if(row == null || row == ""){
		$.messager.alert('提示',"请选择右边不用同步的应用!");
		return;
	}
	var v_entity = {};
	v_entity.FIELD_UUID = row.UUID;
	v_entity.FIELD_TYPE = '${param.type}';
	$.sendPost ('jwAppsPushDataAct_deletePushApp_map', v_entity, function(v_result){
			tbreload(current_user_id);
		}, function(data){
			alert("失败");
		}, "json");
}
function rightAll(){
	var v_pushapp = $("#inr").datagrid("getRows");;
	var v_entity = {};
	$.each(v_pushapp, function(i,n){
		v_entity.FIELD_UUID = n.UUID;
		v_entity.FIELD_TYPE = '${param.type}';
		$.sendPost ('jwAppsPushDataAct_deletePushApp_map', v_entity, function(v_result){
			tbreload(current_user_id);
		}, function(data){
			alert("失败");
		}, "json");
	});	
}
/* function addToPush(){
	var v_query = {};
    v_query.deletekey = '${param.uuid}';
	$.sendPost ('jwAppsUnitAct_pushUnitRow', v_query, function(v_result){
		$.messager.alert('提示',v_result.VALUE);
	}, function(data){
		alert("失败");
	}, "json");
}  */
</SCRIPT>
