Process.js 61 KB

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