Process.js 59 KB

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