370 lines
13 KiB
JavaScript
Executable File
370 lines
13 KiB
JavaScript
Executable File
$(function() {
|
||
recordShapeText();
|
||
$("#bar_save").off("click").on("click", function () {
|
||
if (isAutoSave == "1") {
|
||
var obj = Model.define;
|
||
//alert("保存");
|
||
var str = JSON.stringify(obj);
|
||
var imgPath = $("input[name='imgPath']").val();
|
||
$.base64.utf8encode = true;
|
||
var data = "jsonParams="+$.base64.btoa(str)+"&imgPath="+$.base64.btoa(imgPath);
|
||
$.ajax({
|
||
type: "POST",
|
||
url: "../coeTeamPalDesignerImageServlet.wf?&uuid="+chartId,
|
||
data: data,
|
||
success: function (msg, textStatus, jqXHR) {
|
||
if(msg=="true"){
|
||
alert("保存成功");
|
||
}else{
|
||
console.log(msg);
|
||
alert(msg);
|
||
}
|
||
},
|
||
error: function (jqXHR, textStatus, errorThrown) {
|
||
$.simpleAlert(errorThrown, 'err');
|
||
console.log(jqXHR)
|
||
console.log(textStatus)
|
||
console.log(errorThrown)
|
||
}
|
||
});
|
||
}
|
||
else if (isAutoSave == "0") {
|
||
//保存开始时间戳
|
||
//var saveStartTime = new Date().getTime();
|
||
|
||
if (isCorrelateBpms) {
|
||
// if (type == "bpmn" && !isMarked && ($("#bar_rmark").length > 0 && $("#bar_rmark").is(":visible") || $("#bar_cancel_aws_correlate").length > 0 && $("#bar_cancel_aws_correlate").is(":visible"))) {
|
||
var op = "edit|"+processDefVersionId ;
|
||
saveDesigner(null, true, op, true);
|
||
} else {
|
||
if (methodId == "process.bpmn2" && isPalManage) {
|
||
BPMNBiz.validateBPMN(false, function(){save()});
|
||
} else {
|
||
save();
|
||
}
|
||
function save() {
|
||
$.simpleAlert("正在保存", "loading");
|
||
var params = {
|
||
sid: CLB.sid,
|
||
cmd: "com.actionsoft.apps.coe.pal_pl_repository_process_lock_state_check",
|
||
uuid: ruuid
|
||
};
|
||
|
||
$.ajax({
|
||
type: "POST",
|
||
url: "./jd",
|
||
data: params,
|
||
success: function (msg, textStatus, jqXHR) {
|
||
if (msg.result == 'ok') {
|
||
var canSave = msg.data.canSave;
|
||
var lockUser = msg.data.lockUser;
|
||
if (!canSave) {
|
||
$.simpleAlert("该流程文件已被" + lockUser + "锁定", 'info', 2000, {callback:function() {
|
||
BPMNBiz.refreshDesigner();//刷新
|
||
}});
|
||
} else {
|
||
initSaveFun();
|
||
}
|
||
} else {
|
||
$.simpleAlert(msg.msg, 'error', 1500, {callback:function() {
|
||
BPMNBiz.refreshDesigner();//刷新
|
||
}});
|
||
}
|
||
},
|
||
error: function (jqXHR, textStatus, errorThrown) {
|
||
$.simpleAlert("close");
|
||
$.simpleAlert('保存失败', 'error', 1500);
|
||
}
|
||
});
|
||
}
|
||
function initSaveFun() {
|
||
Dock.showView('');
|
||
var obj = Model.define;
|
||
var tempMessageArr = {};
|
||
// 保存前校验,过滤可能出现的错误数据
|
||
for (var messageId in messageArrayForSave) {
|
||
var action = messageArrayForSave[messageId].action;
|
||
if (action == 'remove' && obj.elements[messageId] != undefined) continue;
|
||
if ((action == 'create' || action == 'update') && messageArrayForSave[messageId].name == shapeTextRecord[messageId]) continue;
|
||
tempMessageArr[messageId] = messageArrayForSave[messageId];
|
||
}
|
||
var messageArray = JSON.stringify(tempMessageArr);
|
||
var elements = obj.elements
|
||
for(let i in elements) {
|
||
for(let a = 0; a < elements[i].dataAttributes.length; a ++ ) {
|
||
if(elements[i].dataAttributes[a].attributesJsonArray !== undefined) {
|
||
for(let b = 0; b < elements[i].dataAttributes[a].attributesJsonArray.length; b ++) {
|
||
if(elements[i].dataAttributes[a].attributesJsonArray[b].isRequired && elements[i].dataAttributes[a].attributesJsonArray[b].value == '') {
|
||
$.simpleAlert("close");
|
||
$.simpleAlert("必填项不能为空", 'error');
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
$.ajax({
|
||
type: "POST",
|
||
url: "./jd",
|
||
data: {
|
||
sid: CLB.sid,
|
||
cmd: "com.actionsoft.apps.coe.pal_repository_process_define_save",
|
||
uuid: ruuid,
|
||
define: awsui.encode(obj),
|
||
teamId: $("#teamId").val(),
|
||
BPMInstanceName: BPMInstanceName,
|
||
messages: messageArray
|
||
},
|
||
success: function (msg, textStatus, jqXHR) {
|
||
if(msg.result == "ok") {
|
||
$.simpleAlert("close");
|
||
messageArrayForSave = {};
|
||
$("#saving_tip").css("color", "rgb(26, 164, 125)");
|
||
$("#saving_tip").text("保存成功");
|
||
recordShapeText();// 记录最新的节点及其文本text
|
||
//更多属性的处理,当节点处理完成后再处理更多属性
|
||
if (saveAttributesJson.length > 0 || removeAttributeJson.length > 0){
|
||
$.ajax({
|
||
type : "POST",
|
||
url : "./jd",
|
||
data : {
|
||
sid : encodeURI(CLB.sid),
|
||
cmd : "com.actionsoft.apps.coe.pal_pl_repository_more_attribute_save",
|
||
wsId : $("#wsId").val(),
|
||
uuid : ruuid,
|
||
attributesJson : JSON.stringify(saveAttributesJson),
|
||
removeAttributeJson : JSON.stringify(removeAttributeJson)
|
||
},
|
||
success:function(r) {
|
||
saveAttributesJson = [];
|
||
removeAttributeJson = [];
|
||
},
|
||
error:function(r) {
|
||
}
|
||
});
|
||
}
|
||
$.simpleAlert("保存成功", "ok");
|
||
//保存结束时间戳
|
||
//var saveEndTime = new Date().getTime();
|
||
//console.log("流程保存时间:", (saveEndTime - saveStartTime) + "毫秒");
|
||
} else {
|
||
$.simpleAlert("close");
|
||
$.simpleAlert(msg.data.desc, 'error', 2000);
|
||
}
|
||
},
|
||
error: function (jqXHR, textStatus, errorThrown) {
|
||
$.simpleAlert("close");
|
||
$.simpleAlert('保存失败', 'error', 1500);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
//取消异步发送
|
||
});
|
||
if (isAutoSave == "0") {
|
||
window.onbeforeunload = function(){
|
||
if ($("#saving_tip").text() != "已保存成功" && $("#saving_tip").text() != "保存成功" && $("#saving_tip").text() != "您的文件已经成功保存" && $("#saving_tip").text() != "") {
|
||
return "页面中有未保存的内容,请先保存";
|
||
} else {
|
||
//关闭页面时,释放编辑权
|
||
awsui.ajax.request({
|
||
type: "POST",
|
||
url: "./jd",
|
||
async: false,
|
||
data: {
|
||
sid: CLB.sid,
|
||
cmd: "com.actionsoft.apps.coe.pal_repository_process_define_edit_releaselock",
|
||
uuid: ruuid
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
//在弹出“是否离开”的提示框后,选择离开,则触发onunload事件
|
||
window.onunload = function(){
|
||
//关闭页面时,释放编辑权
|
||
console.log("释放编辑权");
|
||
awsui.ajax.request({
|
||
type: "POST",
|
||
url: "./jd",
|
||
async: false,
|
||
data: {
|
||
sid: CLB.sid,
|
||
cmd: "com.actionsoft.apps.coe.pal_repository_process_define_edit_releaselock",
|
||
uuid: ruuid
|
||
}
|
||
});
|
||
}
|
||
// saveTimer();
|
||
intervalRefresh();
|
||
}
|
||
|
||
// 编号刷点击事件
|
||
$('#bar_sort').off("click").on("click",function (){
|
||
if ($("#saving_tip").text() != "已保存成功" && $("#saving_tip").text() != "保存成功" && $("#saving_tip").text() != "您的文件已经成功保存") {
|
||
$.simpleAlert('页面未保存,请先保存', 'error', 1500);
|
||
return;
|
||
} else {
|
||
// $.simpleAlert("正在编号", "loading");
|
||
// $.ajax({
|
||
// type: "POST",
|
||
// url: "./jd",
|
||
// data: {
|
||
// sid: CLB.sid,
|
||
// cmd: "com.actionsoft.apps.coe.pal_repository_process_define_save",
|
||
// uuid: ruuid,
|
||
// },
|
||
// success: function (msg, textStatus, jqXHR) {
|
||
// $.simpleAlert("close");
|
||
// console.log(msg)
|
||
// },
|
||
// error: function (jqXHR, textStatus, errorThrown) {
|
||
// $.simpleAlert("close");
|
||
// $.simpleAlert('编号失败', 'error', 1500);
|
||
// }
|
||
// })
|
||
let numObj = {
|
||
brushId: 'number_brush',
|
||
orderList: [
|
||
{ shapeId: 'obj_c9e1cda208700001132717c019b9a350',order: 1},
|
||
{ shapeId: 'obj_c9e1cda2b8a000013b42e5f045db1f01',order: 2},
|
||
{ shapeId: 'obj_c9e1cda4ac10000164dd6bb015406b40',order: 3},
|
||
{ shapeId: 'obj_c9e1cda3109000015741104116a918a8',order: 4},
|
||
{ shapeId: 'obj_c9e1cdab200000014a2eade016e8170d',order: 5},
|
||
{ shapeId: 'obj_c9e1cdb266f0000159a7c8afa7701a68',order: 6},
|
||
]
|
||
}
|
||
let obj = Model.define
|
||
console.log(obj)
|
||
let elements = obj.elements
|
||
let orderList = numObj.orderList
|
||
for (let j = 0; j < orderList.length; j++) {
|
||
for(let i in elements) {
|
||
if (orderList[j].shapeId == i) {
|
||
for(let a = 0; a < elements[i].dataAttributes.length; a ++ ) {
|
||
if(elements[i].dataAttributes[a].attributesJsonArray !== undefined) {
|
||
for(let b = 0; b < elements[i].dataAttributes[a].attributesJsonArray.length; b ++) {
|
||
if(elements[i].dataAttributes[a].attributesJsonArray[b].id == numObj.brushId) {
|
||
elements[i].dataAttributes[a].attributesJsonArray[b].value = orderList[j].order
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// for(let i in elements) {
|
||
// for(let a = 0; a < elements[i].dataAttributes.length; a ++ ) {
|
||
// if(elements[i].dataAttributes[a].attributesJsonArray !== undefined) {
|
||
// for(let b = 0; b < elements[i].dataAttributes[a].attributesJsonArray.length; b ++) {
|
||
// if(elements[i].dataAttributes[a].attributesJsonArray[b].id == 'number_brush') {
|
||
// elements[i].dataAttributes[a].attributesJsonArray[b].value = 24
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
$("#saving_tip").css("color", "rgb(255, 0, 0)");
|
||
$("#saving_tip").text("文件已修改,未保存");
|
||
}
|
||
})
|
||
})
|
||
|
||
|
||
/**定时保存**/
|
||
function saveTimer() {
|
||
// 每隔5分钟时间进行保存
|
||
setInterval(function(){
|
||
var count = 5;
|
||
var msg = "秒之后自动进行保存";
|
||
var alertmsg = function(count, msg) {
|
||
$.simpleAlert(count + msg, "info", 1000, {callback:function(){
|
||
count--;
|
||
if(count < 1) {
|
||
$("#bar_save").click();
|
||
} else {
|
||
alertmsg(count, msg);
|
||
}
|
||
}})
|
||
}
|
||
alertmsg(count, msg);
|
||
// $.simpleAlert("5秒之后自动进行保存", "info", 5000, {callback:function(){$("#bar_save").click();}});
|
||
}, 300000);
|
||
}
|
||
|
||
/**定时刷新,查询流程是否被其他人锁定**/
|
||
function intervalRefresh() {
|
||
//每隔5秒发送请求 检查当前用户是否发生变化
|
||
intervalInd = setInterval(function() {
|
||
awsui.ajax.request({
|
||
type: "POST",
|
||
url: "./jd",
|
||
data: {
|
||
sid: CLB.sid,
|
||
cmd: "com.actionsoft.apps.coe.pal_repository_process_define_get_lock_info",
|
||
uuid: ruuid
|
||
},
|
||
cache : false,
|
||
alert : false,
|
||
ok: function(msg){
|
||
if (msg.data.isLocked) {
|
||
var m = '当前流程被 ' + msg.data.currentUserName + ' 强行获取编辑权或锁定'
|
||
$.simpleAlert(m,"info",4000,{mode:true,callback:function() {
|
||
if ($("#saving_tip").text() != "已保存成功" && $("#saving_tip").text() != "保存成功" && $("#saving_tip").text() != "您的文件已经成功保存" && $("#saving_tip").text() != "") {
|
||
$("#saving_tip").text('');// 防止reload时出现浏览器自带提示
|
||
}
|
||
window.location.reload();
|
||
}});
|
||
}
|
||
}
|
||
});
|
||
}, 10000);
|
||
}
|
||
|
||
var CommonLock = {
|
||
lockOrLuckFun: function (optype) {//锁定 解锁流程
|
||
if (isAutoSave == "0") {
|
||
if ($("#saving_tip").text() != "已保存成功" && $("#saving_tip").text() != "保存成功" && $("#saving_tip").text() != "您的文件已经成功保存" && $("#saving_tip").text() != "") {
|
||
$.simpleAlert('页面中有未保存的内容,请先保存');
|
||
return;
|
||
}
|
||
}
|
||
$.post("./jd", {
|
||
cmd: "com.actionsoft.apps.coe.pal_pl_repository_lock_or_unlock_process",
|
||
sid: sid,
|
||
uuid: ruuid,
|
||
optype: optype
|
||
}, function t(msg) {
|
||
if (msg.result == 'ok') {
|
||
if (optype == 'unlockpro') {
|
||
$.simpleAlert("文件已解锁", 'ok', 500, {callback: CommonLock.refreshDesigner});
|
||
} else {
|
||
$.simpleAlert("文件已锁定", 'ok', 500, {callback: CommonLock.refreshDesigner});
|
||
}
|
||
} else {
|
||
CommonLock.refreshDesigner();
|
||
}
|
||
}, "json");
|
||
},
|
||
refreshDesigner: function () {
|
||
//刷新当前页面
|
||
if (top.location != self.location) {
|
||
location.href = location.href;
|
||
} else {
|
||
window.location.reload();
|
||
}
|
||
}
|
||
}
|
||
|
||
// 记录所有节点及节点名称,保存时对比
|
||
var shapeTextRecord = {};
|
||
function recordShapeText() {
|
||
shapeTextRecord = {};// 初始化
|
||
var obj = Model.define;
|
||
var shapes = obj.elements;
|
||
for(var shape in shapes) {
|
||
shapeTextRecord[shape] = shapes[shape].text;
|
||
}
|
||
} |