Process.js 67 KB

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