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