Process.js 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.process = MWF.xApplication.process || {};
  3. MWF.xApplication.process.ProcessDesigner = MWF.xApplication.process.ProcessDesigner || {};
  4. MWF.APPPD = MWF.xApplication.process.ProcessDesigner;
  5. MWF.require("MWF.widget.Common", null, false);
  6. MWF.xDesktop.requireApp("process.ProcessDesigner", "lp."+MWF.language, null, false);
  7. MWF.xDesktop.requireApp("process.ProcessDesigner", "Property", null, false);
  8. MWF.xDesktop.requireApp("process.ProcessDesigner", "Activity", null, false);
  9. MWF.xDesktop.requireApp("process.ProcessDesigner", "Route", null, false);
  10. MWF.xApplication.process.ProcessDesigner.Process = new Class({
  11. Extends: MWF.widget.Common,
  12. Implements: [Options, Events],
  13. options: {
  14. "style": "default",
  15. "isView": false
  16. },
  17. initialize: function(paper, process, designer, options){
  18. this.setOptions(options);
  19. this.path = "/x_component_process_ProcessDesigner/$Process/";
  20. this.cssPath = "/x_component_process_ProcessDesigner/$Process/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.designer = designer;
  23. this.process = process;
  24. this.process.projectionData = (process.project) ? JSON.parse(process.project) : null;
  25. this.paper = paper;
  26. if(this.designer.application) this.process.applicationName = this.designer.application.name;
  27. if(this.designer.application) this.process.application = this.designer.application.id;
  28. // if(this.designer.category) this.process.processCategory = this.designer.category.data.id;
  29. // this.process.starterMode = "assign";
  30. this.activityTemplates = null;
  31. this.routeTemplates = null;
  32. //activity list
  33. this.begin = null;
  34. this.ends = {};
  35. this.cancels={};
  36. this.manuals = {};
  37. this.conditions = {};
  38. this.choices = {};
  39. this.splits = {};
  40. this.parallels = {};
  41. this.merges = {};
  42. this.embeds = {};
  43. this.delays = {};
  44. this.invokes = {};
  45. this.services = {};
  46. this.agents = {};
  47. this.messages = {};
  48. this.activitys=[];
  49. this.selectedActivitys = [];
  50. this.selectedActivityDatas = [];
  51. this.scripts = {};
  52. this.routes = {};
  53. this.routeDatas = {};
  54. this.isGrid = true;
  55. //activity loaded
  56. this.loadedBegin = false;
  57. this.loadedEnds = false;
  58. this.loadedCancels = false;
  59. this.loadedConditions = false;
  60. this.loadedChoices = false;
  61. this.loadedManuals = false;
  62. this.loadedSplits = false;
  63. this.loadedParallels = false;
  64. this.loadedMerges = false;
  65. this.loadedEmbeds = false;
  66. this.loadedDelays = false;
  67. this.loadedInvokes = false;
  68. this.loadedServices = false;
  69. this.loadedAgents = false;
  70. this.loadedMessages = false;
  71. this.isCreateRoute = false;
  72. this.currentCreateRoute = null;
  73. this.isCopyRoute = false;
  74. this.currentCopyRoute = null;
  75. this.isBrokenLine = false;
  76. this.isChangeRouteTo = false;
  77. this.isChangeRouteFrom = false;
  78. this.currentChangeRoute = null;
  79. this.unSelectedEvent = true;
  80. this.panel = null;
  81. this.property = null;
  82. // this.isFocus = false;
  83. this.isNewProcess = (this.process.id) ? false : true;
  84. },
  85. load : function(){
  86. // if (this.isNewProcess){
  87. // this.process.createTime = new Date().format('db');
  88. // this.process.updateTime = new Date().format('db');
  89. // }
  90. this.createPropertyPanel();
  91. this.loadProcessActivitys(function(){
  92. // this.loadProcessActivitys();
  93. this.loadProcessRoutes();
  94. this.loadActivityRoutes();
  95. this.loadProcessScripts();
  96. this.checkLoadRoutes();
  97. if (this.isNewProcess) this.checkUUID();
  98. this.fireEvent("postLoad");
  99. }.bind(this));
  100. this.setEvent();
  101. this.setMenu();
  102. this.showProperty();
  103. this.showEditionInfor();
  104. },
  105. checkLoadRoutes: function(){
  106. Object.each(this.routes, function(route){
  107. if (!route.loaded) route.load();
  108. });
  109. },
  110. checkUUID: function(){
  111. //新流程, 此处处理所有元素的id
  112. this.process.isNewProcess = true;
  113. var idCount = (this.process.begin) ? 2 : 1;
  114. idCount += (this.process.endList) ? this.process.endList.length : 0;
  115. idCount += (this.process.manualList) ? this.process.manualList.length : 0;
  116. idCount += (this.process.conditionList) ? this.process.conditionList.length : 0;
  117. idCount += (this.process.choiceList) ? this.process.choiceList.length : 0;
  118. idCount += (this.process.parallelList) ? this.process.parallelList.length : 0;
  119. idCount += (this.process.splitList) ? this.process.splitList.length : 0;
  120. idCount += (this.process.mergeList) ? this.process.mergeList.length : 0;
  121. idCount += (this.process.embedList) ? this.process.embedList.length : 0;
  122. idCount += (this.process.invokeList) ? this.process.invokeList.length : 0;
  123. idCount += (this.process.cancelList) ? this.process.cancelList.length : 0;
  124. idCount += (this.process.delayList) ? this.process.delayList.length : 0;
  125. idCount += (this.process.messageList) ? this.process.messageList.length : 0;
  126. idCount += (this.process.serviceList) ? this.process.serviceList.length : 0;
  127. idCount += (this.process.routeList) ? this.process.routeList.length : 0;
  128. this.designer.actions.getId(idCount, function(ids){
  129. this.checkUUIDs = ids.data;
  130. //流程ID
  131. this.process.id = this.checkUUIDs.pop().id;
  132. this.process.createTime = new Date().format('db');
  133. this.process.updateTime = new Date().format('db');
  134. for (var i=0; i<this.activitys.length; i++){
  135. if (this.activitys[i].type!="begin"){
  136. delete this[this.activitys[i].type+"s"][this.activitys[i].data.id];
  137. }
  138. this.activitys[i].data.id = this.checkUUIDs.pop().id;
  139. this.activitys[i].data.process = this.process.id;
  140. if (this.activitys[i].type!="begin"){
  141. this[this.activitys[i].type+"s"][this.activitys[i].data.id] = this.activitys[i];
  142. }
  143. }
  144. for (var i=0; i<this.activitys.length; i++){
  145. this.activitys[i].checkUUID();
  146. }
  147. }.bind(this));
  148. },
  149. loadProcessScripts: function(){
  150. if (this.process.scriptList){
  151. this.process.scriptList.each(function(script){
  152. this.scripts[script.id] = script;
  153. }.bind(this));
  154. }
  155. },
  156. setStyle: function(style){
  157. this.options.style = style;
  158. this.reload(this.process);
  159. },
  160. reload: function(process){
  161. debugger;
  162. //this.process = process;
  163. this.panel.destroy();
  164. this.paper.clear();
  165. this.initialize(this.paper, process, this.designer, this.options);
  166. this.createPropertyPanel();
  167. //return false;
  168. this.loadProcessActivitys(function(){
  169. this.loadProcessRoutes();
  170. this.loadActivityRoutes();
  171. this.checkLoadRoutes();
  172. // this.loadProcessRoutes();
  173. // this.loadProcessDecisions();
  174. // this.loadActivityDecisions();
  175. }.bind(this));
  176. this.showProperty();
  177. this.showEditionInfor();
  178. if (process && this.designer.options.id != process.id){
  179. var app = layout.desktop.apps["process.ProcessDesigner"+this.designer.options.id];
  180. if (app){
  181. delete layout.desktop.apps["process.ProcessDesigner"+this.designer.options.id];
  182. this.designer.appId = "process.ProcessDesigner"+process.id;
  183. layout.desktop.apps[this.designer.appId] = this.designer;
  184. }
  185. this.designer.setOptions({"id": process.id});
  186. }
  187. },
  188. setEvent: function(){
  189. this.paper.canvas.addEvent("selectstart", function(e){e.preventDefault();e.stopPropagation();});
  190. if (!this.options.isView){
  191. this.paper.canvas.addEvent("click", function(e){
  192. if (this.unSelectedEvent){
  193. if (this.currentSelected || this.selectedActivitys.length) this.unSelected(e);
  194. }else{
  195. this.unSelectedEvent = true;
  196. }
  197. }.bind(this));
  198. this.paper.canvas.addEvent("mousedown", function(e){
  199. this.checkCreateRoute(e);
  200. this.checkSelectMulti(e);
  201. }.bind(this));
  202. }
  203. //this.paper.canvas.addEvents({
  204. // "blur": function(){this.isFocus = false;}.bind(this),
  205. // "focus": function(){this.isFocus = true;}.bind(this)
  206. //});
  207. },
  208. checkSelectMulti: function(e){
  209. if (!e.rightClick){
  210. var x = e.event.offsetX;
  211. var y = e.event.offsetY;
  212. var els = this.paper.getElementsByPoint(x, y);
  213. if (!els.length){
  214. if (!this.isCreateRoute && !this.isCopyRoute){
  215. this.checkSelectMultiMouseMoveBind = function(e){
  216. this.checkSelectMultiMouseMove(e, {"x": x, "y": y});
  217. }.bind(this);
  218. this.checkSelectMultiMouseUpBind = function(e){
  219. this.checkSelectMultiStop(e, {"x": x, "y": y});
  220. }.bind(this);
  221. this.paper.canvas.addEvent("mousemove", this.checkSelectMultiMouseMoveBind);
  222. this.paper.canvas.addEvent("mouseup", this.checkSelectMultiMouseUpBind);
  223. }
  224. }
  225. }
  226. },
  227. unSelectedAll: function(){
  228. if (this.currentSelected) this.currentSelected.unSelected();
  229. this.property.hide();
  230. this.selectedActivitys.each(function(a){
  231. a.unSelectedMulti();
  232. });
  233. this.selectedActivitys = [];
  234. this.selectedActivityDatas = [];
  235. },
  236. checkSelectMultiMouseMove: function(e, p){
  237. var pMove = {"x": e.event.offsetX, "y": e.event.offsetY};
  238. if (MWFRaphael.getPointDistance(p,pMove)>8){
  239. this.paper.canvas.removeEvent("mousemove", this.checkSelectMultiMouseMoveBind);
  240. if (!this.isCreateRoute && !this.isCopyRoute && !this.isBrokenLine && !this.isChangeRouteTo && !this.isChangeRouteFrom){
  241. var x = Math.min(p.x, pMove.x);
  242. var y = Math.min(p.y, pMove.y);
  243. var width = Math.abs(pMove.x-p.x);
  244. var height = Math.abs(pMove.y-p.y);
  245. var selectBox = this.paper.rect(x, y, width, height, 0).attr({
  246. "fill": "#a8caec",
  247. "stroke": "#3399ff",
  248. "stroke-width": "0.8",
  249. "fill-opacity": 0.5
  250. });
  251. this.beginSelectMultiMouseMoveBind = function(e){
  252. this.beginSelectMultiMouseMove(e, p, selectBox);
  253. }.bind(this);
  254. this.endSelectMultiMouseMoveBind = function(e){
  255. return this.endSelectMulti(e, p, selectBox);
  256. }.bind(this);
  257. this.unSelectedAll();
  258. this.paper.canvas.addEvent("mousemove", this.beginSelectMultiMouseMoveBind);
  259. this.paper.canvas.addEvent("mouseup", this.endSelectMultiMouseMoveBind);
  260. }
  261. }
  262. },
  263. checkSelectMultiStop: function(){
  264. this.paper.canvas.removeEvent("mousemove", this.checkSelectMultiMouseMoveBind);
  265. },
  266. beginSelectMultiMouseMove: function(e, p, rect){
  267. var pMove = {"x": e.event.offsetX, "y": e.event.offsetY};
  268. var x = Math.min(p.x, pMove.x);
  269. var y = Math.min(p.y, pMove.y);
  270. var width = Math.abs(pMove.x-p.x);
  271. var height = Math.abs(pMove.y-p.y);
  272. // rect.attr("path", MWFRaphael.getRectPath(x, y, width, height, 0));
  273. rect.attr({
  274. //"path", MWFRaphael.getRectPath(x, y, width, height, 0)
  275. "x": x,
  276. "y": y,
  277. "width": width,
  278. "height": height
  279. });
  280. this.checkSelectActivity(e, p, rect);
  281. },
  282. endSelectMulti: function(e, p, rect){
  283. rect.remove();
  284. if (this.selectedActivityDatas.length){
  285. this.panel.data = this.selectedActivityDatas;
  286. }
  287. this.paper.canvas.removeEvent("mousemove", this.beginSelectMultiMouseMoveBind);
  288. this.paper.canvas.removeEvent("mouseup", this.endSelectMultiMouseMoveBind);
  289. if (this.selectedActivitys.length){
  290. this.unSelectedEvent = false;
  291. window.setTimeout(function(){this.unSelectedEvent = true;}.bind(this), 300);
  292. }
  293. return false;
  294. },
  295. checkSelectActivity: function(e, p, rect){
  296. var pMove = {"x": e.event.offsetX, "y": e.event.offsetY};
  297. var x = Math.min(p.x, pMove.x);
  298. var y = Math.min(p.y, pMove.y);
  299. var toX = Math.max(p.x, pMove.x);
  300. var toY = Math.max(p.y, pMove.y);
  301. this.activitys.each(function(activity){
  302. var ax = activity.center.x;
  303. var ay = activity.center.y;
  304. if (ax>x && ax<toX && ay>y && ay<toY){
  305. if (!activity.selectedMultiStatus) activity.selectedMulti();
  306. }else{
  307. this.selectedActivitys.erase(activity);
  308. this.selectedActivityDatas.erase(activity.data);
  309. activity.unSelectedMulti();
  310. }
  311. }.bind(this));
  312. if (this.selectedActivityDatas.length){
  313. if (this.property) this.property.showMultiActivity(this.selectedActivitys);
  314. this.panel.propertyTabPage.showTabIm();
  315. this.panel.data = this.selectedActivityDatas;
  316. }else{
  317. this.unSelectedAll();
  318. this.showProperty();
  319. }
  320. },
  321. showProperty: function(){
  322. if (!this.property){
  323. this.property = new MWF.APPPD.Process.Property(this, {
  324. "onPostLoad": function(){
  325. this.property.show();
  326. }.bind(this)
  327. });
  328. this.property.load();
  329. }else{
  330. this.property.show();
  331. }
  332. // this.isFocus = true;
  333. },
  334. showEditionInfor: function(){
  335. if (this.process.edition){
  336. if (this.designer.processEditionNode){
  337. this.designer.processEditionNode.removeEvents("click");
  338. if (this.process.editionEnable){
  339. this.designer.processEditionNode.set("text", this.designer.lp.enable);
  340. this.designer.processEditionNode.addClass("mainColor_bg");
  341. }else{
  342. this.designer.processEditionNode.set("text", this.designer.lp.notEnable);
  343. this.designer.processEditionNode.removeClass("mainColor_bg");
  344. this.designer.processEditionNode.addEvent("click", function(e){
  345. this.enableCurrentEdition(e);
  346. }.bind(this));
  347. }
  348. }
  349. if (this.designer.processEditionInforNode){
  350. var text = this.designer.lp.currentEdition+": <span class='mainColor_color'>"+this.process.editionNumber+"</span> "+this.designer.lp.editionUpdate+": <span class='mainColor_color'>"+o2.name.cn(this.process.lastUpdatePerson)+" ("+this.process.updateTime+")</span>";
  351. this.designer.processEditionInforNode.set("html", text);
  352. }
  353. }
  354. },
  355. enableCurrentEdition: function(e){
  356. var _self = this;
  357. this.designer.confirm("infor", e, this.designer.lp.edition_list.enabledProcessTitle, {"html": this.designer.lp.edition_list.enabledProcessInfor}, 600, 120, function(){
  358. _self.save(function(){
  359. var actions = o2.Actions.load("x_processplatform_assemble_designer").ProcessAction;
  360. actions.enableProcess(this.process.id, function(json){
  361. actions.get(this.process.id, function(json){
  362. this.reload(json.data);
  363. }.bind(this))
  364. }.bind(this));
  365. }.bind(_self));
  366. this.close();
  367. },function(){this.close();})
  368. },
  369. unSelected: function(e){
  370. //var els = this.paper.getElementsByPoint(e.event.layerX, e.event.layerY);
  371. var els = this.paper.getElementsByPoint(e.event.offsetX, e.event.offsetY);
  372. if (!els.length){
  373. this.unSelectedAll();
  374. this.showProperty();
  375. // if (this.currentSelected){
  376. // this.currentSelected.unSelected();
  377. // }
  378. }
  379. },
  380. setMenu: function(){
  381. MWF.require("MWF.widget.Menu", function(){
  382. this.menu = new MWF.widget.Menu(this.paper.canvas, {
  383. "onQueryShow": function(e){
  384. //var obj = this.getPointElement(e.event.layerX, e.event.layerY);
  385. var obj = this.getPointElement(e.event.offsetX, e.event.offsetY);
  386. switch (obj.type){
  387. case "activity":
  388. this.addActivityMenu(obj.bind);
  389. break;
  390. case "route":
  391. this.addRouteMenu(obj.bind);
  392. break;
  393. default:
  394. this.addProcessMenu();
  395. };
  396. }.bind(this)
  397. });
  398. this.menu.load();
  399. }.bind(this));
  400. },
  401. addPublicMenu: function(bind, newRoute){
  402. var newRouteFun = newRoute;
  403. if (!newRouteFun) newRouteFun = this.createRoute.bind(this);
  404. this.menu.addMenuItem(MWF.APPPD.LP.menu.newRoute, "click", newRouteFun, this.designer.path+""+this.options.style+"/toolbarIcon/"+"newRouter.gif");
  405. if (!this.newActivityMenu){
  406. MWF.require("MWF.widget.Menu", null, false);
  407. this.newActivityMenu = new MWF.widget.Menu(this.paper.canvas, {"event": null});
  408. this.newActivityMenu.load();
  409. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.manual, "click", this.createManualActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"manual.gif");
  410. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.condition, "click", this.createConditionActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"condition.gif");
  411. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.auto, "click", this.createAutoActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"auto.gif");
  412. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.split, "click", this.createSplitActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"split.gif");
  413. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.merge, "click", this.createMergeActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"merge.gif");
  414. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.embed, "click", this.createEmbedActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"embed.gif");
  415. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.invoke, "click", this.createInvokesActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"invoke.gif");
  416. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.begin, "click", this.createBeginActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"begin.gif");
  417. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.end, "click", this.createEndActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"end.gif");
  418. }
  419. this.menu.addMenuMenu(MWF.APPPD.LP.menu.newActivity, this.designer.path+""+this.options.style+"/toolbarIcon/"+"newActivity.gif", this.newActivityMenu);
  420. },
  421. addActivityMenu: function(bind){
  422. this.menu.clearItems();
  423. var newRoute = function(){bind.quickCreateRoute();};
  424. this.addPublicMenu(bind, newRoute);
  425. this.menu.addMenuLine();
  426. 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");
  427. this.menu.addMenuLine();
  428. 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");
  429. },
  430. addRouteMenu: function(bind){
  431. this.menu.clearItems();
  432. this.addPublicMenu();
  433. this.menu.addMenuLine();
  434. 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");
  435. },
  436. addProcessMenu: function(){
  437. var process = this;
  438. this.menu.clearItems();
  439. this.addPublicMenu();
  440. this.menu.addMenuLine();
  441. this.menu.addMenuItem(MWF.APPPD.LP.menu.saveProcess, "click", this.save.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"save.gif");
  442. this.menu.addMenuItem(MWF.APPPD.LP.menu.saveProcessNew, "click", this.saveNew.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"saveNew.gif", true);
  443. this.menu.addMenuLine();
  444. if (this.isGrid){
  445. this.menu.addMenuItem(MWF.APPPD.LP.menu.hideGrid, "click", function(){process.switchGrid(this);}, this.designer.path+""+this.options.style+"/toolbarIcon/"+"gridding.gif");
  446. }else{
  447. this.menu.addMenuItem(MWF.APPPD.LP.menu.showGrid, "click", function(){process.switchGrid(this);}, this.designer.path+""+this.options.style+"/toolbarIcon/"+"gridding.gif");
  448. }
  449. this.menu.addMenuLine();
  450. this.menu.addMenuItem(MWF.APPPD.LP.menu.checkProcess, "click", this.checkProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"checkProcess.gif", true);
  451. this.menu.addMenuItem(MWF.APPPD.LP.menu.exportProcess, "click", this.exportProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"processExplode.gif", true);
  452. this.menu.addMenuLine();
  453. this.menu.addMenuItem(MWF.APPPD.LP.menu.printProcess, "click", this.printProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"print.gif", true);
  454. },
  455. saveNew: function(e){
  456. //unrealized
  457. this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100);
  458. //layout.notice("error", {x: "right", y:"top"}, MWF.APPPD.LP.unrealized);
  459. },
  460. checkProcess: function(e){
  461. //unrealized
  462. this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100);
  463. },
  464. exportProcess: function(e){
  465. //unrealized
  466. this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100);
  467. },
  468. printProcess: function(e){
  469. //unrealized
  470. this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100);
  471. },
  472. saveNewEdition: function(e){
  473. if (this.process.isNewProcess){
  474. this.save();
  475. }else{
  476. var node = new Element("div", {"styles":this.designer.css.saveNewEditionNode});
  477. var inforNode = new Element("div", {"html":this.designer.lp.upgradeInfor}).inject(node);
  478. var descriptionNode = new Element("div", {"styles": this.designer.css.editionDescriptionNode}).inject(node);
  479. var descriptionTitleNode = new Element("div", {"styles": this.designer.css.descriptionTitleNode, "text": this.designer.lp.editionDiscription}).inject(descriptionNode);
  480. var descriptionTextAreaNode = new Element("textarea", {"styles": this.designer.css.descriptionTextAreaNode}).inject(descriptionNode);
  481. var _self = this;
  482. o2.DL.open({
  483. "content": node,
  484. "title": this.designer.lp.upgradeConfirm,
  485. "offset": {"y": -100},
  486. "height": 330,
  487. "buttonList": [{
  488. "type": "ok",
  489. "text": this.designer.lp.ok,
  490. "action": function(){
  491. var textarea = this.content.getElement("textarea");
  492. var discription = textarea.get("value");
  493. if (!discription) {
  494. _self.designer.notice(_self.designer.lp.inputDiscription, "error", descriptionNode);
  495. }else{
  496. var checkbox = this.content.getElement("input");
  497. var enable = (!!checkbox && checkbox.get("checked"));
  498. _self.doSaveNewEdition(enable, discription);
  499. this.close();
  500. }
  501. }
  502. },{
  503. "text": this.designer.lp.cancel,
  504. "action": function(){
  505. this.close();
  506. }
  507. }]
  508. });
  509. // var _self = this;
  510. // this.designer.confirm("infor", e, this.designer.lp.upgradeConfirm, {"html": this.designer.lp.upgradeInfor}, 520, 210, function(){
  511. // var checkbox = this.content.getElement("input");
  512. // var enable = (!!checkbox && checkbox.get("checked"));
  513. // _self.doSaveNewEdition(enable);
  514. // this.close();
  515. // }, function(){
  516. // this.close();
  517. // });
  518. }
  519. },
  520. doSaveNewEdition: function(enable, description){
  521. debugger;
  522. var process = Object.clone(this.process);
  523. process.editionDes = description;
  524. var oldIds = [];
  525. oldIds.push(process.id);
  526. if (process.begin) oldIds.push(process.begin.id);
  527. if (process.endList) process.endList.each(function(a){oldIds.push(a.id);});
  528. if (process.agentList) process.agentList.each(function(a){oldIds.push(a.id);});
  529. if (process.manualList) process.manualList.each(function(a){oldIds.push(a.id);});
  530. if (process.conditionList) process.conditionList.each(function(a){oldIds.push(a.id);});
  531. if (process.choiceList) process.choiceList.each(function(a){oldIds.push(a.id);});
  532. if (process.parallelList) process.parallelList.each(function(a){oldIds.push(a.id);});
  533. if (process.splitList) process.splitList.each(function(a){oldIds.push(a.id);});
  534. if (process.mergeList) process.mergeList.each(function(a){oldIds.push(a.id);});
  535. if (process.embedList) process.embedList.each(function(a){oldIds.push(a.id);});
  536. if (process.invokeList) process.invokeList.each(function(a){oldIds.push(a.id);});
  537. if (process.cancelList) process.cancelList.each(function(a){oldIds.push(a.id);});
  538. if (process.delayList) process.delayList.each(function(a){oldIds.push(a.id);});
  539. if (process.messageList) process.messageList.each(function(a){oldIds.push(a.id);});
  540. if (process.serviceList) process.serviceList.each(function(a){oldIds.push(a.id);});
  541. if (process.routeList) process.routeList.each(function(a){oldIds.push(a.id);});
  542. var actions = o2.Actions.load("x_processplatform_assemble_designer");
  543. this.designer.actions.getId(oldIds.length, function(ids) {
  544. var checkUUIDs = ids.data;
  545. var processStr = JSON.encode(process);
  546. oldIds.each(function(oid, i){
  547. var reg = new RegExp(oid, "ig");
  548. processStr = processStr.replace(reg, checkUUIDs[i].id);
  549. }.bind(this));
  550. process = JSON.decode(processStr);
  551. actions.ProcessAction.upgrade(this.process.id, process, function(json){
  552. var processId = json.data.id;
  553. if (enable){
  554. actions.ProcessAction.enableProcess(processId, function(processJson){
  555. actions.ProcessAction.get(processId, function(processJson){
  556. this.reload(processJson.data);
  557. }.bind(this))
  558. }.bind(this))
  559. }else{
  560. actions.ProcessAction.get(processId, function(processJson){
  561. this.reload(processJson.data);
  562. }.bind(this))
  563. }
  564. }.bind(this));
  565. }.bind(this));
  566. },
  567. listEdition: function(){
  568. if (this.process.edition){
  569. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.EditionList", function(){
  570. var list = new MWF.xApplication.process.ProcessDesigner.widget.EditionList(this.process.application, this.process.edition, this);
  571. list.load();
  572. }.bind(this));
  573. // o2.Actions.load("x_processplatform_assemble_designer").ProcessAction.listEdition(this.process.application, this.process.edition, function(json){
  574. // var editionList = json.data;
  575. // this.listEditionDlg(json.data);
  576. // }.bind(this));
  577. }else{
  578. this.designer.notice("infor", this.designer.lp.save_process);
  579. }
  580. },
  581. listEditionDlg: function(editionList){
  582. //var node = new Element("div", )
  583. },
  584. switchGrid: function(item){
  585. if (this.isGrid){
  586. this.hideGrid();
  587. }else{
  588. this.showGrid();
  589. }
  590. },
  591. showGrid: function(){
  592. this.designer.paperNode.setStyle("background-image", "url("+MWF.defaultPath+"/process/ProcessChart/$Process/"+this.options.style+"/griddingbg.gif)");
  593. // if (this.GridSet){
  594. // this.GridSet.show();
  595. // }else{
  596. // var paperSize = $(this.paper.canvas).getParent().getSize();
  597. // this.GridSet = this.paper.set();
  598. // for (var i=20; i<paperSize.x; i=i+20){
  599. // var lineV = this.paper.path("M"+i+",0L"+i+","+paperSize.y).attr({
  600. // "stroke": "#ccc",
  601. // "stroke-dasharray": ".",
  602. // "stroke-width": 1
  603. // });
  604. // lineV.toBack();
  605. // this.GridSet.push(lineV);
  606. // }
  607. // for (var j=20; j<paperSize.y; j=j+20){
  608. // var lineL = this.paper.path("M0,"+j+"L"+paperSize.x+","+j).attr({
  609. // "stroke": "#ccc",
  610. // "stroke-dasharray": ".",
  611. // "stroke-width": 1
  612. // });
  613. // lineL.toBack();
  614. // this.GridSet.push(lineL);
  615. // }
  616. // }
  617. this.isGrid = true;
  618. },
  619. hideGrid: function(){
  620. this.designer.paperNode.setStyle("background-image", "");
  621. // if (this.GridSet){
  622. // this.GridSet.hide();
  623. // }
  624. this.isGrid = false;
  625. },
  626. getPointElement: function(x, y){
  627. var els = this.paper.getElementsByPoint(x, y);
  628. var bindObject = null;
  629. var bindType = "none";
  630. if (els.length){
  631. for (var i=0; i<els.length; i++){
  632. var bind = els[i].data("bind");
  633. if (bind){
  634. if (instanceOf(bind, MWF.APPPD.Activity)){
  635. bindObject = bind;
  636. bindType = "activity";
  637. break;
  638. }
  639. if (instanceOf(bind, MWF.APPPD.Route)){
  640. bindObject = bind;
  641. bindType = "route";
  642. }
  643. };
  644. }
  645. }
  646. return {"bind": bindObject, "type": bindType};
  647. },
  648. // loadProcessDecisions: function(){
  649. // if (this.process.decisionList){
  650. // this.process.decisionList.each(function(d){
  651. // this.decisionDatas[d.id] = d;
  652. // }.bind(this));
  653. // }
  654. // },
  655. loadActivityRoutes: function(){
  656. this.activitys.each(function(activity){
  657. activity.loadRoutes();
  658. });
  659. },
  660. // loadActivityDecisions: function(){
  661. // if (this.begin) this.begin.loadDecisions();
  662. // for (a in this.ends){
  663. // this.ends[a].loadDecisions();
  664. // };
  665. // for (a in this.manuals){
  666. // this.manuals[a].loadDecisions();
  667. // };
  668. // for (a in this.autos){
  669. // this.autos[a].loadDecisions();
  670. // };
  671. // for (a in this.conditions){
  672. // this.conditions[a].loadDecisions();
  673. // };
  674. // for (a in this.embeds){
  675. // this.embeds[a].loadDecisions();
  676. // };
  677. // for (a in this.invokes){
  678. // this.invokes[a].loadDecisions();
  679. // };
  680. // },
  681. loadProcessRoutes: function(){
  682. this.process.routeList.each(function(item){
  683. this.routes[item.id] = new MWF.APPPD.Route(item, this);
  684. this.routeDatas[item.id] = item;
  685. // this.routes[item.id].load();
  686. }.bind(this));
  687. },
  688. createPropertyPanel: function(){
  689. if (!this.options.isView){
  690. this.panel = new MWF.APPPD.Process.Panel(this);
  691. this.panel.load();
  692. }
  693. },
  694. loadedActivitys: function(callback){
  695. if (this.loadedBegin && this.loadedEnds && this.loadedCancels && this.loadedConditions && this.loadedChoices && this.loadedSplits && this.loadedParallels && this.loadedMerges && this.loadedManuals && this.loadedEmbeds && this.loadedDelays && this.loadedInvokes && this.loadedServices && this.loadedAgents && this.loadedMessages){
  696. if (callback) callback();
  697. }
  698. },
  699. loadProcessActivitys: function(callback){
  700. this.loadBegin(function(){this.loadedBegin = true; this.loadedActivitys(callback);}.bind(this));
  701. this.loadEndList(function(){this.loadedEnds = true; this.loadedActivitys(callback);}.bind(this));
  702. this.loadCancelList(function(){this.loadedCancels = true; this.loadedActivitys(callback);}.bind(this));
  703. this.loadManualList(function(){this.loadedManuals = true; this.loadedActivitys(callback);}.bind(this));
  704. this.loadConditionList(function(){this.loadedConditions = true; this.loadedActivitys(callback);}.bind(this));
  705. this.loadChoiceList(function(){this.loadedChoices = true; this.loadedActivitys(callback);}.bind(this));
  706. this.loadSplitList(function(){this.loadedSplits = true; this.loadedActivitys(callback);}.bind(this));
  707. this.loadParallelList(function(){this.loadedParallels = true; this.loadedActivitys(callback);}.bind(this));
  708. this.loadMergeList(function(){this.loadedMerges = true; this.loadedActivitys(callback);}.bind(this));
  709. this.loadEmbedList(function(){this.loadedEmbeds = true; this.loadedActivitys(callback);}.bind(this));
  710. this.loadDelayList(function(){this.loadedDelays = true; this.loadedActivitys(callback);}.bind(this));
  711. this.loadInvokeList(function(){this.loadedInvokes = true; this.loadedActivitys(callback);}.bind(this));
  712. this.loadServiceList(function(){this.loadedServices = true; this.loadedActivitys(callback);}.bind(this));
  713. this.loadAgentList(function(){this.loadedAgents = true; this.loadedActivitys(callback);}.bind(this));
  714. this.loadMessageList(function(){this.loadedMessages = true; this.loadedActivitys(callback);}.bind(this));
  715. },
  716. loadBegin: function(callback){
  717. var data = this.process["begin"];
  718. if (data){
  719. this.begin = new MWF.APPPD.Activity.Begin(data, this);
  720. this.begin.load(callback);
  721. }else{
  722. if (callback) callback();;
  723. }
  724. this.activitys.push(this.begin);
  725. },
  726. loadEndList: function(callback){
  727. this.loadActivitys("End", "endList", this.ends, callback);
  728. },
  729. loadCancelList: function(callback){
  730. this.loadActivitys("Cancel", "cancelList", this.cancels, callback);
  731. },
  732. loadManualList: function(callback){
  733. this.loadActivitys("Manual", "manualList", this.manuals, callback);
  734. },
  735. loadConditionList: function(callback){
  736. this.loadActivitys("Condition", "conditionList", this.conditions, callback);
  737. },
  738. loadChoiceList: function(callback){
  739. this.loadActivitys("Choice", "choiceList", this.choices, callback);
  740. },
  741. loadSplitList: function(callback){
  742. this.loadActivitys("Split", "splitList", this.splits, callback);
  743. },
  744. loadParallelList: function(callback){
  745. this.loadActivitys("Parallel", "parallelList", this.parallels, callback);
  746. },
  747. loadMergeList: function(callback){
  748. this.loadActivitys("Merge", "mergeList", this.merges, callback);
  749. },
  750. loadEmbedList: function(callback){
  751. this.loadActivitys("Embed", "embedList", this.embeds, callback);
  752. },
  753. loadDelayList: function(callback){
  754. this.loadActivitys("Delay", "delayList", this.delays, callback);
  755. },
  756. loadInvokeList: function(callback){
  757. this.loadActivitys("Invoke", "invokeList", this.invokes, callback);
  758. },
  759. loadServiceList: function(callback){
  760. this.loadActivitys("Service", "serviceList", this.services, callback);
  761. },
  762. loadAgentList: function(callback){
  763. this.loadActivitys("Agent", "agentList", this.agents, callback);
  764. },
  765. loadMessageList: function(callback){
  766. this.loadActivitys("Message", "messageList", this.messages, callback);
  767. },
  768. loadActivitys: function(c, p, children, callback){
  769. var datas = this.process[p];
  770. if (datas){
  771. var count = datas.length;
  772. var loadedCount = 0;
  773. if (count){
  774. datas.each(function(data){
  775. this.loadActivity(c, data, children, function(){
  776. loadedCount++;
  777. if (loadedCount==count){
  778. if (callback) callback();
  779. }
  780. }.bind(this));
  781. }.bind(this));
  782. }else{
  783. if (callback) callback();
  784. }
  785. }else{
  786. if (callback) callback();
  787. }
  788. },
  789. loadActivity: function(c, data, children, callback){
  790. activity = new MWF.APPPD.Activity[c](data, this);
  791. activity.load(callback);
  792. if (c==="begin"){
  793. this.begin = activity;
  794. }else{
  795. children[data.id] = activity;
  796. }
  797. this.activitys.push(activity);
  798. },
  799. destroy: function(){
  800. this.paper.remove();
  801. },
  802. checkActivityEmptyRouteList: function(activitys){
  803. if (activitys && activitys.length){
  804. activitys.each(function(a){
  805. if (a.routeList) a.routeList = a.routeList.filter(function(n){return !!n;});
  806. });
  807. }
  808. },
  809. checkEmptyRouteList: function(){
  810. this.checkActivityEmptyRouteList(this.process.endList);
  811. this.checkActivityEmptyRouteList(this.process.cancelList);
  812. this.checkActivityEmptyRouteList(this.process.manualList);
  813. this.checkActivityEmptyRouteList(this.process.conditionList);
  814. this.checkActivityEmptyRouteList(this.process.choiceList);
  815. this.checkActivityEmptyRouteList(this.process.splitList);
  816. this.checkActivityEmptyRouteList(this.process.parallelList);
  817. this.checkActivityEmptyRouteList(this.process.mergeList);
  818. this.checkActivityEmptyRouteList(this.process.embedList);
  819. this.checkActivityEmptyRouteList(this.process.delayList);
  820. this.checkActivityEmptyRouteList(this.process.invokeList);
  821. this.checkActivityEmptyRouteList(this.process.serviceList);
  822. this.checkActivityEmptyRouteList(this.process.agentList);
  823. this.checkActivityEmptyRouteList(this.process.messageList);
  824. },
  825. save: function(callback){
  826. if (!this.isSave){
  827. this.isSave = true;
  828. //check empty routeList
  829. this.checkEmptyRouteList();
  830. var reload = !!this.process.isNewProcess;
  831. this.designer.actions.saveProcess(this.process, function(responseJSON){
  832. this.isSave = false;
  833. this.process.isNewProcess = false;
  834. this.designer.notice(MWF.APPPD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"} );
  835. this.isNewProcess = false;
  836. this.designer.options.id = responseJSON.data.id;
  837. if (reload){
  838. this.designer.actions.getProcess(responseJSON.data.id, function(json){
  839. this.reload(json.data);
  840. if (callback) callback();
  841. }.bind(this));
  842. }else{
  843. if (callback) callback();
  844. }
  845. }.bind(this), function(xhr, text, error){
  846. this.isSave = false;
  847. var errorText = error+":"+text;
  848. if (xhr) errorText = xhr.responseText;
  849. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  850. }.bind(this));
  851. }else{
  852. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  853. }
  854. //this.process
  855. },
  856. getActivityTemplate: function(callback){
  857. if (this.activityTemplates){
  858. if (callback) callback();
  859. }else{
  860. var activityTemplateUrl = this.path+"activity.json";
  861. var r = new Request.JSON({
  862. url: activityTemplateUrl,
  863. secure: false,
  864. async: false,
  865. method: "get",
  866. noCache: true,
  867. onSuccess: function(responseJSON, responseText){
  868. this.activityTemplates = responseJSON;
  869. if (callback) callback();
  870. }.bind(this),
  871. onError: function(text, error){
  872. alert(error);
  873. }
  874. });
  875. r.send();
  876. }
  877. },
  878. getRouteTemplates: function(callback){
  879. if (this.routeTemplates){
  880. if (callback) callback();
  881. }else{
  882. var routeTemplateUrl = this.path+"route.json";
  883. var r = new Request.JSON({
  884. url: routeTemplateUrl,
  885. secure: false,
  886. async: false,
  887. method: "get",
  888. noCache: true,
  889. onSuccess: function(responseJSON, responseText){
  890. this.routeTemplates = responseJSON;
  891. if (callback) callback();
  892. }.bind(this),
  893. onError: function(text, error){
  894. alert(error);
  895. }
  896. });
  897. r.send();
  898. }
  899. },
  900. createActivity: function(d, c, position){
  901. if (d=="begin"){
  902. if (this.begin){
  903. this.designer.notice(MWF.APPPD.LP.notice["one_begin"], "error", null, {x: "right", y:"top"});
  904. return false;
  905. }
  906. }
  907. var activity = null;
  908. this.getActivityTemplate(function(){
  909. var activityData = Object.clone(this.activityTemplates[d]);
  910. //MWF.require("MWF.widget.UUID", function(){
  911. //activityData.id = (new MWF.widget.UUID()).toString();
  912. this.designer.actions.getUUID(function(id){activityData.id = id;});
  913. activityData.process = this.process.id;
  914. activityData.createTime = new Date().format('db');
  915. activityData.updateTime = new Date().format('db');
  916. activityData.position = position.x+","+position.y;
  917. activity = new MWF.APPPD.Activity[c](activityData, this);
  918. activity.create(position);
  919. if (d=="begin"){
  920. this.begin = activity;
  921. this.process.begin = activityData;
  922. }else{
  923. this[d+"s"][activityData.id] = activity;
  924. if (!this.process[d+"List"]){
  925. this.process[d+"List"] = [];
  926. }
  927. this.process[d+"List"].push(activityData);
  928. }
  929. this.activitys.push(activity);
  930. // }.bind(this));
  931. }.bind(this));
  932. return activity;
  933. },
  934. createManualActivity: function(){
  935. this.createActivity("manual", "Manual");
  936. },
  937. createConditionActivity: function(){
  938. this.createActivity("condition", "Condition");
  939. },
  940. createAutoActivity: function(){
  941. this.createActivity("auto", "Auto");
  942. },
  943. createSplitActivity: function(){
  944. this.createActivity("split", "Split");
  945. },
  946. createMergeActivity: function(){
  947. this.createActivity("merge", "Merge");
  948. },
  949. createEmbedActivity: function(){
  950. this.createActivity("embed", "Embed");
  951. },
  952. createInvokesActivity: function(){
  953. this.createActivity("invoke", "Invoke");
  954. },
  955. createBeginActivity: function(){
  956. this.createActivity("begin", "Begin");
  957. },
  958. createEndActivity: function(){
  959. this.createActivity("end", "End");
  960. },
  961. createRoute: function(){
  962. if (!this.isCopyRoute && !this.isCreateRoute){
  963. this.getRouteTemplates(function(){
  964. var routerData = Object.clone(this.routeTemplates.route);
  965. //routerData.id = this.designer.actions.getUUID();
  966. this.designer.actions.getUUID(function(id){routerData.id = id;});
  967. routerData.process = this.process.id;
  968. routerData.createTime = new Date().format('db');
  969. routerData.updateTime = new Date().format('db');
  970. var route = new MWF.APPPD.Route(routerData, this);
  971. route.isBack = true;
  972. route.load();
  973. route.set.toBack();
  974. this.beginRouteCreate(route);
  975. }.bind(this));
  976. }
  977. },
  978. beginRouteCreate: function(route){
  979. this.isCreateRoute = true;
  980. this.currentCreateRoute = route;
  981. this.designer.setToolBardisabled("createRoute");
  982. //route.set.toFront();
  983. this.routeCreateFromMouseMoveBind = function(e){
  984. this.routeCreateFromMouseMove(e);
  985. }.bind(this);
  986. this.paper.canvas.addEvent("mousemove", this.routeCreateFromMouseMoveBind);
  987. },
  988. routeCreateFromMouseMove: function(e){
  989. //var x = e.event.layerX.toFloat();
  990. //var y = e.event.layerY.toFloat();
  991. var x = e.event.offsetX.toFloat();
  992. var y = e.event.offsetY.toFloat();
  993. var dx = x - this.currentCreateRoute.beginPoint.x-5;
  994. var dy = y - this.currentCreateRoute.beginPoint.y+5;
  995. this.currentCreateRoute.set.transform("t"+dx+","+dy);
  996. },
  997. routeCreateFromActivity: function(activity){
  998. this.paper.canvas.removeEvent("mousemove", this.routeCreateFromMouseMoveBind);
  999. var route = this.currentCreateRoute;
  1000. route.setActivity(null, activity);
  1001. route.reload();
  1002. this.routeCreateToMouseMoveBind = function(e){
  1003. this.routeCreateToMouseMove(e);
  1004. }.bind(this);
  1005. this.paper.canvas.addEvent("mousemove", this.routeCreateToMouseMoveBind);
  1006. },
  1007. routeCreateToMouseMove: function(e){
  1008. //var x = e.event.layerX.toFloat();
  1009. //var y = e.event.layerY.toFloat();
  1010. var x = e.event.offsetX.toFloat();
  1011. var y = e.event.offsetY.toFloat();
  1012. var route = this.currentCreateRoute;
  1013. route.tmpEndPoint = {"x": x-3, "y": y-3};
  1014. route.reload();
  1015. },
  1016. routeCreateToActivity: function(activity){
  1017. this.paper.canvas.removeEvent("mousemove", this.routeCreateToMouseMoveBind);
  1018. var route = this.currentCreateRoute;
  1019. route.tmpEndPoint = null;
  1020. route.tmpBeginPoint = null;
  1021. route.setActivity(activity, null);
  1022. route.isBack = false;
  1023. route.reload();
  1024. activity.shap.attr(activity.style.shap);
  1025. this.endRouteCreate();
  1026. },
  1027. endRouteCreate: function(){
  1028. var route = this.currentCreateRoute;
  1029. route.selected();
  1030. this.isCreateRoute = false;
  1031. this.currentCreateRoute = null;
  1032. route.setListItemData();
  1033. this.designer.setToolBardisabled("decision");
  1034. this.setNewRouteProcessData(route);
  1035. },
  1036. setNewRouteProcessData: function(route){
  1037. this.routes[route.data.id] = route;
  1038. this.process.routeList.push(route.data);
  1039. route.fromActivity.setRouteData(route.data.id);
  1040. // if (!route.fromActivity.data.routeList) route.fromActivity.data.routeList = [];
  1041. // route.fromActivity.data.routeList.push(route.data.id);
  1042. route.data.activity = route.toActivity.data.id;
  1043. route.data.activityType = route.toActivity.type;
  1044. },
  1045. routeCreateCancel: function(){
  1046. var route = this.currentCreateRoute;
  1047. if (route.fromActivity){
  1048. route.fromActivity.routes.erase(route);
  1049. }
  1050. route.destroy();
  1051. delete route;
  1052. this.isCreateRoute = false;
  1053. this.currentCreateRoute = null;
  1054. if (this.routeCreateFromMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeCreateFromMouseMoveBind);
  1055. if (this.routeCreateToMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeCreateToMouseMoveBind);
  1056. },
  1057. checkCreateRoute: function(e){
  1058. if (this.isCreateRoute || this.isCopyRoute){
  1059. if (e.rightClick){
  1060. if (this.isCreateRoute){
  1061. this.routeCreateCancel();
  1062. }
  1063. if (this.isCopyRoute){
  1064. this.routeAddCancel();
  1065. }
  1066. }
  1067. if (this.menu) this.menu.pause(1);
  1068. }
  1069. },
  1070. clearSelected: function(){
  1071. this.begin.unSelectActivity();
  1072. for (a in this.ends) this.ends[a].unSelected();
  1073. for (a in this.conditions) this.conditions[a].unSelected();
  1074. for (a in this.autos) this.autos[a].unSelected();
  1075. for (a in this.manuals) this.manuals[a].unSelected();
  1076. for (a in this.embeds) this.embeds[a].unSelected();
  1077. for (a in this.invokes) this.invokes[a].unSelected();
  1078. },
  1079. copyRoute: function(route){
  1080. if (!this.isCopyRoute && !this.isCreateRoute){
  1081. var newRouteData = Object.clone(route.data);
  1082. //newRouteData.id = Raphael.createUUID();
  1083. //newRouteData.id = this.designer.actions.getUUID();
  1084. this.designer.actions.getUUID(function(id){newRouteData.id = id;});
  1085. var route = new MWF.APPPD.Route(newRouteData, this);
  1086. route.load();
  1087. route.isBack = true;
  1088. this.isCopyRoute = true;
  1089. this.currentCopyRoute = route;
  1090. this.beginRouteCopy(route);
  1091. }
  1092. },
  1093. beginRouteCopy: function(route){
  1094. this.routeCopyMouseMoveBind = function(e){
  1095. this.copyRouteMouseMove(e, route);
  1096. }.bind(this);
  1097. this.paper.canvas.addEvent("mousemove", this.routeCopyMouseMoveBind);
  1098. },
  1099. copyRouteMouseMove: function(e, route){
  1100. route.tmpBeginPoint = {"x": e.event.offsetX-5, "y": e.event.offsetY-5};
  1101. route.reload();
  1102. },
  1103. routeAddFromActivity: function(activity){
  1104. var route = this.currentCopyRoute;
  1105. this.paper.canvas.removeEvent("mousemove", this.routeCopyMouseMoveBind);
  1106. route.setActivity(null, activity);
  1107. route.isBack = false;
  1108. route.reload();
  1109. activity.shap.attr(activity.style.shap);
  1110. this.endRouteCopy();
  1111. },
  1112. endRouteCopy: function(){
  1113. var route = this.currentCopyRoute;
  1114. route.selected();
  1115. this.isCopyRoute = false;
  1116. this.currentCopyRoute = null;
  1117. route.setListItemData();
  1118. this.designer.setToolBardisabled("decision");
  1119. this.setCopyRouteProcessData(route);
  1120. },
  1121. routeAddCancel: function(){
  1122. var route = this.currentCopyRoute;
  1123. route.destroy();
  1124. delete route;
  1125. this.isCopyRoute = false;
  1126. this.currentCopyRoute = null;
  1127. if (this.routeAddMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeAddMouseMoveBind);
  1128. },
  1129. setCopyRouteProcessData: function(route){
  1130. this.process.routeList.push(route.data);
  1131. route.fromActivity.setRouteData(route.data.id);
  1132. // if (!route.fromActivity.data.routeList) route.fromActivity.data.routeList = [];
  1133. // route.fromActivity.data.routeList.push(route.data.id);
  1134. this.routeDatas[route.data.id] = route.data;
  1135. },
  1136. deleteRoute: function(e, route){
  1137. var _self = this;
  1138. this.designer.shortcut = false;
  1139. this.designer.confirm("warn", e, MWF.APPPD.LP.notice.deleteRouteTitle, MWF.APPPD.LP.notice.deleteRoute, 300, 120, function(){
  1140. route.destroy();
  1141. delete route;
  1142. _self.designer.shortcut = true;
  1143. this.close();
  1144. }, function(){
  1145. _self.designer.shortcut = true;
  1146. this.close();
  1147. }, null);
  1148. },
  1149. copyActivity: function(activity){
  1150. var activityData = Object.clone(activity.data);
  1151. var type = activity.type;
  1152. var c = type.capitalize();
  1153. //activityData.id = this.designer.actions.getUUID();
  1154. this.designer.actions.getUUID(function(id){activityData.id = id;});
  1155. activityData.process = this.process.id;
  1156. activity = new MWF.APPPD.Activity[c](activityData, this);
  1157. activity.create();
  1158. activity.selected();
  1159. if (type=="begin"){
  1160. this.begin = activity;
  1161. this.process.begin = activityData;
  1162. }else{
  1163. this[type+"s"][activityData.id] = activity;
  1164. if (!this.process[type+"List"]){
  1165. this.process[type+"List"] = [];
  1166. }
  1167. this.process[type+"List"].push(activityData);
  1168. }
  1169. },
  1170. deleteActivity: function(e, activity){
  1171. var _self = this;
  1172. this.designer.shortcut = false;
  1173. this.designer.confirm("warn", e, MWF.APPPD.LP.notice.deleteActivityTitle, MWF.APPPD.LP.notice.deleteActivity, 300, 120, function(){
  1174. activity.destroy();
  1175. delete activity;
  1176. _self.designer.shortcut = true;
  1177. this.close();
  1178. }, function(){
  1179. _self.designer.shortcut = true;
  1180. this.close();
  1181. }, null);
  1182. },
  1183. explode: function(){
  1184. // this._getFormData();
  1185. MWF.require("MWF.widget.Base64", null, false);
  1186. var data = MWF.widget.Base64.encode(JSON.encode(this.process));
  1187. MWF.require("MWF.widget.Panel", function(){
  1188. var node = new Element("div");
  1189. //var size = this.designer.formNode.getSize();
  1190. var position = this.designer.paperNode.getPosition(this.designer.paperNode.getOffsetParent());
  1191. var textarea = new Element("textarea", {
  1192. "styles": {
  1193. "border": "1px solid #999",
  1194. "width": "770px",
  1195. "margin-left": "14px",
  1196. "margin-top": "14px",
  1197. "height": "580px"
  1198. },
  1199. "text": JSON.encode(this.process)
  1200. }).inject(node);
  1201. this.explodePanel = new MWF.widget.Panel(node, {
  1202. "style": "form",
  1203. "isResize": false,
  1204. "isMax": false,
  1205. "title": "",
  1206. "width": 800,
  1207. "height": 660,
  1208. "top": position.y,
  1209. "left": position.x+3,
  1210. "isExpand": false,
  1211. "target": this.designer.node
  1212. });
  1213. this.explodePanel.load();
  1214. }.bind(this));
  1215. }
  1216. });
  1217. MWF.xApplication.process.ProcessDesigner.Process.Panel = new Class({
  1218. initialize: function(process){
  1219. this.process = process;
  1220. this.width = 370;
  1221. this.top = 0;
  1222. var paperSize = this.process.designer.paperNode.getSize();
  1223. this.left = (paperSize.x.toFloat())-376;
  1224. this.height = (paperSize.y.toFloat())-6;
  1225. this.stopParseJson = false;
  1226. },
  1227. load: function(){
  1228. this.panelNode = new Element("div");
  1229. this.createModuleListTab();
  1230. this.createPropertyTab();
  1231. this.createPanelResizeNode();
  1232. this.moduleTabContent.inject(this.panelNode);
  1233. this.panelResizeNode.inject(this.panelNode);
  1234. this.propertyTabContent.inject(this.panelNode);
  1235. MWF.require("MWF.widget.Panel", function(){
  1236. this.modulePanel = new MWF.widget.Panel(this.panelNode, {
  1237. "title": MWF.APPPD.LP.property,
  1238. "isClose": false,
  1239. "target": this.process.designer.paperNode,
  1240. "height": this.height,
  1241. "width": this.width,
  1242. "left": this.left,
  1243. "top": this.top,
  1244. "transition": Fx.Transitions.linear.easeIn,
  1245. "transitionOut": Fx.Transitions.linear.easeOut,
  1246. "duration": 100,
  1247. "onResize": function(){
  1248. this.setPanelSize(this.panelModulePercent);
  1249. }.bind(this)
  1250. });
  1251. this.modulePanel.load();
  1252. this.setPanelSize(this.panelModulePercent);
  1253. }.bind(this));
  1254. },
  1255. setPanelSize: function(percent){
  1256. var contentSize = this.modulePanel.content.getSize();
  1257. var resizeSize = this.panelResizeNode.getSize();
  1258. var resizeMarginTop = this.panelResizeNode.getStyle("margin-top");
  1259. var resizeMarginBottom = this.panelResizeNode.getStyle("margin-bottom");
  1260. var useHeight = (contentSize.y.toFloat()) - (resizeSize.y.toFloat()) - (resizeMarginTop.toFloat()) - (resizeMarginBottom.toFloat());
  1261. var p = percent;
  1262. if (!p) p = 0.3;
  1263. var moduleHeight = useHeight*p;
  1264. var propertyHeight = useHeight - moduleHeight;
  1265. this.moduleListContent.setStyle("height", moduleHeight);
  1266. if (!this.propertyPanel) this.propertyListContent.setStyle("height", propertyHeight);
  1267. var moduleListTabSize = this.moduleListTab.tabNodeContainer.getSize();
  1268. this.moduleListTab.pages.each(function(page){
  1269. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1270. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1271. var tabContentNodeAreaHeight = moduleHeight - topMargin - bottomMargin - moduleListTabSize.y.toFloat()-2;
  1272. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1273. }.bind(this));
  1274. if (!this.propertyPanel) {
  1275. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1276. this.propertyListTab.pages.each(function(page){
  1277. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1278. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1279. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1280. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1281. }.bind(this));
  1282. }
  1283. // var contentNodeContainerHeight = moduleHeight - moduleListTabSize.y.toFloat()-2;
  1284. // this.moduleListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1285. //
  1286. // contentNodeContainerHeight = propertyHeight - propertyListTabSize.y.toFloat()-2;
  1287. // this.propertyListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1288. if (this.jsonStringConfirmNode)this.setJsonStringConfirmNodePosition();
  1289. },
  1290. createPanelResizeNode: function(){
  1291. this.panelResizeNode = new Element("div", {
  1292. "styles": this.process.css.panelResizeNode
  1293. });
  1294. this.panelResizeNode.addEvent("mousedown", function(e){
  1295. this.beginPanelResize(e);
  1296. }.bind(this));
  1297. },
  1298. beginPanelResize: function(){
  1299. this.panelResizeMouseMoveBind = function(e){
  1300. this.panelResize(e);
  1301. }.bind(this);
  1302. this.panelResizeMouseUpBind = function(){
  1303. $(document.body).removeEvent("selectstart",this.panelResizeSelecttBind);
  1304. $(document.body).removeEvent("mousemove",this.panelResizeMouseMoveBind);
  1305. $(document.body).removeEvent("mouseup",this.panelResizeMouseUpBind);
  1306. }.bind(this);
  1307. this.panelResizeSelecttBind = function(){
  1308. return false;
  1309. }.bind(this);
  1310. $(document.body).addEvent("selectstart",this.panelResizeSelecttBind);
  1311. $(document.body).addEvent("mousemove",this.panelResizeMouseMoveBind);
  1312. $(document.body).addEvent("mouseup",this.panelResizeMouseUpBind);
  1313. },
  1314. panelResize: function(e){
  1315. var y = e.event.pageY;
  1316. var modulePosition = this.moduleListContent.getPosition();
  1317. var moduleHeight = (y.toFloat()) - (modulePosition.y.toFloat());
  1318. if (moduleHeight<40) moduleHeight = 40;
  1319. var contentSize = this.modulePanel.content.getSize();
  1320. var resizeSize = this.panelResizeNode.getSize();
  1321. var resizeMarginTop = this.panelResizeNode.getStyle("margin-top");
  1322. var resizeMarginBottom = this.panelResizeNode.getStyle("margin-bottom");
  1323. var useHeight = (contentSize.y.toFloat()) - (resizeSize.y.toFloat()) - (resizeMarginTop.toFloat()) - (resizeMarginBottom.toFloat());
  1324. var propertyHeight = useHeight - moduleHeight;
  1325. if (propertyHeight<40){
  1326. propertyHeight = 40;
  1327. moduleHeight = useHeight - propertyHeight;
  1328. }
  1329. this.moduleListContent.setStyle("height", moduleHeight);
  1330. this.propertyListContent.setStyle("height", propertyHeight);
  1331. var moduleListTabSize = this.moduleListTab.tabNodeContainer.getSize();
  1332. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1333. this.moduleListTab.pages.each(function(page){
  1334. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1335. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1336. var tabContentNodeAreaHeight = moduleHeight - topMargin - bottomMargin - (moduleListTabSize.y.toFloat())-2;
  1337. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1338. }.bind(this));
  1339. this.propertyListTab.pages.each(function(page){
  1340. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1341. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1342. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1343. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1344. }.bind(this));
  1345. // var contentNodeContainerHeight = moduleHeight - moduleListTabSize.y.toFloat()-2;
  1346. // this.moduleListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1347. //
  1348. // contentNodeContainerHeight = propertyHeight - propertyListTabSize.y.toFloat()-2;
  1349. // this.propertyListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1350. if (this.jsonStringConfirmNode)this.setJsonStringConfirmNodePosition();
  1351. this.panelModulePercent = moduleHeight.toFloat()/useHeight.toFloat();
  1352. },
  1353. loadJson: function(json){
  1354. // MWF.require("MWF.widget.MaskNode", function(){
  1355. // this.jsonMarkNode = new MWF.widget.MaskNode(this.jsonObjectNode, {"zIndex": 30000});
  1356. // this.jsonMarkNode.load();
  1357. MWF.require("MWF.widget.JsonParse", function(){
  1358. this.jsonParse = new MWF.widget.JsonParse(json, this.jsonObjectNode, this.jsonStringNode);
  1359. this.jsonParse.load();
  1360. }.bind(this));
  1361. // this.jsonParse = new MWF.APPPD.Process.JsonParse(json, this.jsonObjectNode, this.jsonStringNode);
  1362. // window.setTimeout(function(){
  1363. // this.jsonParse.load();
  1364. // }.bind(this), 1);
  1365. // }.bind(this));
  1366. },
  1367. loadJsonString: function(json){
  1368. // o2.load("JSBeautifier_html", function(){
  1369. // htmlNode.set("text", html_beautify(copy.outerHTML, {"indent_size":1}));
  1370. // }.bind(this));
  1371. this.jsonStringNode.set("text", JSON.stringify(json,null,2));
  1372. MWF.widget.ace.load(function(){
  1373. COMMON.AjaxModule.loadDom("/o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  1374. var highlight = ace.require("ace/ext/static_highlight");
  1375. highlight(this.jsonStringNode, {mode: "ace/mode/json", theme: "ace/theme/tomorrow", "fontSize": 16});
  1376. }.bind(this));
  1377. }.bind(this));
  1378. },
  1379. clearJson: function(){
  1380. this.json = null;
  1381. this.jsonString = "";
  1382. this.jsonStringNode.set("text", "");
  1383. this.jsonObjectNode.empty();
  1384. if (this.jsonParse) this.jsonParse = null;
  1385. // if (this.jsonMarkNode) this.jsonMarkNode.hide();
  1386. },
  1387. createJsonStringNode: function(){
  1388. var jsonStringNode = new Element("div", {
  1389. // "readonly": true,
  1390. "styles": {
  1391. "width": "100%",
  1392. "height": "100%",
  1393. "overflow": "auto",
  1394. "border": "0px"
  1395. }
  1396. });
  1397. // jsonStringNode.set("text", this.jsonString);
  1398. return jsonStringNode;
  1399. },
  1400. createJsonObjectNode: function(){
  1401. this.jsonObjectNode = new Element("div", {
  1402. "styles": {
  1403. //"overflow": "hideen",
  1404. "margin-top": "0px",
  1405. "height": "auto"
  1406. }
  1407. });
  1408. // this.loadObjectTree();
  1409. return this.jsonObjectNode;
  1410. },
  1411. createJsonStringConfirmNode: function(){
  1412. this.jsonStringConfirmNode = new Element("div", {
  1413. "styles": {
  1414. "width": "20px",
  1415. "height": "20px",
  1416. "background-color": "#EEE",
  1417. "background": "url("+MWF.defaultPath+"/process/ProcessChart/$Process/"+this.process.options.style+"/checkmark.png"+") no-repeat center center",
  1418. "position": "absolute",
  1419. "cursor": "pointer",
  1420. "display": "none"
  1421. },
  1422. "events": {
  1423. "mouseover": function(){
  1424. this.store("flag", true);
  1425. },
  1426. "mouseout": function(){
  1427. this.store("flag", false);
  1428. },
  1429. "click": function(){
  1430. this.checkJsonStringAndReload();
  1431. }.bind(this)
  1432. }
  1433. }).inject(this.jsonStringNode, "after");
  1434. },
  1435. checkJsonStringAndReload: function(){
  1436. if (!this.process.selectedActivitys.length){
  1437. try {
  1438. var data = JSON.decode(this.jsonStringNode.value);
  1439. if (data){
  1440. if (this.process.currentSelected){
  1441. Object.copy(data, this.process.currentSelected.data);
  1442. this.process.currentSelected.redraw();
  1443. }else{
  1444. data.id = this.process.process.id;
  1445. data.processCategory = this.process.process.processCategory;
  1446. this.process.reload(data);
  1447. }
  1448. }
  1449. }catch(e){
  1450. this.designer.notice(e.message, "error", this.jsonStringNode.getParent(), {x: "left", y:"top"});
  1451. }
  1452. }
  1453. },
  1454. setJsonStringConfirmNodePosition: function(){
  1455. var p = this.jsonStringNode.getPosition(this.panelNode);
  1456. var size = this.panelNode.getSize();
  1457. this.jsonStringConfirmNode.setStyles({
  1458. "display": "block",
  1459. "top" : p.y+4,
  1460. "left" : size.x-26
  1461. });
  1462. },
  1463. createPropertyTab: function(){
  1464. this.propertyTabContent = new Element("div");
  1465. this.propertyListContent = new Element("div", {
  1466. "styles": this.process.css.propertyListContent
  1467. }).inject(this.propertyTabContent);
  1468. this.propertyListNode = new Element("div", {
  1469. "styles": this.process.css.propertyListNode
  1470. });
  1471. this.process.propertyListNode = this.propertyListNode;
  1472. this.jsonObjectNode = this.createJsonObjectNode();
  1473. this.jsonStringNode = this.createJsonStringNode();
  1474. this.jsonStringNode.addEvents({
  1475. "focus": function(){
  1476. if (!this.process.selectedActivitys.length){
  1477. if (!this.jsonStringConfirmNode) this.createJsonStringConfirmNode();
  1478. this.setJsonStringConfirmNodePosition();
  1479. }
  1480. }.bind(this),
  1481. "blur": function(e){
  1482. if (this.jsonStringConfirmNode){
  1483. if (!this.jsonStringConfirmNode.retrieve("flag")) this.jsonStringConfirmNode.setStyle("display", "none");
  1484. }
  1485. }.bind(this)
  1486. });
  1487. MWF.require("MWF.widget.Tab", function(){
  1488. this.propertyListTab = new MWF.widget.Tab(this.propertyListContent, {"style": "moduleList"});
  1489. this.propertyListTab.load();
  1490. this.propertyTabPage = this.propertyListTab.addTab(this.propertyListNode, MWF.APPPD.LP.property, false);
  1491. this.objectTabPage = this.propertyListTab.addTab(this.jsonObjectNode, "JSON", false);
  1492. this.stringTabPage = this.propertyListTab.addTab(this.jsonStringNode, "Text", false);
  1493. this.process.setScrollBar(this.propertyTabPage.contentNodeArea, "small", null, null);
  1494. this.process.setScrollBar(this.objectTabPage.contentNodeArea, "small", null, null);
  1495. this.process.setScrollBar(this.stringTabPage.contentNodeArea, "small", null, null);
  1496. this.objectTabPage.setOptions({
  1497. "onShow": function(){
  1498. this.loadJson(this.data);
  1499. }.bind(this),
  1500. "onHide": function(){
  1501. this.clearJson();
  1502. }.bind(this)
  1503. });
  1504. this.stringTabPage.setOptions({
  1505. "onShow": function(){
  1506. this.loadJsonString(this.data);
  1507. }.bind(this),
  1508. "onHide": function(){
  1509. this.clearJson();
  1510. }.bind(this)
  1511. });
  1512. this.propertyTabPage.showTab();
  1513. this.propertyListTab.tabNodeContainer.addEvent("mousedown", function(event){
  1514. //event.stop();
  1515. this.propertyTabMove(event);
  1516. }.bind(this));
  1517. // this.propertyDrag = new Drag(this.propertyTabContent, {
  1518. // "handle": this.propertyListTab.tabNodeContainer,
  1519. // "snap": 10,
  1520. // "onStart": function(el, e){
  1521. // }.bind(this)
  1522. // });
  1523. }.bind(this), false);
  1524. // this.propertyListContent.setStyle("height", 300);
  1525. },
  1526. propertyTabMove: function(event){
  1527. // var tmpContent = this.propertyListContent.clone().setStyles(this.propertyListContent.getCoordinates()).setStyles({
  1528. // "opacity": 0.7,
  1529. // "border": "1px dashed #CCC",
  1530. // "z-index": this.modulePanel.container.getStyle("z-index").toInt()+1,
  1531. // "position": "absolute"
  1532. // }).inject(this.process.designer.paperNode);
  1533. var size = this.propertyListContent.getSize();
  1534. var tmpContent = new Element("div", {
  1535. "styles": {
  1536. "opacity": 0.7,
  1537. "border": "1px dashed #CCC",
  1538. "z-index": this.modulePanel.container.getStyle("z-index").toInt()+1,
  1539. "width": size.x,
  1540. "height": size.y,
  1541. "background-color": "#EEE",
  1542. "position": "absolute"
  1543. }
  1544. }).inject(this.process.designer.paperNode);
  1545. tmpContent.position({
  1546. relativeTo: this.propertyListContent,
  1547. position: 'upperLeft',
  1548. edge: 'upperLeft'
  1549. });
  1550. var drag = new Drag.Move(tmpContent, {
  1551. "droppables": [this.process.designer.paperNode, this.panelNode],
  1552. "onEnter": function(dragging, inObj){
  1553. if (this.propertyPanel){
  1554. if (this.panelNode==inObj){
  1555. dragging.tween('border', "4px dashed #666");
  1556. }else{
  1557. dragging.tween('border', "1px dashed #CCC");
  1558. }
  1559. }else{
  1560. if (this.panelNode==inObj){
  1561. dragging.tween('border', "1px dashed #CCC");
  1562. }else{
  1563. dragging.tween('border', "4px dashed #666");
  1564. }
  1565. }
  1566. }.bind(this),
  1567. "onLeave": function(dragging, paper){
  1568. dragging.tween('border', "1px dashed #CCC");
  1569. },
  1570. "onDrop": function(dragging, inObj){
  1571. if (this.panelNode!=inObj){
  1572. this.propertyOut(dragging);
  1573. }else{
  1574. this.propertyIn();
  1575. }
  1576. dragging.destroy();
  1577. }.bind(this),
  1578. "onCancel": function(dragging){
  1579. dragging.destroy();
  1580. }
  1581. });
  1582. drag.start(event);
  1583. },
  1584. propertyOut: function(dragging){
  1585. if (!this.propertyPanel){
  1586. var coordinates = dragging.getCoordinates();
  1587. var p = this.process.designer.paperNode.getPosition();
  1588. var propertyPanelNode = new Element("div");
  1589. this.propertyListContent.inject(propertyPanelNode);
  1590. MWF.require("MWF.widget.Panel", function(){
  1591. this.propertyPanel = new MWF.widget.Panel(propertyPanelNode, {
  1592. "title": MWF.APPPD.LP.property,
  1593. "isClose": false,
  1594. "target": this.process.designer.paperNode,
  1595. "height": coordinates.height,
  1596. "width": coordinates.width,
  1597. "left": coordinates.left.toFloat() - p.x.toFloat(),
  1598. "top": coordinates.top.toFloat() - p.y.toFloat(),
  1599. "onResize": function(){
  1600. this.setPropertyPanelSize();
  1601. }.bind(this)
  1602. });
  1603. this.propertyPanel.load();
  1604. this.propertyOutSetHeight();
  1605. this.setPropertyPanelSize(this.panelModulePercent);
  1606. }.bind(this));
  1607. };
  1608. },
  1609. setPropertyPanelSize: function(){
  1610. var contentSize = this.propertyPanel.content.getSize();
  1611. var propertyHeight = contentSize.y;
  1612. this.propertyListContent.setStyle("height", propertyHeight);
  1613. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1614. this.propertyListTab.pages.each(function(page){
  1615. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1616. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1617. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1618. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1619. }.bind(this));
  1620. },
  1621. propertyOutSetHeight: function(){
  1622. this.panelResizeNode.setStyles(this.process.css.panelResizeNodeHide);
  1623. this.panelModulePercent = "1";
  1624. this.setPanelSize(this.panelModulePercent);
  1625. },
  1626. propertyIn: function(){
  1627. this.propertyListContent.inject(this.propertyTabContent);
  1628. if (this.propertyPanel) this.propertyPanel.closePanel();
  1629. this.propertyPanel = null;
  1630. this.propertyInSetHeight();
  1631. },
  1632. propertyInSetHeight: function(){
  1633. this.panelResizeNode.setStyles(this.process.css.panelResizeNode);
  1634. this.panelModulePercent = "0.3";
  1635. this.setPanelSize(this.panelModulePercent);
  1636. },
  1637. createModuleListTab: function(){
  1638. this.moduleTabContent = new Element("div");
  1639. this.moduleListContent = new Element("div", {
  1640. "styles": this.process.css.moduleListContent
  1641. }).inject(this.moduleTabContent);
  1642. this.activityListNode = new Element("div", {
  1643. "styles": this.process.css.activityListNode
  1644. });
  1645. this.process.activityListNode = this.activityListNode;
  1646. this.activityTable = new HtmlTable({
  1647. "properties": this.process.css.activityListTable
  1648. }).inject(this.activityListNode);
  1649. this.process.activityTable = this.activityTable;
  1650. this.routeListNode = new Element("div", {
  1651. "styles": this.process.css.routeListNode
  1652. });
  1653. this.process.routeListNode = this.routeListNode;
  1654. this.routeTable = new HtmlTable({
  1655. "properties": this.process.css.routeListTable
  1656. }).inject(this.routeListNode);
  1657. this.process.routeTable = this.routeTable;
  1658. MWF.require("MWF.widget.Tab", function(){
  1659. this.moduleListTab = new MWF.widget.Tab(this.moduleListContent, {"style": "moduleList"});
  1660. this.moduleListTab.load();
  1661. // this.process.setScrollBar(this.moduleListTab.contentNodeContainer, null, null, null);
  1662. var activityTabPage = this.moduleListTab.addTab(this.activityListNode, MWF.APPPD.LP.activity, false);
  1663. this.process.setScrollBar(activityTabPage.contentNodeArea, "small", null, null);
  1664. var routeTabPage = this.moduleListTab.addTab(this.routeListNode, MWF.APPPD.LP.route, false);
  1665. this.process.setScrollBar(routeTabPage.contentNodeArea, "small", null, null);
  1666. activityTabPage.showTab();
  1667. }.bind(this), false);
  1668. },
  1669. destroy: function(){
  1670. if (this.modulePanel) this.modulePanel.destroy();
  1671. if (this.propertyPanel) this.propertyPanel.destroy();
  1672. }
  1673. });
  1674. MWF.xApplication.process.ProcessDesigner.Process.Property = new Class({
  1675. Implements: [Options, Events],
  1676. Extends: MWF.APPPD.Property,
  1677. initialize: function(process, options){
  1678. this.setOptions(options);
  1679. this.process = process;
  1680. this.paper = this.process.paper;
  1681. this.data = process.process;
  1682. this.htmlPath = "/x_component_process_ProcessDesigner/$Process/process.html";
  1683. }
  1684. });
  1685. MWF.xApplication.process.ProcessDesigner.Process.JsonParse = new Class({
  1686. initialize: function(json, jsonObjectNode, jsonStringNode){
  1687. this.json = json;
  1688. this.jsonObjectNode = jsonObjectNode;
  1689. this.jsonStringNode = jsonStringNode;
  1690. this.stopParseJson = false;
  1691. },
  1692. load: function(){
  1693. this.jsonString = JSON.encode(this.json);
  1694. // this.jsonStringNode.set("text", JSON.format(this.json));
  1695. this.loadObjectTree();
  1696. },
  1697. loadObjectTree: function(){
  1698. if (this.objectTree){
  1699. this.objectTree.node.destroy();
  1700. this.objectTree = null;
  1701. }
  1702. MWF.require("MWF.widget.Tree", function(){
  1703. this.objectTree = new MWF.widget.Tree(this.jsonObjectNode, {"style": "jsonview"});
  1704. this.objectTree.load();
  1705. var str = this.parseJsonObject(0, this.objectTree, "", "JSON", this.json, true);
  1706. var jsonStr = str.substring(0, str.length-2);
  1707. if (!this.stopParseJson){
  1708. this.jsonStringNode.set("text", jsonStr);
  1709. }else{
  1710. this.stopParseJson = false;
  1711. }
  1712. }.bind(this));
  1713. },
  1714. parseJsonObject: function(level, treeNode, title, p, v, expand){
  1715. if (this.stopParseJson){
  1716. // alert(this.stopParseJson);
  1717. return false;
  1718. }
  1719. var o = {
  1720. "expand": expand,
  1721. "title": "",
  1722. "text": "",
  1723. "action": "",
  1724. "icon": ""
  1725. };
  1726. var tab = "";
  1727. for (var i=0; i<level; i++) tab+="\t";
  1728. //var title = title;
  1729. if (title) title="\""+title+"\": ";
  1730. var jsonStr = "";
  1731. var nextLevel = level+1;
  1732. switch (typeOf(v)){
  1733. case "object":
  1734. o.text = p;
  1735. o.icon = "object.png";
  1736. var node = treeNode.appendChild(o);
  1737. var jsonStrBegin = tab+title+"{";
  1738. var jsonStrEnd = tab+"}";
  1739. for (i in v){
  1740. jsonStr += this.parseJsonObject(nextLevel, node, i, i, v[i], false);
  1741. }
  1742. jsonStr = jsonStrBegin+"\n"+jsonStr.substring(0, jsonStr.length-2)+"\n"+jsonStrEnd+",\n";
  1743. break;
  1744. case "array":
  1745. o.text = p;
  1746. o.icon = "array.png";
  1747. var node = treeNode.appendChild(o);
  1748. var jsonStrBegin = tab+title+"[";
  1749. var jsonStrEnd = tab+"]";
  1750. v.each(function(item, idx){
  1751. jsonStr += this.parseJsonObject(nextLevel, node, "", "["+idx+"]", item, false);
  1752. }.bind(this));
  1753. jsonStr = jsonStrBegin+"\n"+jsonStr.substring(0, jsonStr.length-2)+"\n"+jsonStrEnd+",\n";
  1754. break;
  1755. case "string":
  1756. jsonStr += tab+title+"\""+v+"\",\n";
  1757. o.text = p + " : \""+v+"\"";
  1758. o.icon = "string.png";
  1759. //var node =
  1760. treeNode.appendChild(o);
  1761. break;
  1762. case "date":
  1763. jsonStr += tab+title+"\""+v+"\",\n";
  1764. o.text = p + " : \""+v+"\"";
  1765. o.icon = "string.png";
  1766. //var node =
  1767. treeNode.appendChild(o);
  1768. break;
  1769. default:
  1770. jsonStr += tab+title+v+",\n";
  1771. o.text = p + " : "+v;
  1772. o.icon = "string.png";
  1773. //var node =
  1774. treeNode.appendChild(o);
  1775. }
  1776. return jsonStr;
  1777. }
  1778. });