Main.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. MWF.APPPD = MWF.xApplication.process.ProcessDesigner;
  2. MWF.APPPD.options = {
  3. "multitask": true,
  4. "executable": false
  5. };
  6. //MWF.xDesktop.requireApp("process.ProcessManager", "Actions.RestActions", null, false);
  7. MWF.require("MWF.widget.MWFRaphael", null, false);
  8. MWF.xApplication.process.ProcessDesigner.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "template": "process.json",
  14. "name": "process.ProcessDesigner",
  15. "icon": "icon.png",
  16. "title": MWF.APPPD.LP.title,
  17. "appTitle": MWF.APPPD.LP.title,
  18. "id": "",
  19. "tooltip": {
  20. "unCategory": MWF.APPPD.LP.unCategory
  21. },
  22. "actions": null,
  23. "category": null,
  24. "processData": null
  25. },
  26. onQueryLoad: function(){
  27. this.shortcut = true;
  28. if (this.status){
  29. this.options.id = this.status.id;
  30. }
  31. if (!this.options.id){
  32. this.options.desktopReload = false;
  33. this.options.title = this.options.title + "-"+MWF.APPPD.LP.newProcess;
  34. }
  35. this.actions = MWF.Actions.get("x_processplatform_assemble_designer");
  36. //this.actions = new MWF.xApplication.process.ProcessManager.Actions.RestActions();
  37. this.lp = MWF.xApplication.process.ProcessDesigner.LP;
  38. // this.processData = this.options.processData;
  39. },
  40. loadApplication: function(callback){
  41. this.gadgets = [];
  42. this.gadgetMode="all";
  43. this.gadgetDecrease = 0;
  44. this.createNode();
  45. if (!this.options.isRefresh){
  46. this.maxSize(function(){
  47. this.openProcess();
  48. }.bind(this));
  49. }else{
  50. this.openProcess();
  51. }
  52. this.addKeyboardEvents();
  53. if (callback) callback();
  54. },
  55. addKeyboardEvents: function(){
  56. this.addEvent("copy", function(){
  57. this.copyModule();
  58. }.bind(this));
  59. this.addEvent("paste", function(){
  60. this.pasteModule();
  61. }.bind(this));
  62. this.addEvent("keySave", function(e){
  63. this.keySave(e);
  64. }.bind(this));
  65. this.addEvent("keyDelete", function(e){
  66. this.keyDelete(e);
  67. }.bind(this));
  68. //this.addEvent("cut", function(){
  69. // this.cutModule();
  70. //}.bind(this));
  71. },
  72. keySave: function(e){
  73. if (this.shortcut) {
  74. if (this.process) this.saveProcess();
  75. e.preventDefault();
  76. }
  77. },
  78. keyDelete: function(e){
  79. if (this.shortcut) {
  80. if (this.process) {
  81. if (this.process.selectedActivitys.length) {
  82. } else if (this.process.currentSelected) {
  83. var p = this.content.getPosition();
  84. if (this.process.currentSelected.type) {
  85. var a = this.process.currentSelected;
  86. var e = {"event": {"x": a.center.x + p.x, "y": a.center.y + p.y}};
  87. this.process.deleteActivity(e, this.process.currentSelected);
  88. } else {
  89. var r = this.process.currentSelected;
  90. var e = {"event": {"x": r.beginPoint.x + p.x, "y": r.beginPoint.y + p.y}};
  91. this.process.deleteRoute(e, this.process.currentSelected);
  92. }
  93. }
  94. }
  95. }
  96. },
  97. copyModule: function(){
  98. if (this.shortcut) {
  99. if (this.process) {
  100. // if (this.process.isFocus){
  101. if (this.process.selectedActivitys.length) {
  102. var activitys = [];
  103. var routes = [];
  104. this.process.selectedActivitys.each(function (activity) {
  105. //if (activity.data.type.toLowerCase()!=="begin"){
  106. activitys.push(Object.clone(activity.data));
  107. activity.routes.each(function (route) {
  108. if (route.toActivity) {
  109. //if (this.process.selectedActivitys.indexOf(route.toActivity) != -1){
  110. routes.push(Object.clone(route.data));
  111. //}else{
  112. // activity.routes = null;
  113. //}
  114. } else {
  115. routes.push(Object.clone(route.data));
  116. }
  117. }.bind(this));
  118. //}
  119. //activity.routes = activity.routes.clean();
  120. }.bind(this));
  121. MWF.clipboard.data = {
  122. "type": "process",
  123. "data": {
  124. "activitys": activitys,
  125. "routes": routes
  126. }
  127. };
  128. } else if (this.process.currentSelected) {
  129. if (this.process.currentSelected.type) {
  130. //if (this.process.currentSelected.data.type.toLowerCase()!=="begin"){
  131. var data = Object.clone(this.process.currentSelected.data);
  132. MWF.clipboard.data = {
  133. "type": "process",
  134. "data": {
  135. "activitys": [data],
  136. "routes": []
  137. }
  138. };
  139. //}
  140. } else {
  141. MWF.clipboard.data = null;
  142. }
  143. }
  144. // }
  145. }
  146. }
  147. },
  148. pasteModuleError: function(bakData){
  149. this.notice(this.lp.notice.processCopyError, "error");
  150. this.process.reload(bakData);
  151. MWF.clipboard.data = null;
  152. },
  153. pasteModule: function(){
  154. if (this.process){
  155. // if (this.process.isFocus){
  156. if (MWF.clipboard.data){
  157. if (MWF.clipboard.data.type=="process"){
  158. var bakData = Object.clone(this.process.process);
  159. this.process.unSelectedAll();
  160. var activitys = MWF.clipboard.data.data.activitys;
  161. var routes = MWF.clipboard.data.data.routes;
  162. var checkUUIDs;
  163. this.actions.getId(activitys.length+routes.length, function(ids) {
  164. try {
  165. checkUUIDs = ids.data;
  166. var idReplace = {};
  167. var processId = this.process.process.id;
  168. activitys.each(function(d){
  169. var id = checkUUIDs.pop().id;
  170. idReplace[d.id] = id;
  171. d.id = id;
  172. d.process = processId;
  173. });
  174. routes.each(function(d){
  175. var id = checkUUIDs.pop().id;
  176. idReplace[d.id] = id;
  177. d.id = id;
  178. d.process = processId;
  179. d.activity = idReplace[d.activity];
  180. });
  181. activitys.each(function(d){
  182. if (d.route){
  183. d.route = idReplace[d.route];
  184. }
  185. if (d.routeList){
  186. d.routeList.each(function(r, i){
  187. d.routeList[i] = idReplace[r]
  188. });
  189. }
  190. });
  191. var loadRoutes = function(){
  192. try{
  193. routes.each(function(item){
  194. this.process.process.routeList.push(Object.clone(item));
  195. this.process.routes[item.id] = new MWF.APPPD.Route(item, this.process);
  196. this.process.routeDatas[item.id] = item;
  197. // this.routes[item.id].load();
  198. }.bind(this));
  199. activitys.each(function(d){
  200. //this.process[d.type+"s"][d.id].loadRoutes();
  201. (this.process[d.type] || this.process[d.type+"s"][d.id]).loadRoutes();
  202. if (activitys.length>1){
  203. (this.process[d.type] || this.process[d.type+"s"][d.id]).selectedMulti();
  204. }else{
  205. this.process[d.type+"s"][d.id].selected();
  206. }
  207. }.bind(this));
  208. routes.each(function(item){
  209. var route = this.process.routes[item.id];
  210. if (!route.loaded) route.load();
  211. }.bind(this));
  212. MWF.clipboard.data = null;
  213. }catch(e){
  214. this.pasteModuleError(bakData);
  215. }
  216. };
  217. var loadedCount = 0;
  218. activitys.each(function(activity){
  219. //if (activity.type.toLowerCase()!=="begin"){
  220. var data = Object.clone(activity);
  221. var type = data.type;
  222. if (type.toLowerCase()=="begin"){
  223. if (!this.process.begin){
  224. this.process.process.begin = data;
  225. this.process.loadBegin(function(){
  226. loadedCount++;
  227. if (loadedCount==activitys.length) loadRoutes.apply(this);
  228. }.bind(this));
  229. }else{
  230. //loadedCount++;
  231. activitys.erase(activity);
  232. if (loadedCount==activitys.length) loadRoutes.apply(this);
  233. }
  234. }else{
  235. if (!this.process.process[type+"List"]) this.process.process[type+"List"] = [];
  236. this.process.process[type+"List"].push(data);
  237. var c = type.capitalize();
  238. // if (type==="begin") {
  239. // if (!this.process.begin){
  240. // this.process.loadActivity(c, data, this.process.begin, function(){
  241. // loadedCount++;
  242. // if (loadedCount==activitys.length) loadRoutes.apply(this);
  243. // }.bind(this));
  244. // }
  245. // }else{
  246. this.process.loadActivity(c, data, this.process[type+"s"], function(){
  247. loadedCount++;
  248. if (loadedCount==activitys.length) loadRoutes.apply(this);
  249. }.bind(this));
  250. // }
  251. }
  252. // }
  253. }.bind(this));
  254. }catch(e){
  255. this.pasteModuleError(bakData)
  256. }
  257. }.bind(this));
  258. }
  259. }
  260. // }
  261. }
  262. },
  263. createNode: function(){
  264. this.content.setStyle("overflow", "hidden");
  265. this.node = new Element("div", {
  266. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  267. }).inject(this.content);
  268. },
  269. openProcess: function(){
  270. this.loadNodes();
  271. this.loadGadgets();
  272. this.loadToolbar(function(){
  273. this.resizePaper();
  274. this.addEvent("resize", function(){this.resizePaper();}.bind(this));
  275. this.getProcessData(function(){
  276. this.loadPaper();
  277. }.bind(this));
  278. }.bind(this));
  279. this.resizeNode();
  280. this.addEvent("resize", this.resizeNode.bind(this));
  281. },
  282. resizeNode: function(){
  283. var nodeSize = this.node.getSize();
  284. var titleSize = this.gadgetTitleNode.getSize();
  285. var titleMarginTop = this.gadgetTitleNode.getStyle("margin-top").toFloat();
  286. var titleMarginBottom = this.gadgetTitleNode.getStyle("margin-bottom").toFloat();
  287. var titlePaddingTop = this.gadgetTitleNode.getStyle("padding-top").toFloat();
  288. var titlePaddingBottom = this.gadgetTitleNode.getStyle("padding-bottom").toFloat();
  289. y = titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom;
  290. y = nodeSize.y-y;
  291. this.gadgetContentNode.setStyle("height", ""+y+"px");
  292. },
  293. getProcessData: function(callback){
  294. if (!this.options.id){
  295. this.loadNewProcessData(callback);
  296. }else{
  297. this.loadProcessData(callback);
  298. }
  299. },
  300. loadNewProcessData: function(callback){
  301. //MWF.getJSON(this.path+"process.json", {
  302. var url = "/x_component_process_ProcessDesigner/$Process/template/"+this.options.template;
  303. MWF.getJSON(url, {
  304. "onSuccess": function(obj){
  305. obj.id="";
  306. obj.isNewProcess = true;
  307. this.processData = obj;
  308. if (callback) callback();
  309. }.bind(this),
  310. "onerror": function(text){
  311. this.notice(text, "error");
  312. }.bind(this),
  313. "onRequestFailure": function(xhr){
  314. this.notice(xhr.responseText, "error");
  315. }.bind(this)
  316. });
  317. },
  318. loadProcessData: function(callback){
  319. this.actions.getProcess(this.options.id, function(process){
  320. if (process){
  321. this.processData = process.data;
  322. this.processData.isNewProcess = false;
  323. this.setTitle(this.options.appTitle + "-"+this.processData.name);
  324. if (!this.application){
  325. this.actions.getApplication(process.data.application, function(json){
  326. this.application = {"name": json.data.name, "id": json.data.id};
  327. if (callback) callback();
  328. }.bind(this));
  329. }else{
  330. if (callback) callback();
  331. }
  332. }
  333. }.bind(this));
  334. },
  335. loadGadgets: function(){
  336. this.gadgetTitleNode = new Element("div", {
  337. "styles": this.css.gadgetTitleNode,
  338. "text": MWF.APPPD.LP.tools
  339. }).inject(this.gadgetAreaNode);
  340. this.gadgetTitleActionNode = new Element("div", {
  341. "styles": this.css.gadgetTitleActionNode,
  342. "events": {"click": function(e){this.switchGadgetAreaMode();}.bind(this)}
  343. }).inject(this.gadgetAreaNode);
  344. this.gadgetContentNode = new Element("div", {
  345. "styles": this.css.gadgetContentNode,
  346. "events": {"selectstart": function(e){e.preventDefault(); e.stopPropagation();}}
  347. }).inject(this.gadgetAreaNode);
  348. MWF.getJSON(this.path+"gadget.json", function(json){
  349. Object.each(json, function(value, key){
  350. this.createGadgetNode(value, key);
  351. }.bind(this));
  352. }.bind(this));
  353. this.setScrollBar(this.gadgetContentNode, null, {
  354. "V": {"x": 0, "y": 0},
  355. "H": {"x": 0, "y": 0}
  356. });
  357. },
  358. switchGadgetAreaMode: function(){
  359. if (this.gadgetMode=="all"){
  360. var size = this.gadgetAreaNode.getSize();
  361. this.gadgetDecrease = (size.x.toFloat())-60;
  362. this.gadgets.each(function(node){
  363. node.getLast().setStyle("display", "none");
  364. });
  365. this.gadgetTitleNode.set("text", "");
  366. this.gadgetAreaNode.setStyle("width", "60px");
  367. var rightMargin = this.rightContentNode.getStyle("margin-left").toFloat();
  368. rightMargin = rightMargin - this.gadgetDecrease;
  369. this.rightContentNode.setStyle("margin-left", ""+rightMargin+"px");
  370. this.gadgetTitleActionNode.setStyles(this.css.gadgetTitleActionNodeRight);
  371. this.gadgetMode="simple";
  372. }else{
  373. sizeX = 60 + this.gadgetDecrease;
  374. var rightMargin = this.rightContentNode.getStyle("margin-left").toFloat();
  375. rightMargin = rightMargin + this.gadgetDecrease;
  376. this.gadgetAreaNode.setStyle("width", ""+sizeX+"px");
  377. this.rightContentNode.setStyle("margin-left", ""+rightMargin+"px");
  378. this.gadgets.each(function(node){
  379. node.getLast().setStyle("display", "block");
  380. });
  381. this.gadgetTitleNode.set("text", MWF.APPPD.LP.tools);
  382. this.gadgetTitleActionNode.setStyles(this.css.gadgetTitleActionNode);
  383. this.gadgetMode="all";
  384. }
  385. },
  386. createGadgetNode: function(data, key){
  387. var _self = this;
  388. var gadgetNode = new Element("div", {
  389. "styles": this.css.gadgetToolNode,
  390. "title": data.text,
  391. "events": {
  392. "mouseover": function(e){
  393. try {
  394. this.setStyles(_self.css.gadgetToolNodeOver);
  395. }catch(e){
  396. this.setStyles(_self.css.gadgetToolNodeOverCSS2);
  397. };
  398. },
  399. "mouseout": function(e){
  400. try {
  401. this.setStyles(_self.css.gadgetToolNode);
  402. }catch(e){};
  403. },
  404. "mousedown": function(e){
  405. try {
  406. this.setStyles(_self.css.gadgetToolNodeDown);
  407. }catch(e){
  408. this.setStyles(_self.css.gadgetToolNodeDownCSS2);
  409. };
  410. },
  411. "mouseup": function(e){
  412. try {
  413. this.setStyles(_self.css.gadgetToolNodeUp);
  414. }catch(e){
  415. this.setStyles(_self.css.gadgetToolNodeUpCSS2);
  416. };
  417. }
  418. }
  419. }).inject(this.gadgetContentNode);
  420. gadgetNode.store("gadgetClass", data.className);
  421. gadgetNode.store("gadgetType", key);
  422. gadgetNode.store("gadgetIcon", data.icon);
  423. var iconNode = new Element("div", {
  424. "styles": this.css.gadgetToolIconNode
  425. }).inject(gadgetNode);
  426. iconNode.setStyle("background-image", "url("+this.path+this.options.style+"/gadget/"+data.icon+")");
  427. var textNode = new Element("div", {
  428. "styles": this.css.gadgetToolTextNode,
  429. "text": data.text
  430. });
  431. textNode.inject(gadgetNode);
  432. // var designer = this;
  433. gadgetNode.addEvent("mousedown", function(e){
  434. var className = this.retrieve("gadgetClass");
  435. var gadgetType = this.retrieve("gadgetType");
  436. var gadgetIcon = this.retrieve("gadgetIcon");
  437. _self.gadgetCreateActivity(this, gadgetType, gadgetIcon, className, e);
  438. });
  439. this.gadgets.push(gadgetNode);
  440. },
  441. gadgetCreateActivity: function(node, gadgetType, gadgetIcon, className, e){
  442. var activity = null;
  443. // if (activity){
  444. var moveNode = new Element("div", {
  445. "styles": {
  446. "width": "30px",
  447. "height": "30px",
  448. "opacity": "1",
  449. "background": "url("+this.path+this.options.style+"/gadget/"+gadgetIcon+") top left no-repeat",
  450. "postion": "absolute"
  451. }
  452. }).inject(this.paperNode);
  453. var moveNodeSize = moveNode.getSize();
  454. //moveNode.position({"relativeTo": node, "position": "upperLeft", "edge": "upperLeft"});
  455. var x = e.page.x;
  456. var y = e.page.y;
  457. moveNode.positionTo(x, y);
  458. var droppables = [this.paperNode];
  459. var nodeDrag = new Drag.Move(moveNode, {
  460. "droppables": droppables,
  461. "onEnter": function(dragging, inObj){
  462. moveNode.setStyles({
  463. "opacity":"1",
  464. "background": "url("+this.path+this.options.style+"/gadget/"+gadgetIcon+") top left no-repeat"
  465. });
  466. //moveNode.setStyle("opacity","0");
  467. //activity = this.process.createActivity(gadgetType, className);
  468. //if (activity){
  469. // activity.selected();
  470. // activity.activityMoveStart();
  471. //
  472. // moveNode.dragMove = true;
  473. //
  474. // var p = moveNode.getPosition(this.paperNode);
  475. // var dx = p.x - activity.point.x;
  476. // var dy = p.y - activity.point.y;
  477. // activity.activityMove(dx, dy, 0, 0, e);
  478. //
  479. // moveNode.dx = activity.point.x;
  480. // moveNode.dy = activity.point.y;
  481. // activity.activityMoveStart();
  482. //}else{
  483. // moveNode.setStyles({
  484. // "opacity":"1",
  485. // "background": "url("+this.path+this.options.style+"/gadget/stop.png) top left no-repeat",
  486. // });
  487. //}
  488. }.bind(this),
  489. "onLeave": function(dragging, inObj){
  490. moveNode.setStyles({
  491. "opacity":"1",
  492. "background": "url("+this.path+this.options.style+"/gadget/stop.png) top left no-repeat"
  493. });
  494. if (activity) activity.destroy();
  495. moveNode.dragMove = false;
  496. }.bind(this),
  497. "onDrag": function(e){
  498. if (moveNode.dragMove){
  499. var p = moveNode.getPosition(this.paperNode);
  500. var dx = p.x-moveNode.dx;
  501. var dy = p.y-moveNode.dy;
  502. activity.activityMove(dx, dy, 0, 0, e);
  503. }
  504. }.bind(this),
  505. "onDrop": function(dragging, inObj){
  506. //if (moveNode.dragMove){
  507. // activity.activityMoveEnd();
  508. //}
  509. }.bind(this),
  510. "onComplete": function(e){
  511. var p = moveNode.getPosition(this.paperNode);
  512. //var dx = p.x - activity.point.x;
  513. //var dy = p.y - activity.point.y;
  514. activity = this.process.createActivity(gadgetType, className, {"x": p.x, "y": p.y});
  515. if (activity) activity.selected();
  516. // activity.activityMoveStart();
  517. //moveNode.dragMove = true;
  518. // activity.activityMove(dx, dy, 0, 0, e);
  519. //moveNode.dx = activity.point.x;
  520. //moveNode.dy = activity.point.y;
  521. //activity.activityMoveStart();
  522. // activity.activityMoveEnd();
  523. moveNode.destroy();
  524. }.bind(this),
  525. "onCancel": function(dragging){
  526. if (activity) activity.destroy();
  527. moveNode.destroy();
  528. }.bind(this)
  529. });
  530. nodeDrag.start(e);
  531. // }
  532. },
  533. loadNodes: function(){
  534. this.gadgetAreaNode = new Element("div", {
  535. "styles": this.css.gadgetAreaNode
  536. }).inject(this.node);
  537. this.rightContentNode = new Element("div", {
  538. "styles": this.css.rightContentNode
  539. }).inject(this.node);
  540. this.toolbarNode = new Element("div", {
  541. "styles": this.css.toolbarNode
  542. }).inject(this.rightContentNode);
  543. this.paperAreaNode = new Element("div", {
  544. "styles": this.css.paperAreaNode
  545. }).inject(this.rightContentNode);
  546. this.paperNode = new Element("div", {
  547. "styles": this.css.paperNode
  548. }).inject(this.paperAreaNode);
  549. },
  550. loadToolbar: function(callback){
  551. this.getProcessToolbarHTML(function(toolbarNode){
  552. var spans = toolbarNode.getElements("span");
  553. spans.each(function(item, idx){
  554. var img = item.get("MWFButtonImage");
  555. if (img){
  556. item.set("MWFButtonImage", this.path+""+this.options.style+"/toolbarIcon/"+img);
  557. }
  558. }.bind(this));
  559. $(toolbarNode).inject(this.toolbarNode);
  560. MWF.require("MWF.widget.Toolbar", function(){
  561. this.processToolbar = new MWF.widget.Toolbar(toolbarNode, {"style": "Process"}, this);
  562. this.processToolbar.load();
  563. if (callback) callback();
  564. }.bind(this));
  565. var select = toolbarNode.getElement("select");
  566. if (select){
  567. select.addEvent("change", function(){
  568. this.process.setStyle(select.options[select.selectedIndex].value);
  569. }.bind(this));
  570. }
  571. this.processEditionNode = toolbarNode.getElement(".processEdition");
  572. this.processEditionInforNode = toolbarNode.getElement(".processEditionInfor");
  573. }.bind(this));
  574. },
  575. getProcessToolbarHTML: function(callback){
  576. var toolbarUrl = this.path+"processToolbars.html";
  577. var r = new Request.HTML({
  578. url: toolbarUrl,
  579. method: "get",
  580. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  581. var toolbarNode = responseTree[0];
  582. if (callback) callback(toolbarNode);
  583. }.bind(this),
  584. onFailure: function(xhr){
  585. this.notice("request processToolbars error: "+xhr.responseText, "error");
  586. }.bind(this)
  587. });
  588. r.send();
  589. },
  590. resizePaper: function(){
  591. var nodeSize = this.node.getSize();
  592. var toolbarSize = this.processToolbar.node.getSize();
  593. var y = nodeSize.y - toolbarSize.y;
  594. var marginTop = this.paperNode.getStyle("margin-top").toFloat();
  595. var marginBottom = this.paperNode.getStyle("margin-bottom").toFloat();
  596. y = y - marginTop - marginBottom;
  597. //this.paperAreaNode.setStyle("height", ""+y+"px");
  598. this.paperNode.setStyle("height", ""+y+"px");
  599. if (this.paper) this.paper.setSize("100%", "100%");
  600. if (this.process){
  601. if (this.process.panel){
  602. this.process.panel.modulePanel.container.position({
  603. relativeTo: this.paperNode,
  604. position: 'upperRight',
  605. edge: 'upperRight'
  606. });
  607. var size = this.process.panel.modulePanel.container.getSize();
  608. var pSize = this.paperNode.getSize();
  609. if (pSize.y<size.y){
  610. var height = (this.paperNode.getSize().y.toFloat())-6;
  611. this.process.panel.modulePanel.container.setStyle("height", ""+height+"px");
  612. this.process.panel.modulePanel.content.setStyle("height", this.process.panel.modulePanel.getContentHeight());
  613. this.process.panel.setPanelSize();
  614. }
  615. if (pSize.x<size.x){
  616. this.process.panel.modulePanel.container.setStyle("width", ""+pSize.x+"px");
  617. }
  618. if (this.process.panel.propertyPanel){
  619. this.process.panel.propertyPanel.container.position({
  620. relativeTo: this.paperNode,
  621. position: 'bottomRight',
  622. edge: 'bottomRight'
  623. });
  624. var size = this.process.panel.propertyPanel.container.getSize();
  625. var pSize = this.paperNode.getSize();
  626. if (pSize.y<size.y){
  627. var height = (this.paperNode.getSize().y.toFloat())-6;
  628. this.process.panel.propertyPanel.container.setStyle("height", ""+height+"px");
  629. this.process.panel.propertyPanel.content.setStyle("height", this.process.panel.propertyPanel.getContentHeight());
  630. this.process.panel.setPropertyPanelSize();
  631. }
  632. if (pSize.x<size.x){
  633. this.process.panel.propertyPanel.container.setStyle("width", ""+pSize.x+"px");
  634. }
  635. }
  636. }
  637. }
  638. },
  639. loadPaper: function(){
  640. MWFRaphael.load(function(){
  641. this.paperInNode = new Element("div", {"styles": this.css.paperInNode}).inject(this.paperNode);
  642. this.paper = Raphael(this.paperInNode, "100%", "99%");
  643. this.paper.container = this.paperNode;
  644. MWF.xDesktop.requireApp("process.ProcessDesigner", "Process", function(){
  645. this.process = new MWF.APPPD.Process(this.paper, this.processData, this, {"style":"flat"});
  646. this.process.load();
  647. }.bind(this));
  648. }.bind(this));
  649. },
  650. setToolBardisabled: function(type){
  651. switch (type){
  652. case "default":
  653. break;
  654. case "createRoute":
  655. break;
  656. case "decision":
  657. break;
  658. default:
  659. }
  660. },
  661. recordStatus: function(){
  662. debugger;
  663. return {"id": this.options.id};
  664. },
  665. saveProcess: function(){
  666. if (!this.process.process.name){
  667. this.notice(this.lp.notice.no_name, "error");
  668. return false;
  669. }
  670. this.process.save(function(){
  671. var name = this.process.process.name;
  672. this.setTitle(this.options.appTitle + "-"+name);
  673. this.options.desktopReload = true;
  674. this.options.id = this.process.process.id;
  675. }.bind(this));
  676. },
  677. saveNewProcess: function(b, e){
  678. //this.process.saveNew(e);
  679. },
  680. createManualActivity: function(){
  681. this.process.createManualActivity();
  682. },
  683. createConditionActivity: function(){
  684. this.process.createConditionActivity();
  685. },
  686. createAutoActivity: function(){
  687. this.process.createAutoActivity();
  688. },
  689. createSplitActivity: function(){
  690. this.process.createSplitActivity();
  691. },
  692. createMergeActivity: function(){
  693. this.process.createMergeActivity();
  694. },
  695. createEmbedActivity: function(){
  696. this.process.createEmbedActivity();
  697. },
  698. createInvokesActivity: function(){
  699. this.process.createInvokesActivity();
  700. },
  701. createBeginActivity: function(){
  702. this.process.createBeginActivity();
  703. },
  704. createEndActivity: function(){
  705. this.process.createEndActivity();
  706. },
  707. createRoute: function(){
  708. this.process.createRoute();
  709. },
  710. processExplode: function(){
  711. this.process.explode();
  712. },
  713. saveNewEdition: function(el, e){
  714. this.process.saveNewEdition(e);
  715. },
  716. listEdition: function(el, e){
  717. this.process.listEdition(e);
  718. },
  719. onPostClose: function() {
  720. if (this.process) {
  721. this.process.activitys.each(function (activity) {
  722. activity.routes.each(function (route) {
  723. MWF.release(route);
  724. });
  725. MWF.release(activity);
  726. });
  727. MWF.release(this.process);
  728. }
  729. }
  730. });