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.

506 lines
22 KiB
JavaScript

12 months ago
var commonGridObj_step;
var editCount;
function $(id){
return document.getElementById(id);
}
function createStepGrid(){
var headerArgs_step = new Array("<input type=\"checkbox\" id=\"ck_all\" onclick=\"checkAll(commonGridObj_step)\" />","步骤编号","系统名称","显示名称","过滤条件","审核人","是否必须审核","是否最终审核","是否并行","是否区分部门","所属部门","创建人","创建时间","备注");
//width
var widthArgs_step = new Array("40","80","150","150","150","100","100","100","100","80","80","150","150","150");
//column align
var colAlignArgs_step = new Array("center","center","center","center","center","center","center","center","center","center","center","center","center","center");
//column sort
var colSortArgs_step = new Array("na","str","str","str","str","str","str","str","str","str","str","str","str","str");
//column type
var colTypeArgs_step = new Array("ch","ro","ed","ed","ro","ro","ch","ch","ch","ch","ro","ro","ro","txt");
commonGridObj_step = new TGridCommon("mygrid_container_steps","form1",headerArgs_step,widthArgs_step,colAlignArgs_step,colSortArgs_step,colTypeArgs_step);
commonGridObj_step.setResponseUrl("WorkFlowGridSource.aspx");
var workflowID = $("h_workflowid").value.trim();
commonGridObj_step.setRequest("WorkFlowGridSource.aspx?handle=steplist&flowid="+workflowID);
commonGridObj_step.setSourceType("json");
commonGridObj_step.setSkin("xp");
commonGridObj_step.setImageUrl("../images/");
commonGridObj_step.initGrid();
commonGridObj_step.bind();
commonGridObj_step.getGridObj().enableEditEvents(true,false,true);
commonGridObj_step.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(stage == 0){
if(cInd == 6 || cInd == 7 || cInd == 8){
return false;
}else{
return true;
}
}
if(stage == 2){
return true;
}
});
commonGridObj_step.getGridObj().attachEvent("onRowSelect", function(id,ind){
if(ind == 5){
var openSet = "height=360, width=460, toolbar=no, menubar=no,scrollbars=no, resizable=no,location=no, status=no,Top= " +(screen.height-490)/2 + ",Left= "+(screen.width-1000)/2
var openType = "_blank";
if (id==""){
alert("请保存步骤信息后,再设置");
return;
}
var openUrl = "UserTree.aspx?stepid="+id;
window.open (openUrl,openType,openSet);
}
});
}
function checkAll(gridObj){
if(gridObj != null){
var checkAllVal = $("ck_all").checked;
for(var i=0;i<gridObj.getGridObj().getRowsNum();i++){
if(checkAllVal){
gridObj.getGridObj().cellByIndex(i,0).setValue(1);
}else{
gridObj.getGridObj().cellByIndex(i,0).setValue(0);
}
}
}
}
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g,""); }
function addStep(){
if(commonGridObj_step != null){
var newStepGuid = commonGridObj_step.newGuid();
var rowCount = commonGridObj_step.getGridObj().getRowsNum();
var newStepNo = getLastStepNo();
var userID = $("h_userid").value.trim();
for(var i=0;i<commonGridObj_step.getGridObj().getRowsNum();i++){
commonGridObj_step.getGridObj().cellByIndex(i,7).setValue(0);
}
commonGridObj_step.getGridObj().addRow(newStepGuid,["0",newStepNo,"","","设置条件","设置",1,1,0,0,"","","",""],rowCount);
editCount++;
}
}
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 deleteStep(){
var iCount = 0;
var recvArg = new Array();
for(var i=0;i<commonGridObj_step.getGridObj().getRowsNum();i++){
var checkState = commonGridObj_step.getGridObj().cellByIndex(i,0).getValue();
var rowID = commonGridObj_step.getGridObj().getRowId(i);
if(checkState == 1){
recvArg.push(rowID);
iCount++;
}
}
if(iCount > 0){
var delCount = 0;
if(recvArg.length > 0){
if(window.confirm("您确定要将所选工作流步骤删除")){
while(delCount < recvArg.length){
//删除工作流步骤信息分2种情况1:workflow_step;2:workflow_step,workflow_do
var urlVal = "WorkFlowGridSource.aspx?stepid="+recvArg[delCount]+"&handle=deleteStep";
var loader = dhtmlxAjax.getSync(urlVal);
var loadVal = loader.xmlDoc.responseText;
if(loadVal == 1 ){
//commonGridObj_step.getGridObj().deleteRow(recvArg[delCount]);
}
delCount++;
}
}
}
createStepGrid();
}
}//end deleteStep
function refreshList(){
if(window.confirm("您确定要刷新页面,有未保存的记录,如果确定刷新则放弃未保存的记录")){
createStepGrid();
}
}
//获取新的步骤编号信息
function getLastStepNo(){
var lastStepNo = 0;
if(commonGridObj_step != null){
for(var i=0;i<commonGridObj_step.getGridObj().getRowsNum();i++){
var tempStepNo = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,1).getValue());
if(tempStepNo > lastStepNo){
lastStepNo = tempStepNo;
}
}
}
return lastStepNo+1;
}
function saveStep(){
var saveStepObj = null;
if(commonGridObj_step != null){
for(var i=0;i<commonGridObj_step.getGridObj().getRowsNum();i++){
var rowID = commonGridObj_step.getGridObj().getRowId(i);
var stepNo = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,1).getValue());
var stepName = commonGridObj_step.getGridObj().cellByIndex(i,2).getValue();
var stepDescription = commonGridObj_step.getGridObj().cellByIndex(i,3).getValue();
var isMust = commonGridObj_step.getGridObj().cellByIndex(i,6).getValue();
var isLast = commonGridObj_step.getGridObj().cellByIndex(i,7).getValue();
var isParallel = commonGridObj_step.getGridObj().cellByIndex(i,8).getValue();
var isDepartment = commonGridObj_step.getGridObj().cellByIndex(i,9).getValue();
var remark = commonGridObj_step.getGridObj().cellByIndex(i,13).getValue();
if(stepName.trim() == ""){
alert("系统名称不能为空");
return;
}
if(stepName.trim().indexOf("'") >= 0){
alert("系统名称格式错误,不能识别单引号");
return;
}
if(stepDescription.trim() == ""){
alert("显示名称不能为空");
return;
}
if(stepDescription.trim().indexOf("'") >= 0){
alert("显示名称格式错误,不能识别单引号");
return;
}
if(saveStepObj != null){
if(saveStepObj.steps.length > 0){
var newCache = saveStepObj.steps;
newCache = {id:rowID,no:stepNo,name:stepName,desp:stepDescription,must:isMust,last:isLast,parallel:isParallel,dept:isDepartment,remark:remark};
saveStepObj.steps.push(newCache);
$("h_cache").value = JSON.stringify(saveStepObj);
}else{
var cacheBuffer = "";
var result = "";
cacheBuffer += "{";
cacheBuffer += "\"id\":\""+rowID+"\",";
cacheBuffer += "\"no\":\""+stepNo+"\",";
cacheBuffer += "\"name\":"+stepName+",";
cacheBuffer += "\"desp\":\""+stepDescription+"\",";
cacheBuffer += "\"must\":"+isMust+",";
cacheBuffer += "\"last\":"+isLast+",";
cacheBuffer += "\"parallel\":"+isParallel+",";
cacheBuffer += "\"dept\":"+isDepartment+",";
cacheBuffer += "\"remark\":\""+remark+"\"";
cacheBuffer += "}";
result += "{\"steps\":[";
result += cacheBuffer;
result += "]}";
saveStepObj = eval('(' + result + ')');
$("h_cache").value = JSON.stringify(saveStepObj);
}
}else{
var cacheBuffer = "";
var result = "";
cacheBuffer += "{";
cacheBuffer += "\"id\":\""+rowID+"\",";
cacheBuffer += "\"no\":\""+stepNo+"\",";
cacheBuffer += "\"name\":\""+stepName+"\",";
cacheBuffer += "\"desp\":\""+stepDescription+"\",";
cacheBuffer += "\"must\":"+isMust+",";
cacheBuffer += "\"last\":"+isLast+",";
cacheBuffer += "\"parallel\":"+isParallel+",";
cacheBuffer += "\"dept\":"+isDepartment+",";
cacheBuffer += "\"remark\":\""+remark+"\"";
cacheBuffer += "}";
result += "{\"steps\":[";
result += cacheBuffer;
result += "]}";
saveStepObj = eval('(' + result + ')');
$("h_cache").value = JSON.stringify(saveStepObj);
}
}
}
if($("h_cache").value.trim() != ""){
$("h_post").value = "1";
postEnterFee();
}
}
function upStep(){
var tempCount = 0;
var checkState = 0;
for(var i=0;i<commonGridObj_step.getGridObj().getRowsNum();i++){
var check = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,0).getValue());
if(check == 1){
checkState = i;
tempCount++;
}
}
if(tempCount > 1){
checkState = 0;
tempCount = 0;
alert("每次只能移动一条步骤");
return;
}
if(checkState == 0){
alert("已经是最第一步骤,不能移动");
return;
}
var oldObj = getCacheObj();
var oldCount = checkState - 1;
oldObj.steps[0].id = commonGridObj_step.getGridObj().getRowId(oldCount);
oldObj.steps[0].check = parseInt(commonGridObj_step.getGridObj().cellByIndex(oldCount,0).getValue());
oldObj.steps[0].no = parseInt(commonGridObj_step.getGridObj().cellByIndex(oldCount,1).getValue());
oldObj.steps[0].name = commonGridObj_step.getGridObj().cellByIndex(oldCount,2).getValue();
oldObj.steps[0].desp = commonGridObj_step.getGridObj().cellByIndex(oldCount,3).getValue();
oldObj.steps[0].must = commonGridObj_step.getGridObj().cellByIndex(oldCount,6).getValue();
oldObj.steps[0].last = commonGridObj_step.getGridObj().cellByIndex(oldCount,7).getValue();
oldObj.steps[0].parallel = commonGridObj_step.getGridObj().cellByIndex(oldCount,8).getValue();
oldObj.steps[0].dept = commonGridObj_step.getGridObj().cellByIndex(oldCount,9).getValue();
//alert(JSON.stringify(oldObj));
var currObj = getCacheObj();
var currCount = checkState;
currObj.steps[0].id = commonGridObj_step.getGridObj().getRowId(currCount);
currObj.steps[0].check = parseInt(commonGridObj_step.getGridObj().cellByIndex(currCount,0).getValue());
currObj.steps[0].no = parseInt(commonGridObj_step.getGridObj().cellByIndex(currCount,1).getValue());
currObj.steps[0].name = commonGridObj_step.getGridObj().cellByIndex(currCount,2).getValue();
currObj.steps[0].desp = commonGridObj_step.getGridObj().cellByIndex(currCount,3).getValue();
currObj.steps[0].must = commonGridObj_step.getGridObj().cellByIndex(currCount,6).getValue();
currObj.steps[0].last = commonGridObj_step.getGridObj().cellByIndex(currCount,7).getValue();
currObj.steps[0].parallel = commonGridObj_step.getGridObj().cellByIndex(currCount,8).getValue();
currObj.steps[0].dept = commonGridObj_step.getGridObj().cellByIndex(currCount,9).getValue();
//alert(JSON.stringify(currObj));
commonGridObj_step.getGridObj().setRowId(oldCount,currObj.steps[0].id);
// commonGridObj_step.getGridObj().cellByIndex(oldCount,1).setValue(currObj.steps[0].no);
commonGridObj_step.getGridObj().cellByIndex(oldCount,0).setValue(currObj.steps[0].check);
commonGridObj_step.getGridObj().cellByIndex(oldCount,2).setValue(currObj.steps[0].name);
commonGridObj_step.getGridObj().cellByIndex(oldCount,3).setValue(currObj.steps[0].desp);
commonGridObj_step.getGridObj().cellByIndex(oldCount,6).setValue(currObj.steps[0].must);
commonGridObj_step.getGridObj().cellByIndex(oldCount,7).setValue(currObj.steps[0].last);
commonGridObj_step.getGridObj().cellByIndex(oldCount,8).setValue(currObj.steps[0].parallel);
commonGridObj_step.getGridObj().cellByIndex(oldCount,9).setValue(currObj.steps[0].dept);
commonGridObj_step.getGridObj().setRowId(currCount,oldObj.steps[0].id);
// commonGridObj_step.getGridObj().cellByIndex(currCount,1).setValue(oldObj.steps[0].no);
commonGridObj_step.getGridObj().cellByIndex(currCount,0).setValue(oldObj.steps[0].check);
commonGridObj_step.getGridObj().cellByIndex(currCount,2).setValue(oldObj.steps[0].name);
commonGridObj_step.getGridObj().cellByIndex(currCount,3).setValue(oldObj.steps[0].desp);
commonGridObj_step.getGridObj().cellByIndex(currCount,6).setValue(oldObj.steps[0].must);
commonGridObj_step.getGridObj().cellByIndex(currCount,7).setValue(oldObj.steps[0].last);
commonGridObj_step.getGridObj().cellByIndex(currCount,8).setValue(oldObj.steps[0].parallel);
commonGridObj_step.getGridObj().cellByIndex(currCount,9).setValue(oldObj.steps[0].dept);
// alert(JSON.stringify(currObj));alert(JSON.stringify(oldObj));
}
function downStep(){
var tempCount = 0;
var checkState = 0;
for(var i=0;i<commonGridObj_step.getGridObj().getRowsNum();i++){
var check = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,0).getValue());
if(check == 1){
checkState = i;
tempCount++;
}
}
if(tempCount > 1){
checkState = 0;
tempCount = 0;
alert("每次只能移动一条步骤");
return;
}
if(checkState == (commonGridObj_step.getGridObj().getRowsNum() - 1)){
alert("已经是最后步骤,不能移动");
return;
}
var oldObj = getCacheObj();
var oldCount = checkState;
oldObj.steps[0].id = commonGridObj_step.getGridObj().getRowId(oldCount);
oldObj.steps[0].check = parseInt(commonGridObj_step.getGridObj().cellByIndex(oldCount,0).getValue());
oldObj.steps[0].no = parseInt(commonGridObj_step.getGridObj().cellByIndex(oldCount,1).getValue());
oldObj.steps[0].name = commonGridObj_step.getGridObj().cellByIndex(oldCount,2).getValue();
oldObj.steps[0].desp = commonGridObj_step.getGridObj().cellByIndex(oldCount,3).getValue();
oldObj.steps[0].must = commonGridObj_step.getGridObj().cellByIndex(oldCount,6).getValue();
oldObj.steps[0].last = commonGridObj_step.getGridObj().cellByIndex(oldCount,7).getValue();
oldObj.steps[0].parallel = commonGridObj_step.getGridObj().cellByIndex(oldCount,8).getValue();
oldObj.steps[0].dept = commonGridObj_step.getGridObj().cellByIndex(oldCount,9).getValue();
//alert(JSON.stringify(oldObj));
var currObj = getCacheObj();
var currCount = checkState + 1;
currObj.steps[0].id = commonGridObj_step.getGridObj().getRowId(currCount);
currObj.steps[0].check = parseInt(commonGridObj_step.getGridObj().cellByIndex(currCount,0).getValue());
currObj.steps[0].no = parseInt(commonGridObj_step.getGridObj().cellByIndex(currCount,1).getValue());
currObj.steps[0].name = commonGridObj_step.getGridObj().cellByIndex(currCount,2).getValue();
currObj.steps[0].desp = commonGridObj_step.getGridObj().cellByIndex(currCount,3).getValue();
currObj.steps[0].must = commonGridObj_step.getGridObj().cellByIndex(currCount,6).getValue();
currObj.steps[0].last = commonGridObj_step.getGridObj().cellByIndex(currCount,7).getValue();
currObj.steps[0].parallel = commonGridObj_step.getGridObj().cellByIndex(currCount,8).getValue();
currObj.steps[0].dept = commonGridObj_step.getGridObj().cellByIndex(currCount,9).getValue();
//alert(JSON.stringify(currObj));
commonGridObj_step.getGridObj().setRowId(oldCount,currObj.steps[0].id);
// commonGridObj_step.getGridObj().cellByIndex(oldCount,1).setValue(currObj.steps[0].no);
commonGridObj_step.getGridObj().cellByIndex(oldCount,0).setValue(currObj.steps[0].check);
commonGridObj_step.getGridObj().cellByIndex(oldCount,2).setValue(currObj.steps[0].name);
commonGridObj_step.getGridObj().cellByIndex(oldCount,3).setValue(currObj.steps[0].desp);
commonGridObj_step.getGridObj().cellByIndex(oldCount,6).setValue(currObj.steps[0].must);
commonGridObj_step.getGridObj().cellByIndex(oldCount,7).setValue(currObj.steps[0].last);
commonGridObj_step.getGridObj().cellByIndex(oldCount,8).setValue(currObj.steps[0].parallel);
commonGridObj_step.getGridObj().cellByIndex(oldCount,9).setValue(currObj.steps[0].dept);
commonGridObj_step.getGridObj().setRowId(currCount,oldObj.steps[0].id);
// commonGridObj_step.getGridObj().cellByIndex(currCount,1).setValue(oldObj.steps[0].no);
commonGridObj_step.getGridObj().cellByIndex(currCount,0).setValue(oldObj.steps[0].check);
commonGridObj_step.getGridObj().cellByIndex(currCount,2).setValue(oldObj.steps[0].name);
commonGridObj_step.getGridObj().cellByIndex(currCount,3).setValue(oldObj.steps[0].desp);
commonGridObj_step.getGridObj().cellByIndex(currCount,6).setValue(oldObj.steps[0].must);
commonGridObj_step.getGridObj().cellByIndex(currCount,7).setValue(oldObj.steps[0].last);
commonGridObj_step.getGridObj().cellByIndex(currCount,8).setValue(oldObj.steps[0].parallel);
commonGridObj_step.getGridObj().cellByIndex(currCount,9).setValue(oldObj.steps[0].dept);
// alert(JSON.stringify(currObj));alert(JSON.stringify(oldObj));
}
function getCacheObj(){
var tempObj = null;
var cacheBuffer = "";
var result = "";
cacheBuffer += "{";
cacheBuffer += "\"id\":\"\",";
cacheBuffer += "\"check\":0,";
cacheBuffer += "\"no\":\"\",";
cacheBuffer += "\"name\":\"\",";
cacheBuffer += "\"desp\":\"\",";
cacheBuffer += "\"must\":0,";
cacheBuffer += "\"last\":0,";
cacheBuffer += "\"parallel\":0,";
cacheBuffer += "\"dept\":0,";
cacheBuffer += "\"remark\":\"\"";
cacheBuffer += "}";
result += "{\"steps\":[";
result += cacheBuffer;
result += "]}";
tempObj = eval('(' + result + ')');
return tempObj;
}
function doParallel(){
var tempCount = 0;
var checkState = 0;
var paraObj = null;
var sameNo = 0;
var isExistLast = 0;
for(var i=0;i<commonGridObj_step.getGridObj().getRowsNum();i++){
var check = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,0).getValue());
var lastState = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,7).getValue());
if(check == 1){
if(tempCount == 0){
sameNo = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,1).getValue());
}
if(lastState == 1){
isExistLast++;
}
if(paraObj != null){
var newCache = paraObj.steps;
newCache = {id:commonGridObj_step.getGridObj().getRowId(i),check:commonGridObj_step.getGridObj().cellByIndex(i,0).getValue(),
no:parseInt(commonGridObj_step.getGridObj().cellByIndex(i,1).getValue()),name:commonGridObj_step.getGridObj().cellByIndex(i,2).getValue(),
desp:commonGridObj_step.getGridObj().cellByIndex(i,3).getValue(),must:commonGridObj_step.getGridObj().cellByIndex(i,6).getValue(),
last:commonGridObj_step.getGridObj().cellByIndex(i,7).getValue(),parallel:commonGridObj_step.getGridObj().cellByIndex(i,8).getValue(),
dept:commonGridObj_step.getGridObj().cellByIndex(i,9).getValue()};
paraObj.steps.push(newCache);
}else{
paraObj = getCacheObj();
paraObj.steps[0].id = commonGridObj_step.getGridObj().getRowId(i);
paraObj.steps[0].check = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,0).getValue());
paraObj.steps[0].no = parseInt(commonGridObj_step.getGridObj().cellByIndex(i,1).getValue());
paraObj.steps[0].name = commonGridObj_step.getGridObj().cellByIndex(i,2).getValue();
paraObj.steps[0].desp = commonGridObj_step.getGridObj().cellByIndex(i,3).getValue();
paraObj.steps[0].must = commonGridObj_step.getGridObj().cellByIndex(i,6).getValue();
paraObj.steps[0].last = commonGridObj_step.getGridObj().cellByIndex(i,7).getValue();
paraObj.steps[0].parallel = commonGridObj_step.getGridObj().cellByIndex(i,8).getValue();
paraObj.steps[0].dept = commonGridObj_step.getGridObj().cellByIndex(i,9).getValue();
}
tempCount++;
}
}
if(tempCount <= 1){
alert("选择错误,并行权限至少要选中2个步骤项");
return;
}
for(var j=0;j<paraObj.steps.length;j++){
paraObj.steps[j].no = sameNo;
for(var k=0;k<commonGridObj_step.getGridObj().getRowsNum();k++){
if(commonGridObj_step.getGridObj().getRowId(k) == paraObj.steps[j].id){
commonGridObj_step.getGridObj().cellByIndex(k,1).setValue(paraObj.steps[j].no);
if(isExistLast > 0){
commonGridObj_step.getGridObj().cellByIndex(k,7).setValue(1);
}
commonGridObj_step.getGridObj().cellByIndex(k,8).setValue(1);
break;
}
}
}
}
function postEnterFee(){
var myForm = document.getElementById("form1");
myForm.submit() ;
}