Process.js 71 KB

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