Process.js 59 KB

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