Process.js 68 KB

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