Process.js 65 KB

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