You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

337 lines
12 KiB
JavaScript

var commonGridObj_range;
var comboCustomer;//委托单位
var user_tree;
function $(id){
return document.getElementById(id);
}
function createUserTree(){
user_tree = new dhtmlXTreeObject("dvUserTree","100%","100%",0);
user_tree.setSkin('dhx_skyblue');
user_tree.setImagePath("../images/csh_dhx_skyblue/");
var url = "../WorkFlow/WorkFlowGridSource.aspx?handle=usertree&uid="+newGuid();
user_tree.loadJSON(url,function(){
finishLoading();
});
user_tree.enableCheckBoxes(true);
user_tree.attachEvent("onClick", function(id){
initLoading();
user_tree.setCheck(id,true);
createGrid(id);
$("h_checkuser").value = getID(id);
var selectedVal = user_tree.getAllChecked();
var selectedArg = new Array();
if(selectedVal.indexOf(",") >= 0){
selectedArg = selectedVal.split(",");
}else{
selectedArg.push(selectedVal);
}
for(var i=0;i<selectedArg.length;i++){
if(selectedArg[i] != id){
user_tree.setCheck(selectedArg[i],false);
}
}
});
user_tree.attachEvent("onCheck", function(id,state){
if(state){
user_tree.setCheck(id,true);
createGrid(id);
$("h_checkuser").value = getID(id);
var selectedVal = user_tree.getAllChecked();
var selectedArg = new Array();
if(selectedVal.indexOf(",") >= 0){
selectedArg = selectedVal.split(",");
}else{
selectedArg.push(selectedVal);
}
for(var i=0;i<selectedArg.length;i++){
if(selectedArg[i] != id){
user_tree.setCheck(selectedArg[i],false);
}
}
}
});
}
function createGrid(user){
var tempUserID = "";//"1BEC90E1-9780-472F-90C2-0C6390C044A4";
if(user.trim() != ""){
if(validateType(user.trim()) == 1){
tempUserID = getID(user.trim());
}
}
//header
var headerArgs_range = new Array("模块名称","可视范围,#cspan,#cspan,#cspan,#cspan","可操作范围,#cspan,#cspan,#cspan,#cspan");//
//width
var widthArgs_range = new Array("150", "60", "60", "60", "60", "60", "60", "60", "60", "60", "60", "60", "60");
//column align
var colAlignArgs_range = new Array("left", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center", "center");
//column sort
var colSortArgs_range = new Array("str","str","str","str","str","str","str","str","str","str","str","str","str");
//column type
var colTypeArgs_range = new Array("ro","ch","ch","ch","ch","ch","ch","ch","ch","ch","ch","ch","ch");
commonGridObj_range = new TGridCommon("mygrid_container_range","form1",headerArgs_range,widthArgs_range,colAlignArgs_range,colSortArgs_range,colTypeArgs_range);
commonGridObj_range.setResponseUrl("UserAuthorityGridSource.aspx");
commonGridObj_range.setRequest("UserAuthorityGridSource.aspx?handle=getranges&checkuser="+tempUserID+"&uid="+commonGridObj_range.newGuid());
commonGridObj_range.setSourceType("json");
commonGridObj_range.setSkin("xp");
commonGridObj_range.setImageUrl("../images/");
var attachHeaderArgs = new Array("","全部","分公司","部门","个人","无","全部","分公司","部门","个人","无");
commonGridObj_range.isAttchHeader = true;
commonGridObj_range.setAttachHeader(attachHeaderArgs);
commonGridObj_range.initGrid();
commonGridObj_range.loadafter = true;
commonGridObj_range.after = function(){
finishLoading();
};
commonGridObj_range.bind();
commonGridObj_range.getGridObj().attachEvent("onCheckbox", function(rId,cInd,state){
if(state){
var checkUser = $("h_checkuser").value.trim();
var url = "";
var rangeType = 0;
var rangeValue = 5;
if(cInd > 0 && cInd <= 5){
rangeType = 1;
switch(cInd){
case 1:
rangeValue = 0;
break;
case 2:
rangeValue = 1;
break;
case 3:
rangeValue = 2;
break;
case 4:
rangeValue = 3;
break;
case 5:
rangeValue = 4;
break;
}
url = "UserAuthorityGridSource.aspx?handle=saverange&rtype="+rangeType+"&rval="+rangeValue+"&authgid="+rId+"&checkuser="+checkUser+"&uid="+commonGridObj_range.newGuid();
}else if(cInd > 5 && cInd <= 10){
rangeType = 2;
switch(cInd){
case 6:
rangeValue = 0;
break;
case 7:
rangeValue = 1;
break;
case 8:
rangeValue = 2;
break;
case 9:
rangeValue = 3;
break;
case 10:
rangeValue = 4;
break;
}
url = "UserAuthorityGridSource.aspx?handle=saverange&rtype="+rangeType+"&rval="+rangeValue+"&authgid="+rId+"&checkuser="+checkUser+"&uid="+commonGridObj_range.newGuid();
}
var loader = dhtmlxAjax.getSync(url);
var jsonVal = loader.xmlDoc.responseText;
var jsonObj = eval('(' + jsonVal + ')');
if(jsonObj != null){
if(jsonObj.authority[0].state == 1){
var rowIndex = commonGridObj_range.getGridObj().getRowIndex(jsonObj.authority[0].id);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,1).setValue(jsonObj.authority[0].vall);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,2).setValue(jsonObj.authority[0].vcomp);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,3).setValue(jsonObj.authority[0].vdept);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,4).setValue(jsonObj.authority[0].vself);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,5).setValue(jsonObj.authority[0].vnull);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,6).setValue(jsonObj.authority[0].oall);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,7).setValue(jsonObj.authority[0].ocomp);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,8).setValue(jsonObj.authority[0].odept);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,9).setValue(jsonObj.authority[0].oself);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,10).setValue(jsonObj.authority[0].onull);
}
}else{
alert("设置失败");
}
}else{
var rowIndex = commonGridObj_range.getGridObj().getRowIndex(rId);
commonGridObj_range.getGridObj().cellByIndex(rowIndex,cInd).setValue(1);
}
});
}
function reloadEvent(){
commonGridObj_range.reload();
commonGridObj_range.getGridObj().attachEvent("onCheckbox", function(rId,cInd,state){
if(state){
var checkUser = $("h_checkuser").value.trim();
var url = "";
var rangeType = 0;
var rangeValue = 5;
if(cInd > 0 && cInd <= 5){
rangeType = 1;
switch(cInd){
case 1:
rangeValue = 0;
break;
case 2:
rangeValue = 1;
break;
case 3:
rangeValue = 2;
break;
case 4:
rangeValue = 3;
break;
case 5:
rangeValue = 4;
break;
}
url = "UserAuthorityGridSource.aspx?handle=saverange&rtype="+rangeType+"&rval="+rangeValue+"&authgid="+rId+"&checkuser="+checkUser+"&uid="+commonGridObj_range.newGuid();
}else if(cInd > 5 && cInd <= 10){
rangeType = 2;
switch(cInd){
case 6:
rangeValue = 0;
break;
case 7:
rangeValue = 1;
break;
case 8:
rangeValue = 2;
break;
case 9:
rangeValue = 3;
break;
case 10:
rangeValue = 4;
break;
}
url = "UserAuthorityGridSource.aspx?handle=saverange&rtype="+rangeType+"&rval="+rangeValue+"&authgid="+rId+"&checkuser="+checkUser+"&uid="+commonGridObj_range.newGuid();
}
var loader = dhtmlxAjax.getSync(url);
var cacheVal = loader.xmlDoc.responseText;
if(cacheVal == 1){
reloadEvent();
}else{
alert("设置失败");
}
}
});
}
function newGuid(){
var guid = "";
for (var i = 1; i <= 32; i++){
var n = Math.floor(Math.random()*16.0).toString(16);
guid += n;
if((i==8)||(i==12)||(i==16)||(i==20))
guid += "-";
}
return guid.toUpperCase();
}
function initLoading(){
$("progressBar").style.display = "";
}
function finishLoading(){
$("progressBar").style.display = "none";
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function validateType(strObj){
var type = 0;
var result = strObj.substring(0,strObj.indexOf("#"));
var typeName = strObj.substring(strObj.indexOf("#")+1,strObj.length);
switch(typeName){
case "user":
type = 1;
break;
case "comp":
type = 2;
break;
case "dept":
type = 3;
break;
}
return type;
}
function getID(strObj){
var uid = strObj.substring(0,strObj.indexOf("#"));
return uid;
}
function searchUser(txtObjName){
var searchVal = $(txtObjName).value;
var searchType = $("sel_type").value;
var searchUserObj = null;
var searchDeptObj = null;
if(searchType == 1){
var url = "../Modules/ModuleGridSource.aspx?handle=checkuser&searchuser="+escape(searchVal)+"&uid="+newGuid();
var loader = dhtmlxAjax.getSync(url);
var postStatus = loader.xmlDoc.responseText;
if(postStatus != ""){
searchUserObj = JSON.parse(postStatus,function(key,value){
return value;
});
}
if(user_tree != null){
for(var i=0;i<searchUserObj.users.length;i++){
user_tree.selectItem(searchUserObj.users[i].gid+"#user");
user_tree.setCheck(searchUserObj.users[i].gid+"#user",true);
}
}
}else if(searchType == 2){
var url = "../Modules/ModuleGridSource.aspx?handle=checkdept&searchdept="+escape(searchVal)+"&uid="+newGuid();
var loader = dhtmlxAjax.getSync(url);
var postStatus = loader.xmlDoc.responseText;
alert(postStatus);
if(postStatus != ""){
searchDeptObj = JSON.parse(postStatus,function(key,value){
return value;
});
}
if(user_tree != null){
for(var i=0;i<searchDeptObj.depts.length;i++){
user_tree.selectItem(searchDeptObj.depts[i].gid+"#dept");
}
}
}
}