Process.js 60 KB

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