MWF.xApplication = MWF.xApplication || {}; MWF.xApplication.process = MWF.xApplication.process || {}; MWF.xApplication.process.ProcessDesigner = MWF.xApplication.process.ProcessDesigner || {}; MWF.APPPD = MWF.xApplication.process.ProcessDesigner; MWF.require("MWF.widget.Common", null, false); MWF.xDesktop.requireApp("process.ProcessDesigner", "lp."+MWF.language, null, false); MWF.xDesktop.requireApp("process.ProcessDesigner", "Property", null, false); MWF.xDesktop.requireApp("process.ProcessDesigner", "Activity", null, false); MWF.xDesktop.requireApp("process.ProcessDesigner", "Route", null, false); MWF.xApplication.process.ProcessDesigner.Process = new Class({ Extends: MWF.widget.Common, Implements: [Options, Events], options: { "style": "default", "isView": false }, initialize: function(paper, process, designer, options){ this.setOptions(options); this.path = "../x_component_process_ProcessDesigner/$Process/"; this.cssPath = "../x_component_process_ProcessDesigner/$Process/"+this.options.style+"/css.wcss"; this._loadCss(); this.designer = designer; this.process = process; this.process.projectionData = (process.project) ? JSON.parse(process.project) : null; this.paper = paper; if(this.designer.application) this.process.applicationName = this.designer.application.name; if(this.designer.application) this.process.application = this.designer.application.id; // if(this.designer.category) this.process.processCategory = this.designer.category.data.id; // this.process.starterMode = "assign"; this.activityTemplates = null; this.routeTemplates = null; //activity list this.begin = null; this.ends = {}; this.cancels={}; this.manuals = {}; this.conditions = {}; this.choices = {}; this.splits = {}; this.parallels = {}; this.merges = {}; this.embeds = {}; this.publishs = {}; this.delays = {}; this.invokes = {}; this.services = {}; this.agents = {}; this.messages = {}; this.activitys=[]; this.selectedActivitys = []; this.selectedActivityDatas = []; this.scripts = {}; this.routes = {}; this.routeDatas = {}; this.isGrid = true; //activity loaded this.loadedBegin = false; this.loadedEnds = false; this.loadedCancels = false; this.loadedConditions = false; this.loadedChoices = false; this.loadedManuals = false; this.loadedSplits = false; this.loadedParallels = false; this.loadedMerges = false; this.loadedEmbeds = false; this.loadedPublishs = false; this.loadedDelays = false; this.loadedInvokes = false; this.loadedServices = false; this.loadedAgents = false; this.loadedMessages = false; this.isCreateRoute = false; this.currentCreateRoute = null; this.isCopyRoute = false; this.currentCopyRoute = null; this.isBrokenLine = false; this.isChangeRouteTo = false; this.isChangeRouteFrom = false; this.currentChangeRoute = null; this.unSelectedEvent = true; this.panel = null; this.property = null; // this.isFocus = false; this.isNewProcess = (this.process.id) ? false : true; }, load : function(){ // if (this.isNewProcess){ // this.process.createTime = new Date().format('db'); // this.process.updateTime = new Date().format('db'); // } this.createPropertyPanel(); this.loadProcessActivitys(function(){ // this.loadProcessActivitys(); this.loadProcessRoutes(); this.loadActivityRoutes(); this.loadProcessScripts(); this.checkLoadRoutes(); if (this.isNewProcess) this.checkUUID(); this.fireEvent("postLoad"); }.bind(this)); this.setEvent(); this.setMenu(); this.showProperty(); this.showEditionInfor(); }, checkLoadRoutes: function(){ Object.each(this.routes, function(route){ if (!route.loaded) route.load(); }); }, checkUUID: function(){ //新流程, 此处处理所有元素的id this.process.isNewProcess = true; var idCount = (this.process.begin) ? 2 : 1; idCount += (this.process.endList) ? this.process.endList.length : 0; idCount += (this.process.manualList) ? this.process.manualList.length : 0; idCount += (this.process.conditionList) ? this.process.conditionList.length : 0; idCount += (this.process.choiceList) ? this.process.choiceList.length : 0; idCount += (this.process.parallelList) ? this.process.parallelList.length : 0; idCount += (this.process.splitList) ? this.process.splitList.length : 0; idCount += (this.process.mergeList) ? this.process.mergeList.length : 0; idCount += (this.process.embedList) ? this.process.embedList.length : 0; idCount += (this.process.publishList) ? this.process.publishList.length : 0; idCount += (this.process.invokeList) ? this.process.invokeList.length : 0; idCount += (this.process.cancelList) ? this.process.cancelList.length : 0; idCount += (this.process.delayList) ? this.process.delayList.length : 0; idCount += (this.process.messageList) ? this.process.messageList.length : 0; idCount += (this.process.serviceList) ? this.process.serviceList.length : 0; idCount += (this.process.routeList) ? this.process.routeList.length : 0; this.designer.actions.getId(idCount, function(ids){ this.checkUUIDs = ids.data; //流程ID this.process.id = this.checkUUIDs.pop().id; this.process.createTime = new Date().format('db'); this.process.updateTime = new Date().format('db'); for (var i=0; i8){ this.paper.canvas.removeEvent("mousemove", this.checkSelectMultiMouseMoveBind); if (!this.isCreateRoute && !this.isCopyRoute && !this.isBrokenLine && !this.isChangeRouteTo && !this.isChangeRouteFrom){ var x = Math.min(p.x, pMove.x); var y = Math.min(p.y, pMove.y); var width = Math.abs(pMove.x-p.x); var height = Math.abs(pMove.y-p.y); var selectBox = this.paper.rect(x, y, width, height, 0).attr({ "fill": "#a8caec", "stroke": "#3399ff", "stroke-width": "0.8", "fill-opacity": 0.5 }); this.beginSelectMultiMouseMoveBind = function(e){ this.beginSelectMultiMouseMove(e, p, selectBox); }.bind(this); this.endSelectMultiMouseMoveBind = function(e){ return this.endSelectMulti(e, p, selectBox); }.bind(this); this.unSelectedAll(); this.paper.canvas.addEvent("mousemove", this.beginSelectMultiMouseMoveBind); this.paper.canvas.addEvent("mouseup", this.endSelectMultiMouseMoveBind); } } }, checkSelectMultiStop: function(){ this.paper.canvas.removeEvent("mousemove", this.checkSelectMultiMouseMoveBind); }, beginSelectMultiMouseMove: function(e, p, rect){ var pMove = {"x": e.event.offsetX, "y": e.event.offsetY}; var x = Math.min(p.x, pMove.x); var y = Math.min(p.y, pMove.y); var width = Math.abs(pMove.x-p.x); var height = Math.abs(pMove.y-p.y); // rect.attr("path", MWFRaphael.getRectPath(x, y, width, height, 0)); rect.attr({ //"path", MWFRaphael.getRectPath(x, y, width, height, 0) "x": x, "y": y, "width": width, "height": height }); this.checkSelectActivity(e, p, rect); }, endSelectMulti: function(e, p, rect){ rect.remove(); if (this.selectedActivityDatas.length){ this.panel.data = this.selectedActivityDatas; } this.paper.canvas.removeEvent("mousemove", this.beginSelectMultiMouseMoveBind); this.paper.canvas.removeEvent("mouseup", this.endSelectMultiMouseMoveBind); if (this.selectedActivitys.length){ this.unSelectedEvent = false; window.setTimeout(function(){this.unSelectedEvent = true;}.bind(this), 300); } return false; }, checkSelectActivity: function(e, p, rect){ var pMove = {"x": e.event.offsetX, "y": e.event.offsetY}; var x = Math.min(p.x, pMove.x); var y = Math.min(p.y, pMove.y); var toX = Math.max(p.x, pMove.x); var toY = Math.max(p.y, pMove.y); this.activitys.each(function(activity){ var ax = activity.center.x; var ay = activity.center.y; if (ax>x && axy && ay"+this.process.editionNumber+" "+this.designer.lp.editionUpdate+": "+o2.name.cn(this.process.lastUpdatePerson)+" ("+this.process.updateTime+")"; this.designer.processEditionInforNode.set("html", text); this.designer.processEditionInforNode.addEvent("click", function(e){ this.listEdition(e); }.bind(this)); } } }, enableCurrentEdition: function(e){ var _self = this; this.designer.confirm("infor", e, this.designer.lp.edition_list.enabledProcessTitle, {"html": this.designer.lp.edition_list.enabledProcessInfor}, 600, 120, function(){ _self.save(function(){ var actions = o2.Actions.load("x_processplatform_assemble_designer").ProcessAction; actions.enableProcess(this.process.id, function(json){ actions.get(this.process.id, function(json){ this.reload(json.data); }.bind(this)) }.bind(this)); }.bind(_self)); this.close(); },function(){this.close();}) }, unSelected: function(e){ //var els = this.paper.getElementsByPoint(e.event.layerX, e.event.layerY); var els = this.paper.getElementsByPoint(e.event.offsetX, e.event.offsetY); if (!els.length){ this.unSelectedAll(); this.showProperty(); // if (this.currentSelected){ // this.currentSelected.unSelected(); // } } }, setMenu: function(){ MWF.require("MWF.widget.Menu", function(){ this.menu = new MWF.widget.Menu(this.paper.canvas, { "onQueryShow": function(e){ //var obj = this.getPointElement(e.event.layerX, e.event.layerY); var obj = this.getPointElement(e.event.offsetX, e.event.offsetY); switch (obj.type){ case "activity": this.addActivityMenu(obj.bind); break; case "route": this.addRouteMenu(obj.bind); break; default: this.addProcessMenu(); }; }.bind(this) }); this.menu.load(); }.bind(this)); }, addPublicMenu: function(bind, newRoute){ var newRouteFun = newRoute; if (!newRouteFun) newRouteFun = this.createRoute.bind(this); this.menu.addMenuItem(MWF.APPPD.LP.menu.newRoute, "click", newRouteFun, this.designer.path+""+this.options.style+"/toolbarIcon/"+"newRouter.gif"); if (!this.newActivityMenu){ MWF.require("MWF.widget.Menu", null, false); this.newActivityMenu = new MWF.widget.Menu(this.paper.canvas, {"event": null}); this.newActivityMenu.load(); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.manual, "click", this.createManualActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"manual.gif"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.condition, "click", this.createConditionActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"condition.gif"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.auto, "click", this.createAutoActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"auto.gif"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.split, "click", this.createSplitActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"split.gif"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.merge, "click", this.createMergeActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"merge.gif"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.embed, "click", this.createEmbedActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"embed.gif"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.publish, "click", this.createPublishActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"publish.png"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.invoke, "click", this.createInvokesActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"invoke.gif"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.begin, "click", this.createBeginActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"begin.gif"); this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.end, "click", this.createEndActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"end.gif"); } this.menu.addMenuMenu(MWF.APPPD.LP.menu.newActivity, this.designer.path+""+this.options.style+"/toolbarIcon/"+"newActivity.gif", this.newActivityMenu); }, addActivityMenu: function(bind){ this.menu.clearItems(); var newRoute = function(){bind.quickCreateRoute();}; this.addPublicMenu(bind, newRoute); this.menu.addMenuLine(); this.menu.addMenuItem(MWF.APPPD.LP.menu.copyActivity, "click", function(e){this.copyActivity(bind);}.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"copy.png"); this.menu.addMenuLine(); this.menu.addMenuItem(MWF.APPPD.LP.menu.deleteActivity, "click", function(e){this.deleteActivity(e, bind);}.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"deleteActivity.gif"); }, addRouteMenu: function(bind){ this.menu.clearItems(); this.addPublicMenu(); this.menu.addMenuLine(); this.menu.addMenuItem(MWF.APPPD.LP.menu.deleteRoute, "click", function(e){this.deleteRoute(e, bind);}.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"deleteRouter.gif"); }, addProcessMenu: function(){ var process = this; this.menu.clearItems(); this.addPublicMenu(); this.menu.addMenuLine(); this.menu.addMenuItem(MWF.APPPD.LP.menu.saveProcess, "click", this.save.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"save.gif"); this.menu.addMenuItem(MWF.APPPD.LP.menu.saveProcessNew, "click", this.saveNew.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"saveNew.gif", true); this.menu.addMenuLine(); if (this.isGrid){ this.menu.addMenuItem(MWF.APPPD.LP.menu.hideGrid, "click", function(){process.switchGrid(this);}, this.designer.path+""+this.options.style+"/toolbarIcon/"+"gridding.gif"); }else{ this.menu.addMenuItem(MWF.APPPD.LP.menu.showGrid, "click", function(){process.switchGrid(this);}, this.designer.path+""+this.options.style+"/toolbarIcon/"+"gridding.gif"); } this.menu.addMenuLine(); this.menu.addMenuItem(MWF.APPPD.LP.menu.checkProcess, "click", this.checkProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"checkProcess.gif", true); this.menu.addMenuItem(MWF.APPPD.LP.menu.exportProcess, "click", this.exportProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"processExplode.gif", true); this.menu.addMenuLine(); this.menu.addMenuItem(MWF.APPPD.LP.menu.printProcess, "click", this.printProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"print.gif", true); }, saveNew: function(e){ //unrealized this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100); //layout.notice("error", {x: "right", y:"top"}, MWF.APPPD.LP.unrealized); }, checkProcess: function(e){ //unrealized this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100); }, exportProcess: function(e){ //unrealized this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100); }, printProcess: function(e){ //unrealized this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100); }, saveNewEdition: function(e){ if (this.process.isNewProcess){ this.save(); }else{ var node = new Element("div", {"styles":this.designer.css.saveNewEditionNode}); var inforNode = new Element("div", {"html":this.designer.lp.upgradeInfor}).inject(node); var descriptionNode = new Element("div", {"styles": this.designer.css.editionDescriptionNode}).inject(node); var descriptionTitleNode = new Element("div", {"styles": this.designer.css.descriptionTitleNode, "text": this.designer.lp.editionDiscription}).inject(descriptionNode); var descriptionTextAreaNode = new Element("textarea", {"styles": this.designer.css.descriptionTextAreaNode}).inject(descriptionNode); var _self = this; o2.DL.open({ "content": node, "title": this.designer.lp.upgradeConfirm, "offset": {"y": -100}, "height": 400, "width": 600, "buttonList": [{ "type": "ok", "text": this.designer.lp.ok, "action": function(){ var textarea = this.content.getElement("textarea"); var discription = textarea.get("value"); if (!discription) { _self.designer.notice(_self.designer.lp.inputDiscription, "error", descriptionNode); }else{ var checkbox = this.content.getElement("input"); var enable = (!!checkbox && checkbox.get("checked")); _self.doSaveNewEdition(enable, discription); this.close(); } } },{ "type": "cancel", "text": this.designer.lp.cancel, "action": function(){ this.close(); } }] }); // var _self = this; // this.designer.confirm("infor", e, this.designer.lp.upgradeConfirm, {"html": this.designer.lp.upgradeInfor}, 520, 210, function(){ // var checkbox = this.content.getElement("input"); // var enable = (!!checkbox && checkbox.get("checked")); // _self.doSaveNewEdition(enable); // this.close(); // }, function(){ // this.close(); // }); } }, doSaveNewEdition: function(enable, description){ debugger; var process = Object.clone(this.process); process.editionDes = description; var oldIds = []; oldIds.push(process.id); if (process.begin) oldIds.push(process.begin.id); if (process.endList) process.endList.each(function(a){oldIds.push(a.id);}); if (process.agentList) process.agentList.each(function(a){oldIds.push(a.id);}); if (process.manualList) process.manualList.each(function(a){oldIds.push(a.id);}); if (process.conditionList) process.conditionList.each(function(a){oldIds.push(a.id);}); if (process.choiceList) process.choiceList.each(function(a){oldIds.push(a.id);}); if (process.parallelList) process.parallelList.each(function(a){oldIds.push(a.id);}); if (process.splitList) process.splitList.each(function(a){oldIds.push(a.id);}); if (process.mergeList) process.mergeList.each(function(a){oldIds.push(a.id);}); if (process.embedList) process.embedList.each(function(a){oldIds.push(a.id);}); if (process.publishList) process.publishList.each(function(a){oldIds.push(a.id);}); if (process.invokeList) process.invokeList.each(function(a){oldIds.push(a.id);}); if (process.cancelList) process.cancelList.each(function(a){oldIds.push(a.id);}); if (process.delayList) process.delayList.each(function(a){oldIds.push(a.id);}); if (process.messageList) process.messageList.each(function(a){oldIds.push(a.id);}); if (process.serviceList) process.serviceList.each(function(a){oldIds.push(a.id);}); if (process.routeList) process.routeList.each(function(a){oldIds.push(a.id);}); var actions = o2.Actions.load("x_processplatform_assemble_designer"); this.designer.actions.getId(oldIds.length, function(ids) { var checkUUIDs = ids.data; var processStr = JSON.encode(process); oldIds.each(function(oid, i){ var reg = new RegExp(oid, "ig"); processStr = processStr.replace(reg, checkUUIDs[i].id); }.bind(this)); process = JSON.decode(processStr); actions.ProcessAction.upgrade(this.process.id, process, function(json){ var processId = json.data.id; if (enable){ actions.ProcessAction.enableProcess(processId, function(processJson){ actions.ProcessAction.get(processId, function(processJson){ this.reload(processJson.data); }.bind(this)) }.bind(this)) }else{ actions.ProcessAction.get(processId, function(processJson){ this.reload(processJson.data); }.bind(this)) } }.bind(this)); }.bind(this)); }, listEdition: function(){ if (this.process.edition){ if (!this.editionListDlg){ MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.EditionList", function(){ this.editionListDlg = new MWF.xApplication.process.ProcessDesigner.widget.EditionList(this.process.application, this.process.edition, this); this.editionListDlg.load(); }.bind(this)); }else{ this.editionListDlg.show(); } }else{ this.designer.notice("infor", this.designer.lp.save_process); } }, listEditionDlg: function(editionList){ //var node = new Element("div", ) }, switchGrid: function(item){ if (this.isGrid){ this.hideGrid(); }else{ this.showGrid(); } }, showGrid: function(){ this.designer.paperNode.setStyle("background-image", "url("+MWF.defaultPath+"/process/ProcessChart/$Process/"+this.options.style+"/griddingbg.gif)"); // if (this.GridSet){ // this.GridSet.show(); // }else{ // var paperSize = $(this.paper.canvas).getParent().getSize(); // this.GridSet = this.paper.set(); // for (var i=20; i"+MWF.APPPD.LP.showAdvanced+"" }).inject(this.propertyListTab.tabNodeContainer); div.getElement("span").addEvents({ "mousedown": function(e){ e.stopPropagation(); }, "click": function(e){ this.showAdvanced.click(); e.stopPropagation(); }.bind(this) }); o2.UD.getDataJson("process-show-advanced", function(json){ this.showAdvanced = new Element("input", { "type": "checkbox", "checked": (!json) ? false : json.show, "events": { "mousedown": function(e){ e.stopPropagation(); }, "change": function(){ if (this.showAdvanced.checked){ var advs = this.propertyListNode.querySelectorAll("*[data-o2-advanced=\"yes\"]"); if (advs && advs.length){ for (var i=0; i