Process.js 71 KB

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