Process.js 61 KB

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