MWF.xApplication.process.Xform.widget = MWF.xApplication.process.Xform.widget || {}; //MWF.xDesktop.requireApp("process.Xform", "widget.RestActions", null, false); MWF.require("MWF.widget.Common", null, false); MWF.require("MWF.widget.MWFRaphael", null, false); MWF.xApplication.process.Xform.widget.Monitor = new Class({ Implements: [Options, Events], Extends: MWF.widget.Common, options: { "style": "default" }, initialize: function(container, worklog, recordList, processid, options, module){ this.setOptions(options); this.path = "../x_component_process_Xform/widget/$Monitor/"; this.cssPath = "../x_component_process_Xform/widget/$Monitor/"+this.options.style+"/css.wcss"; this._loadCss(); this.container = $(container); this.worklog = worklog; this.recordList = recordList; this.processid = processid; this.mobileScale = 2; this.module = module; this.load(); }, load: function(){ this.logProcessChartNode = new Element("div", {"styles": this.css.logProcessChartNode}).inject(this.container); this.logPathChartNode = new Element("div", {"styles": this.css.logPathChartNode}).inject(this.container); this.checkMonitorOpen(); }, checkMonitorOpen: function(){ var moduleNode = this.container; var module = moduleNode.retrieve("module"); var isDisplayNode = false; var isTabContent = false; while (true){ if (moduleNode.getStyle("display")==="none"){ isDisplayNode = true; } if (module && module.json.type==="Tab$Content"){ isTabContent = true; } if (isDisplayNode && isTabContent) break; moduleNode = moduleNode.getParent(); if (!moduleNode) break; if (!isTabContent) module = moduleNode.retrieve("module"); } if (isDisplayNode){ if (isTabContent){ for (var i=0; i scrollBottom) { // 矩形底部在视口下方,需要向下滚动 scrollParent.scrollTop = rectBottom - scrollSize.y; } // 检查是否需要水平滚动 if (rectLeft < scrollLeft) { // 矩形左侧在视口左方,需要向左滚动 scrollParent.scrollLeft = rectLeft; } else if (rectRight > scrollRight) { // 矩形右侧在视口右方,需要向右滚动 scrollParent.scrollLeft = rectRight - scrollSize.x; } }, playStop: function(){ this.playIcon.remove(); if (this.playLogNode) this.playLogNode.destroy(); this.playLogNode = null; this.playsStatus = { "index": 0 }; this.isPlaying = false; this.toolbar.childrenButton[0].setDisable(false); //this.toolbar.childrenButton[1].setDisable(true); //this.toolbar.childrenButton[2].setDisable(true); this.clearCount(); this.loadWorkLog(); }, processReturnStyle: function(){ this.worklog.each(function(log){ var activityType = log.fromActivityType; var activity = (activityType.toLowerCase()=="begin") ? this.process.begin : this.process[activityType+"s"][log.fromActivity]; activity.shap.attr(activity.style.shap); activity.passedCount = 0; activity.worklogs = []; var route = this.process.routes[log.route]; if (route){ route.line.attr(this.process.css.route.line.normal); route.point.attr(this.process.css.route.decision.normal); route.arrow.attr(this.process.css.route.arrow.normal); } if (log.taskCompletedList && log.taskCompletedList.length){ log.taskCompletedList.each(function(tc){ if (tc.processingType === "appendTask"){ if (activity.routes && activity.routes.length){ activity.routes.each(function(r){ if (tc.routeName === r.data.name){ r.line.attr(this.process.css.route.line.normal); r.point.attr(this.process.css.route.decision.normal); r.arrow.attr(this.process.css.route.arrow.normal); } }.bind(this)); } } }.bind(this)); } if (activity.countSet) activity.countSet.remove(); }.bind(this)); }, loadPaper: function(){ MWFRaphael.load(function(){ this.paperInNode = new Element("div", {"styles": this.css.paperInNode}).inject(this.paperNode); this.paper = Raphael(this.paperInNode, "98%", "99%"); this.paper.container = this.paperNode; MWF.xDesktop.requireApp("process.ProcessDesigner", "Process", function(){ this.process = new MWF.APPPD.Process(this.paper, this.processData, this, {"style":"flat", "isView": true, "onPostLoad": function(){ if (layout.mobile){ var s = this.paper.canvas.getSize(); var x = s.x*this.mobileScale; var y = s.y*this.mobileScale; this.paper.canvas.set({ "viewBox": "0 0 "+x+" "+y+"", "preserveAspectRatio": "xMinYMin meet" }); } this.loadWorkLog(); this.fireEvent("postLoad"); }.bind(this) }); this.process.load(); }.bind(this)); }.bind(this)); }, getProcess: function(callback){ this.action = MWF.Actions.get("x_processplatform_assemble_surface"); //this.action = new MWF.xApplication.process.Xform.widget.RestActions("x_processplatform_assemble_surface"); //this.action = new MWF.xApplication.process.Xform.widget.RestActions("x_processplatform_assemble_designer"); this.action.getProcess(function(json){ if (callback) callback(json); }, null, this.processid) }, clearCount: function (){ var activitys = {}; this.worklog.each(function(log){ var activityType = log.fromActivityType; var activity = (activityType.toLowerCase()=="begin") ? this.process.begin : this.process[activityType+"s"][log.fromActivity]; activity.passedCount = 0; activity.worklogs = []; if (!activitys[log.fromActivity]) activitys[log.fromActivity] = activity }.bind(this)); if (this.recordList){ this.recordList.each(function (r, i){ var activity = activitys[r.fromActivity]; if(activity)activity.recordCount = 0; }.bind(this)); } }, loadWorkLog: function(){ this.countNodes = []; var activitys = {}; this.worklogToken = {}; this.worklog.each(function(log){ this.worklogToken[log.fromActivityToken] = log; var activityType = log.fromActivityType; var activity = (activityType.toLowerCase()=="begin") ? this.process.begin : this.process[activityType+"s"][log.fromActivity]; if (log.connected){ activity.shap.attr(this.css.passedActivityShap); }else{ activity.shap.attr(this.css.currentActivityShap); } var route = this.process.routes[log.route]; if (route){ route.line.attr(this.css.passedRouteShap); route.point.attr(this.css.passedRouteFillShap); route.arrow.attr(this.css.passedRouteFillShap); } if (log.taskCompletedList && log.taskCompletedList.length){ log.taskCompletedList.each(function(tc){ if (tc.processingType === "appendTask"){ if (activity.routes && activity.routes.length){ activity.routes.each(function(r){ if (tc.routeName === r.data.name){ r.line.attr(this.css.passedRouteShap); r.point.attr(this.css.passedRouteFillShap); r.arrow.attr(this.css.passedRouteFillShap); } }.bind(this)); } } }.bind(this)); } var passedCount = log.taskCompletedList.length; //var passedCount = log.taskCompletedList.length || 1; if (passedCount) activity.passedCount = (activity.passedCount) ? activity.passedCount+passedCount : passedCount; if (!activity.worklogs) activity.worklogs = []; activity.worklogs.push(log); if (!activitys[log.fromActivity]) activitys[log.fromActivity] = activity }.bind(this)); if (this.recordList){ this.recordList.each(function (r, i){ var activity = activitys[r.fromActivity]; if (!activity.recordCount) activity.recordCount = 0 activity.recordCount++; }.bind(this)); } var offset = this.paperNode.getPosition(this.paperNode.getOffsetParent()); var size = this.paperNode.getSize(); Object.each(activitys, function(activity){ this.writePassCount(activity); this.writeWorkLog(activity, offset, size); }.bind(this)); }, writePassCount: function(activity){ if (activity.passedCount || activity.recordCount){ var x = activity.point.x+activity.width; var y = activity.point.y; var shap = this.paper.circle(x, y, 9); shap.attr(this.css.activityPassedCount); text = this.paper.text(x, y, activity.recordCount || activity.passedCount); text.attr(this.css.activityPassedCountText); activity.countSet = this.paper.set(); activity.countSet.push(shap, text); } }, writeWorkLog: function(activity, offset, size){ var _self = this; activity.set.click(function(e){ if (!_self.isPlaying){ if (this.process.selectedActivitys.length){ if (!this.noselected){ this.selected(); _self.showWorklog(this, offset, size); } this.noselected = false; } if (this.countSet) this.countSet.toFront(); } e.stopPropagation(); }.bind(activity)); activity.set.mousedown(function(e){ if (!_self.isPlaying) { if (!this.process.selectedActivitys.length) { this.selected(); _self.showWorklog(this, offset, size); } if (this.countSet) this.countSet.toFront(); } e.stopPropagation(); }.bind(activity)); this.paper.canvas.addEvent("click", function(e){ if (!_self.isPlaying) { if (this.unSelectedEvent) { if (this.currentSelected || this.selectedActivitys.length) { this.unSelected(e); _self.hideCurrentWorklog(); } } else { this.unSelectedEvent = true; } } }.bind(this.process)); }, getlogNodePosition : function(activity, node, offset, psize){ var targetCoondinates = { left: activity.point.x, top: activity.point.y, width: activity.width, height: activity.height, right: activity.point.x + activity.width, bottom: activity.point.y + activity.height }; var containerScroll = this.paperNode.getScroll(); var containerSize = this.paperNode.getSize(); var nodeSize = node.getSize(); var left; var offsetX = 10; var priorityOfX = [ "center", "right", "left" ]; for( var i=0; i containerSize.x - targetCoondinates.right){ left = targetCoondinates.left - nodeSize.x - offsetX; positionX = "left"; break; } } if( priorityOfX[i] === "right" ){ if( containerSize.x + containerScroll.x - targetCoondinates.right > nodeSize.x ){ left = targetCoondinates.right + offsetX; positionX = "right"; break; } } } if( !left ){ if( targetCoondinates.left - containerScroll.x > containerSize.x - targetCoondinates.right){ left = targetCoondinates.left - nodeSize.x - offsetX; positionX = "left"; }else{ left = targetCoondinates.right + offsetX; positionX = "right"; } } var top; var priorityOfY = [ "middle", "bottom", "top" ]; for( var i=0; i containerScroll.y && targetCoondinates.bottom - (targetCoondinates.height/2) + ( nodeSize.y / 2 ) - containerScroll.y < containerSize.y ){ top = targetCoondinates.top + (targetCoondinates.height/2) - ( nodeSize.y / 2 ) ; this.positionY = "middle"; break; } } if( priorityOfY[i] === "top" ){ if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom ){ top = targetCoondinates.bottom - nodeSize.y; this.positionY = "top"; break; } } if( priorityOfY[i] === "bottom" ){ if( containerSize.y + containerScroll.y - targetCoondinates.bottom > nodeSize.y ){ top = targetCoondinates.top; this.positionY = "bottom"; break; } } } if( !top ){ if( targetCoondinates.top + (targetCoondinates.height/2) - ( nodeSize.y / 2 ) > containerScroll.y && targetCoondinates.bottom - (targetCoondinates.height/2) + ( nodeSize.y / 2 ) - containerScroll.y < containerSize.y ){ top = targetCoondinates.top + (targetCoondinates.height/2) - ( nodeSize.y / 2 ) ; this.positionY = "middle"; } else if( targetCoondinates.top - containerScroll.y > containerSize.y - targetCoondinates.bottom ){ top = targetCoondinates.bottom - nodeSize.y; this.positionY = "top"; }else{ top = targetCoondinates.top; this.positionY = "bottom"; } } // var arrowOffsetY = 0; // if( this.options.isFitToContainer ){ if( top < containerScroll.y ){ // arrowOffsetY = containerScroll.y - top; top = containerScroll.y; }else if( top + nodeSize.y > containerSize.y + containerScroll.y ){ // arrowOffsetY = containerSize.y + containerScroll.y - top - nodeSize.y; top = containerSize.y + containerScroll.y - nodeSize.y; } return { "x" : left, "y" : top }; }, getlogNodePosition_bak: function(activity, node, offset, psize){ offset.x = 0; offset.y = 0; var size = node.getSize(); var y = 0; var x = activity.point.x+activity.width+15+offset.x; tmpX = x + size.x; if (tmpX>offset.x+psize.x){ x = activity.point.x - size.x - 15 + offset.x; if (x psize.x )x = psize.x - size.x; if( y + size.y > psize.y )y = psize.y - size.y; if( x < 0 )x = 0; if( y < 0 )y = 0; // var p = this.paperNode.getScroll(); // var scrollY = 0; // var scrollX = 0; // var tmpNode = this.paperNode.getParent(); // while (tmpNode){ // var s = tmpNode.getScroll(); // scrollY += s.y; // scrollX += s.x; // tmpNode = tmpNode.getParent(); // } // y = y-p.y-scrollY; // x = x-p.x-scrollX; return {"x": x, "y": y}; }, showWorklog: function(activity, offset, psize){ this.hideCurrentWorklog(); if (!activity.worklogNode) activity.worklogNode = this.createWorkLogNode(activity.worklogs, activity); this.currentWorklogNode = activity.worklogNode; this.currentWorklogNode.setStyle("display", !!this.currentWorklogNode.get("html") ? "block" : "none"); this.setWorkLogPosition(activity, activity.worklogNode, offset, psize); }, setWorkLogPosition(activity, logNode, offset, psize){ if( !logNode )logNode = activity.worklogNode; if( layout.mobile ){ var pSize = this.paperNode.getSize(); var bodySize = $(document.body).getSize(); if( this.paperNode.getPosition().y + pSize.y > bodySize.y ){ var mobileActionNode = document.body.getElement(".o2_form_mobile_actions"); logNode.inject( $(document.body) ); logNode.setStyles({ "display": "block", "position": "absolute", "width": "calc( 100% - 4px )", "max-width": "500px", "bottom": mobileActionNode ? (mobileActionNode.getSize().y+1+"px") : "1px", "left": "0px" }); logNode.setStyle("left", (bodySize.x - logNode.getSize().x)/2 + "px"); }else{ logNode.inject( this.paperNode ); logNode.setStyles({ "display": "block", "position": "absolute", "width": "calc( 100% - 4px )", "max-width": "500px", "bottom": "1px", "left": "0px" }); logNode.setStyle("left", (pSize.x - logNode.getSize().x)/2 + "px"); } }else{ var p = this.getlogNodePosition(activity, logNode, offset, psize); logNode.setPosition({"x": p.x, "y": p.y}); } }, hideCurrentWorklog: function(){ if (this.currentWorklogNode){ this.currentWorklogNode.setStyle("display", "none"); this.currentWorklogNode = null; } }, bindTabEvent: function(){ if( this.module ){ var tab = this.module.getParentModule(); if( tab && tab.page ){ tab.page.addEvent("postHide", function () { if(this.currentWorklogNode)this.currentWorklogNode.hide() }.bind(this)) } } }, createWorkLogNode: function(worklogs, activity){ var node = new Element("div", {"styles": this.css.workLogNode}); if (this.recordList){ var logs = this.recordList.filter(function(r){ return r.fromActivity === activity.data.id; }); logs.each(function(log, idx){ var workNode = new Element("div", {"styles": this.css.workLogWorkNode}).inject(node); if ((idx % 2)==0){ workNode.setStyle("background-color", "#FFF"); }else{ workNode.setStyle("background-color", "#EEE"); } var router, opinion, arrivedActivitys, arrivedUsers; arrivedActivitys = log.properties.nextManualList.map(function(o){ return o.activityName; }).join(","); arrivedUsers = (log.properties.nextManualTaskIdentityList && log.properties.nextManualTaskIdentityList.length) ? o2.name.cns(log.properties.nextManualTaskIdentityList).join(",") : ""; switch (log.type) { case "empower": router = MWF.xApplication.process.Xform.LP.empower; var empowerTo = (log.properties.nextManualTaskIdentityList && log.properties.nextManualTaskIdentityList.length) ? o2.name.cns(log.properties.nextManualTaskIdentityList).join(",") : ""; opinion = MWF.xApplication.process.Xform.LP.empowerTo + empowerTo; break; case "retract": router = MWF.xApplication.process.Xform.LP.retract; opinion = MWF.xApplication.process.Xform.LP.retract; break; case "reroute": router = log.properties.routeName || MWF.xApplication.process.Xform.LP.reroute; opinion = log.properties.opinion || MWF.xApplication.process.Xform.LP.rerouteTo+": "+arrivedActivitys; break; case "rollback": router = log.properties.routeName || MWF.xApplication.process.Xform.LP.rollback; opinion = log.properties.opinion || MWF.xApplication.process.Xform.LP.rollbackTo+": "+log.arrivedActivityName; break; case "reset": var resetUser = log.properties.nextManualTaskIdentityList.erase(log.identity); resetUserText = o2.name.cns(resetUser).join(","); router = MWF.xApplication.process.Xform.LP.resetTo+":"+resetUserText; opinion = log.properties.opinion || "" break; case "appendTask": case "back": case "addSplit": case "urge": case "expire": case "read": default: router = log.properties.routeName || ""; opinion = log.properties.opinion || ""; } if (log.type==="currentTask"){ var taskNode = new Element("div", {"styles": this.css.workLogTaskNode}).inject(workNode); var html = "
"+log.person.substring(0, log.person.indexOf("@"))+" "+MWF.xApplication.process.Xform.LP.processing+"
"; taskNode.set("html", html); }else{ var taskNode = new Element("div", {"styles": this.css.workLogTaskNode}).inject(workNode); var html = "
"+log.person.substring(0, log.person.indexOf("@"))+":
"; html += "
["+router+"] "+o2.txt(opinion)+"
"; html += "
"+log.recordTime+"
"; taskNode.set("html", html); } }.bind(this)); }else{ worklogs.each(function(log, idx){ var workNode = new Element("div", {"styles": this.css.workLogWorkNode}).inject(node); if ((idx % 2)==0){ workNode.setStyle("background-color", "#FFF"); }else{ workNode.setStyle("background-color", "#EEE"); } if (log.taskCompletedList.length+log.taskList.length<1){ if (log.connected){ var taskNode = new Element("div", {"styles": this.css.workLogTaskNode}).inject(workNode); var html = "
"+MWF.xApplication.process.Xform.LP.systemProcess+"
"; html += "
"+log.arrivedTime+"
"; taskNode.set("html", html); }else{ var taskNode = new Element("div", {"styles": this.css.workLogTaskNode}).inject(workNode); var html = "
"+MWF.xApplication.process.Xform.LP.systemProcess+"
"; taskNode.set("html", html); } }else{ log.taskCompletedList.each(function(task){ var taskNode = new Element("div", {"styles": this.css.workLogTaskNode}).inject(workNode); var html = "
"+task.person.substring(0, task.person.indexOf("@"))+":
"; html += "
["+(task.routeName || "")+"] "+o2.txt(task.opinion)+"
"; html += "
"+task.completedTime+"
"; taskNode.set("html", html); }.bind(this)); log.taskList.each(function(task){ var taskNode = new Element("div", {"styles": this.css.workLogTaskNode}).inject(workNode); var html = "
"+task.person.substring(0, task.person.indexOf("@"))+" "+MWF.xApplication.process.Xform.LP.processing+"
"; taskNode.set("html", html); }.bind(this)); } }.bind(this)); } node.inject(this.paperNode); return node; } }); MWF.xApplication.process.Xform.widget.Monitor.Animation = new Class({ Implements: [Events], initialize: function(monitor, log){ } });