Process.js 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  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. this.json = null;
  1169. this.jsonString = "";
  1170. this.jsonStringNode.set("text", "");
  1171. this.jsonObjectNode.empty();
  1172. if (this.jsonParse) this.jsonParse = null;
  1173. // if (this.jsonMarkNode) this.jsonMarkNode.hide();
  1174. },
  1175. createJsonStringNode: function(){
  1176. var jsonStringNode = new Element("textarea", {
  1177. // "readonly": true,
  1178. "styles": {
  1179. "width": "99%",
  1180. "height": "99%",
  1181. "overflow": "auto",
  1182. "border": "0px"
  1183. }
  1184. });
  1185. // jsonStringNode.set("text", this.jsonString);
  1186. return jsonStringNode;
  1187. },
  1188. createJsonObjectNode: function(){
  1189. this.jsonObjectNode = new Element("div", {
  1190. "styles": {
  1191. //"overflow": "hideen",
  1192. "margin-top": "0px",
  1193. "height": "auto"
  1194. }
  1195. });
  1196. // this.loadObjectTree();
  1197. return this.jsonObjectNode;
  1198. },
  1199. createJsonStringConfirmNode: function(){
  1200. this.jsonStringConfirmNode = new Element("div", {
  1201. "styles": {
  1202. "width": "20px",
  1203. "height": "20px",
  1204. "background-color": "#EEE",
  1205. "background": "url("+MWF.defaultPath+"/process/ProcessChart/$Process/"+this.process.options.style+"/checkmark.png"+") no-repeat center center",
  1206. "position": "absolute",
  1207. "cursor": "pointer",
  1208. "display": "none"
  1209. },
  1210. "events": {
  1211. "mouseover": function(){
  1212. this.store("flag", true);
  1213. },
  1214. "mouseout": function(){
  1215. this.store("flag", false);
  1216. },
  1217. "click": function(){
  1218. this.checkJsonStringAndReload();
  1219. }.bind(this)
  1220. }
  1221. }).inject(this.jsonStringNode, "after");
  1222. },
  1223. checkJsonStringAndReload: function(){
  1224. if (!this.process.selectedActivitys.length){
  1225. try {
  1226. var data = JSON.decode(this.jsonStringNode.value);
  1227. if (data){
  1228. if (this.process.currentSelected){
  1229. Object.copy(data, this.process.currentSelected.data);
  1230. this.process.currentSelected.redraw();
  1231. }else{
  1232. data.id = this.process.process.id;
  1233. data.processCategory = this.process.process.processCategory;
  1234. this.process.reload(data);
  1235. }
  1236. }
  1237. }catch(e){
  1238. this.designer.notice(e.message, "error", this.jsonStringNode.getParent(), {x: "left", y:"top"});
  1239. }
  1240. }
  1241. },
  1242. setJsonStringConfirmNodePosition: function(){
  1243. var p = this.jsonStringNode.getPosition(this.panelNode);
  1244. var size = this.panelNode.getSize();
  1245. this.jsonStringConfirmNode.setStyles({
  1246. "display": "block",
  1247. "top" : p.y+4,
  1248. "left" : size.x-26
  1249. });
  1250. },
  1251. createPropertyTab: function(){
  1252. this.propertyTabContent = new Element("div");
  1253. this.propertyListContent = new Element("div", {
  1254. "styles": this.process.css.propertyListContent
  1255. }).inject(this.propertyTabContent);
  1256. this.propertyListNode = new Element("div", {
  1257. "styles": this.process.css.propertyListNode
  1258. });
  1259. this.process.propertyListNode = this.propertyListNode;
  1260. this.jsonObjectNode = this.createJsonObjectNode();
  1261. this.jsonStringNode = this.createJsonStringNode();
  1262. this.jsonStringNode.addEvents({
  1263. "focus": function(){
  1264. if (!this.process.selectedActivitys.length){
  1265. if (!this.jsonStringConfirmNode) this.createJsonStringConfirmNode();
  1266. this.setJsonStringConfirmNodePosition();
  1267. }
  1268. }.bind(this),
  1269. "blur": function(e){
  1270. if (this.jsonStringConfirmNode){
  1271. if (!this.jsonStringConfirmNode.retrieve("flag")) this.jsonStringConfirmNode.setStyle("display", "none");
  1272. }
  1273. }.bind(this)
  1274. });
  1275. MWF.require("MWF.widget.Tab", function(){
  1276. this.propertyListTab = new MWF.widget.Tab(this.propertyListContent, {"style": "moduleList"});
  1277. this.propertyListTab.load();
  1278. this.propertyTabPage = this.propertyListTab.addTab(this.propertyListNode, MWF.APPPD.LP.property, false);
  1279. this.objectTabPage = this.propertyListTab.addTab(this.jsonObjectNode, "JSON", false);
  1280. this.stringTabPage = this.propertyListTab.addTab(this.jsonStringNode, "Text", false);
  1281. this.process.setScrollBar(this.propertyTabPage.contentNodeArea, "small", null, null);
  1282. this.process.setScrollBar(this.objectTabPage.contentNodeArea, "small", null, null);
  1283. this.process.setScrollBar(this.stringTabPage.contentNodeArea, "small", null, null);
  1284. this.objectTabPage.setOptions({
  1285. "onShow": function(){
  1286. this.loadJson(this.data);
  1287. }.bind(this),
  1288. "onHide": function(){
  1289. this.clearJson();
  1290. }.bind(this)
  1291. });
  1292. this.stringTabPage.setOptions({
  1293. "onShow": function(){
  1294. this.loadJson(this.data);
  1295. }.bind(this),
  1296. "onHide": function(){
  1297. this.clearJson();
  1298. }.bind(this)
  1299. });
  1300. this.propertyTabPage.showTab();
  1301. this.propertyListTab.tabNodeContainer.addEvent("mousedown", function(event){
  1302. //event.stop();
  1303. this.propertyTabMove(event);
  1304. }.bind(this));
  1305. // this.propertyDrag = new Drag(this.propertyTabContent, {
  1306. // "handle": this.propertyListTab.tabNodeContainer,
  1307. // "snap": 10,
  1308. // "onStart": function(el, e){
  1309. // }.bind(this)
  1310. // });
  1311. }.bind(this), false);
  1312. // this.propertyListContent.setStyle("height", 300);
  1313. },
  1314. propertyTabMove: function(event){
  1315. // var tmpContent = this.propertyListContent.clone().setStyles(this.propertyListContent.getCoordinates()).setStyles({
  1316. // "opacity": 0.7,
  1317. // "border": "1px dashed #CCC",
  1318. // "z-index": this.modulePanel.container.getStyle("z-index").toInt()+1,
  1319. // "position": "absolute"
  1320. // }).inject(this.process.designer.paperNode);
  1321. var size = this.propertyListContent.getSize();
  1322. var tmpContent = new Element("div", {
  1323. "styles": {
  1324. "opacity": 0.7,
  1325. "border": "1px dashed #CCC",
  1326. "z-index": this.modulePanel.container.getStyle("z-index").toInt()+1,
  1327. "width": size.x,
  1328. "height": size.y,
  1329. "background-color": "#EEE",
  1330. "position": "absolute"
  1331. }
  1332. }).inject(this.process.designer.paperNode);
  1333. tmpContent.position({
  1334. relativeTo: this.propertyListContent,
  1335. position: 'upperLeft',
  1336. edge: 'upperLeft'
  1337. });
  1338. var drag = new Drag.Move(tmpContent, {
  1339. "droppables": [this.process.designer.paperNode, this.panelNode],
  1340. "onEnter": function(dragging, inObj){
  1341. if (this.propertyPanel){
  1342. if (this.panelNode==inObj){
  1343. dragging.tween('border', "4px dashed #666");
  1344. }else{
  1345. dragging.tween('border', "1px dashed #CCC");
  1346. }
  1347. }else{
  1348. if (this.panelNode==inObj){
  1349. dragging.tween('border', "1px dashed #CCC");
  1350. }else{
  1351. dragging.tween('border', "4px dashed #666");
  1352. }
  1353. }
  1354. }.bind(this),
  1355. "onLeave": function(dragging, paper){
  1356. dragging.tween('border', "1px dashed #CCC");
  1357. },
  1358. "onDrop": function(dragging, inObj){
  1359. if (this.panelNode!=inObj){
  1360. this.propertyOut(dragging);
  1361. }else{
  1362. this.propertyIn();
  1363. }
  1364. dragging.destroy();
  1365. }.bind(this),
  1366. "onCancel": function(dragging){
  1367. dragging.destroy();
  1368. }
  1369. });
  1370. drag.start(event);
  1371. },
  1372. propertyOut: function(dragging){
  1373. if (!this.propertyPanel){
  1374. var coordinates = dragging.getCoordinates();
  1375. var p = this.process.designer.paperNode.getPosition();
  1376. var propertyPanelNode = new Element("div");
  1377. this.propertyListContent.inject(propertyPanelNode);
  1378. MWF.require("MWF.widget.Panel", function(){
  1379. this.propertyPanel = new MWF.widget.Panel(propertyPanelNode, {
  1380. "title": MWF.APPPD.LP.property,
  1381. "isClose": false,
  1382. "target": this.process.designer.paperNode,
  1383. "height": coordinates.height,
  1384. "width": coordinates.width,
  1385. "left": coordinates.left.toFloat() - p.x.toFloat(),
  1386. "top": coordinates.top.toFloat() - p.y.toFloat(),
  1387. "onResize": function(){
  1388. this.setPropertyPanelSize();
  1389. }.bind(this)
  1390. });
  1391. this.propertyPanel.load();
  1392. this.propertyOutSetHeight();
  1393. this.setPropertyPanelSize(this.panelModulePercent);
  1394. }.bind(this));
  1395. };
  1396. },
  1397. setPropertyPanelSize: function(){
  1398. var contentSize = this.propertyPanel.content.getSize();
  1399. var propertyHeight = contentSize.y;
  1400. this.propertyListContent.setStyle("height", propertyHeight);
  1401. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1402. this.propertyListTab.pages.each(function(page){
  1403. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1404. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1405. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1406. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1407. }.bind(this));
  1408. },
  1409. propertyOutSetHeight: function(){
  1410. this.panelResizeNode.setStyles(this.process.css.panelResizeNodeHide);
  1411. this.panelModulePercent = "1";
  1412. this.setPanelSize(this.panelModulePercent);
  1413. },
  1414. propertyIn: function(){
  1415. this.propertyListContent.inject(this.propertyTabContent);
  1416. if (this.propertyPanel) this.propertyPanel.closePanel();
  1417. this.propertyPanel = null;
  1418. this.propertyInSetHeight();
  1419. },
  1420. propertyInSetHeight: function(){
  1421. this.panelResizeNode.setStyles(this.process.css.panelResizeNode);
  1422. this.panelModulePercent = "0.3";
  1423. this.setPanelSize(this.panelModulePercent);
  1424. },
  1425. createModuleListTab: function(){
  1426. this.moduleTabContent = new Element("div");
  1427. this.moduleListContent = new Element("div", {
  1428. "styles": this.process.css.moduleListContent
  1429. }).inject(this.moduleTabContent);
  1430. this.activityListNode = new Element("div", {
  1431. "styles": this.process.css.activityListNode
  1432. });
  1433. this.process.activityListNode = this.activityListNode;
  1434. this.activityTable = new HtmlTable({
  1435. "properties": this.process.css.activityListTable
  1436. }).inject(this.activityListNode);
  1437. this.process.activityTable = this.activityTable;
  1438. this.routeListNode = new Element("div", {
  1439. "styles": this.process.css.routeListNode
  1440. });
  1441. this.process.routeListNode = this.routeListNode;
  1442. this.routeTable = new HtmlTable({
  1443. "properties": this.process.css.routeListTable
  1444. }).inject(this.routeListNode);
  1445. this.process.routeTable = this.routeTable;
  1446. MWF.require("MWF.widget.Tab", function(){
  1447. this.moduleListTab = new MWF.widget.Tab(this.moduleListContent, {"style": "moduleList"});
  1448. this.moduleListTab.load();
  1449. // this.process.setScrollBar(this.moduleListTab.contentNodeContainer, null, null, null);
  1450. var activityTabPage = this.moduleListTab.addTab(this.activityListNode, MWF.APPPD.LP.activity, false);
  1451. this.process.setScrollBar(activityTabPage.contentNodeArea, "small", null, null);
  1452. var routeTabPage = this.moduleListTab.addTab(this.routeListNode, MWF.APPPD.LP.route, false);
  1453. this.process.setScrollBar(routeTabPage.contentNodeArea, "small", null, null);
  1454. activityTabPage.showTab();
  1455. }.bind(this), false);
  1456. },
  1457. destroy: function(){
  1458. if (this.modulePanel) this.modulePanel.destroy();
  1459. if (this.propertyPanel) this.propertyPanel.destroy();
  1460. }
  1461. });
  1462. MWF.xApplication.process.ProcessDesigner.Process.Property = new Class({
  1463. Implements: [Options, Events],
  1464. Extends: MWF.APPPD.Property,
  1465. initialize: function(process, options){
  1466. this.setOptions(options);
  1467. this.process = process;
  1468. this.paper = this.process.paper;
  1469. this.data = process.process;
  1470. this.htmlPath = "/x_component_process_ProcessDesigner/$Process/process.html";
  1471. }
  1472. });
  1473. MWF.xApplication.process.ProcessDesigner.Process.JsonParse = new Class({
  1474. initialize: function(json, jsonObjectNode, jsonStringNode){
  1475. this.json = json;
  1476. this.jsonObjectNode = jsonObjectNode;
  1477. this.jsonStringNode = jsonStringNode;
  1478. this.stopParseJson = false;
  1479. },
  1480. load: function(){
  1481. this.jsonString = JSON.encode(this.json);
  1482. // this.jsonStringNode.set("text", JSON.format(this.json));
  1483. this.loadObjectTree();
  1484. },
  1485. loadObjectTree: function(){
  1486. if (this.objectTree){
  1487. this.objectTree.node.destroy();
  1488. this.objectTree = null;
  1489. }
  1490. MWF.require("MWF.widget.Tree", function(){
  1491. this.objectTree = new MWF.widget.Tree(this.jsonObjectNode, {"style": "jsonview"});
  1492. this.objectTree.load();
  1493. var str = this.parseJsonObject(0, this.objectTree, "", "JSON", this.json, true);
  1494. var jsonStr = str.substring(0, str.length-2);
  1495. if (!this.stopParseJson){
  1496. this.jsonStringNode.set("text", jsonStr);
  1497. }else{
  1498. this.stopParseJson = false;
  1499. }
  1500. }.bind(this));
  1501. },
  1502. parseJsonObject: function(level, treeNode, title, p, v, expand){
  1503. if (this.stopParseJson){
  1504. // alert(this.stopParseJson);
  1505. return false;
  1506. }
  1507. var o = {
  1508. "expand": expand,
  1509. "title": "",
  1510. "text": "",
  1511. "action": "",
  1512. "icon": ""
  1513. };
  1514. var tab = "";
  1515. for (var i=0; i<level; i++) tab+="\t";
  1516. //var title = title;
  1517. if (title) title="\""+title+"\": ";
  1518. var jsonStr = "";
  1519. var nextLevel = level+1;
  1520. switch (typeOf(v)){
  1521. case "object":
  1522. o.text = p;
  1523. o.icon = "object.png";
  1524. var node = treeNode.appendChild(o);
  1525. var jsonStrBegin = tab+title+"{";
  1526. var jsonStrEnd = tab+"}";
  1527. for (i in v){
  1528. jsonStr += this.parseJsonObject(nextLevel, node, i, i, v[i], false);
  1529. }
  1530. jsonStr = jsonStrBegin+"\n"+jsonStr.substring(0, jsonStr.length-2)+"\n"+jsonStrEnd+",\n";
  1531. break;
  1532. case "array":
  1533. o.text = p;
  1534. o.icon = "array.png";
  1535. var node = treeNode.appendChild(o);
  1536. var jsonStrBegin = tab+title+"[";
  1537. var jsonStrEnd = tab+"]";
  1538. v.each(function(item, idx){
  1539. jsonStr += this.parseJsonObject(nextLevel, node, "", "["+idx+"]", item, false);
  1540. }.bind(this));
  1541. jsonStr = jsonStrBegin+"\n"+jsonStr.substring(0, jsonStr.length-2)+"\n"+jsonStrEnd+",\n";
  1542. break;
  1543. case "string":
  1544. jsonStr += tab+title+"\""+v+"\",\n";
  1545. o.text = p + " : \""+v+"\"";
  1546. o.icon = "string.png";
  1547. //var node =
  1548. treeNode.appendChild(o);
  1549. break;
  1550. case "date":
  1551. jsonStr += tab+title+"\""+v+"\",\n";
  1552. o.text = p + " : \""+v+"\"";
  1553. o.icon = "string.png";
  1554. //var node =
  1555. treeNode.appendChild(o);
  1556. break;
  1557. default:
  1558. jsonStr += tab+title+v+",\n";
  1559. o.text = p + " : "+v;
  1560. o.icon = "string.png";
  1561. //var node =
  1562. treeNode.appendChild(o);
  1563. }
  1564. return jsonStr;
  1565. }
  1566. });