ProcessExplorer.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. MWF.xDesktop.requireApp("process.ProcessManager", "Explorer", null, false);
  2. MWF.xApplication.process.ProcessManager.ProcessExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.Explorer,
  4. Implements: [Options, Events],
  5. keyCopy: function(e){
  6. if (this.selectMarkItems.length){
  7. var items = [];
  8. var i = 0;
  9. var checkItems = function(e){
  10. if (i>=this.selectMarkItems.length){
  11. if (items.length){
  12. var str = JSON.encode(items);
  13. if (e){
  14. e.clipboardData.setData('text/plain', str);
  15. }else {
  16. window.clipboardData.setData("Text", str);
  17. }
  18. this.app.notice(this.app.lp.copyed, "success");
  19. }
  20. }
  21. }.bind(this);
  22. this.selectMarkItems.each(function(item){
  23. this.app.restActions.getProcess(item.data.id, function(json){
  24. json.data.elementType = "process";
  25. items.push(json.data);
  26. i++;
  27. checkItems(e);
  28. }.bind(this), null, false)
  29. }.bind(this));
  30. }
  31. },
  32. keyPaste: function(e){
  33. var dataStr = "";
  34. if (e){
  35. dataStr = e.clipboardData.getData('text/plain');
  36. }else{
  37. dataStr = window.clipboardData.getData("Text");
  38. }
  39. var data = JSON.decode(dataStr);
  40. this.pasteItem(data, 0);
  41. // data.each(function(item){
  42. // if (item.elementType==="process"){
  43. // this.saveItemAs(this.app.options.application, item);
  44. // }
  45. // }.bind(this));
  46. },
  47. pasteItem: function(data, i){
  48. if (i<data.length){
  49. var item = data[i];
  50. if (item.elementType==="process"){
  51. this.saveItemAs(item, function(){
  52. i++;
  53. this.pasteItem(data, i);
  54. }.bind(this), function(){
  55. i++;
  56. this.pasteItem(data, i);
  57. }.bind(this), function(){
  58. this.reload();
  59. }.bind(this));
  60. }else{
  61. i++;
  62. this.pasteItem(data, i);
  63. }
  64. }else{
  65. this.reload();
  66. }
  67. },
  68. saveItemAs: function(data, success, failure, cancel){
  69. this.app.restActions.listProcess(this.app.options.application.id, function(dJson){
  70. var i=1;
  71. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  72. if (someItems.length){
  73. var someItem = someItems[0];
  74. var lp = this.app.lp;
  75. var _self = this;
  76. var d1 = new Date().parse(data.lastUpdateTime);
  77. var d2 = new Date().parse(someItem.lastUpdateTime);
  78. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  79. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='font-weight: bold; font-size:14px;'>"+lp.copySource+" "+someItem.name+"</div>";
  80. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.lastUpdateTime+"</div>" +
  81. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(someItem.lastUpdatePerson)+"</div>" +
  82. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  83. html += "<div style='overflow: hidden; margin: 10px 0px; padding: 5px 10px; background-color: #ffffff; border-radius: 6px;'><div style='clear: both;font-weight: bold; font-size:14px;'>"+lp.copyTarget+" "+data.name+"</div>";
  84. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.lastUpdateTime+"</div>" +
  85. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.lastUpdatePerson)+"</div>" +
  86. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  87. // html += "<>"
  88. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  89. {
  90. "text": lp.copyConfirm_overwrite,
  91. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  92. },
  93. {
  94. "text": lp.copyConfirm_new,
  95. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  96. },
  97. {
  98. "text": lp.copyConfirm_skip,
  99. "action": function(){/*nothing*/ this.close(); if (success) success();}
  100. },
  101. {
  102. "text": lp.copyConfirm_cancel,
  103. "action": function(){this.close(); if (cancel) cancel();}
  104. }
  105. ]);
  106. }else{
  107. this.saveItemAsNew(dJson, data, success, failure)
  108. }
  109. }.bind(this), function(){if (failure) failure();}.bind(this));
  110. },
  111. saveItemAsUpdate: function(someItem, process, success, failure){
  112. process.id = someItem.id;
  113. process.name = someItem.name;
  114. process.alias = someItem.alias;
  115. process.application = someItem.application;
  116. process.applicationName = someItem.applicationName;
  117. process.isNewProcess = false;
  118. if (process.begin) process.begin.process = process.id;
  119. if (process.endList) process.endList.each(function(a){a.process = process.id;});
  120. if (process.manualList) process.manualList.each(function(a){a.process = process.id;});
  121. if (process.conditionList) process.conditionList.each(function(a){a.process = process.id;});
  122. if (process.choiceList) process.choiceList.each(function(a){a.process = process.id;});
  123. if (process.parallelList) process.parallelList.each(function(a){a.process = process.id;});
  124. if (process.splitList) process.splitList.each(function(a){a.process = process.id;});
  125. if (process.mergeList) process.mergeList.each(function(a){a.process = process.id;});
  126. if (process.embedList) process.embedList.each(function(a){a.process = process.id;});
  127. if (process.invokeList) process.invokeList.each(function(a){a.process = process.id;});
  128. if (process.cancelList) process.cancelList.each(function(a){a.process = process.id;});
  129. if (process.delayList) process.delayList.each(function(a){a.process = process.id;});
  130. if (process.messageList) process.messageList.each(function(a){a.process = process.id;});
  131. if (process.serviceList) process.serviceList.each(function(a){a.process = process.id;});
  132. if (process.routeList) process.routeList.each(function(a){a.process = process.id;});
  133. this.app.restActions.saveProcess(process, function(){
  134. if (success) success();
  135. }.bind(this), function(){
  136. if (failure) failure();
  137. }.bind(this));
  138. },
  139. saveItemAsNew: function(processJson, process, success, failure){
  140. var item = this.app.options.application;
  141. var id = item.id;
  142. var name = item.name;
  143. process.alias = "";
  144. var oldName = process.name;
  145. var i=1;
  146. while (processJson.data.some(function(d){ return d.name==process.name })){
  147. process.name = oldName+"_copy"+i;
  148. i++;
  149. }
  150. process.application = id;
  151. process.applicationName = name;
  152. var oldIds = [];
  153. oldIds.push(process.id);
  154. if (process.begin) oldIds.push(process.begin.id);
  155. if (process.endList) process.endList.each(function(a){oldIds.push(a.id);});
  156. if (process.manualList) process.manualList.each(function(a){oldIds.push(a.id);});
  157. if (process.conditionList) process.conditionList.each(function(a){oldIds.push(a.id);});
  158. if (process.choiceList) process.choiceList.each(function(a){oldIds.push(a.id);});
  159. if (process.parallelList) process.parallelList.each(function(a){oldIds.push(a.id);});
  160. if (process.splitList) process.splitList.each(function(a){oldIds.push(a.id);});
  161. if (process.mergeList) process.mergeList.each(function(a){oldIds.push(a.id);});
  162. if (process.embedList) process.embedList.each(function(a){oldIds.push(a.id);});
  163. if (process.invokeList) process.invokeList.each(function(a){oldIds.push(a.id);});
  164. if (process.cancelList) process.cancelList.each(function(a){oldIds.push(a.id);});
  165. if (process.delayList) process.delayList.each(function(a){oldIds.push(a.id);});
  166. if (process.messageList) process.messageList.each(function(a){oldIds.push(a.id);});
  167. if (process.serviceList) process.serviceList.each(function(a){oldIds.push(a.id);});
  168. if (process.routeList) process.routeList.each(function(a){oldIds.push(a.id);});
  169. this.app.restActions.getId(oldIds.length, function(ids) {
  170. var checkUUIDs = ids.data;
  171. var processStr = JSON.encode(process);
  172. oldIds.each(function(oid, i){
  173. var reg = new RegExp(oid, "ig");
  174. processStr = processStr.replace(reg, checkUUIDs[i].id);
  175. }.bind(this));
  176. process = JSON.decode(processStr);
  177. process.isNewProcess = true;
  178. this.app.restActions.saveProcess(process, function(){
  179. if (success) success();
  180. }.bind(this), function(){
  181. if (failure) failure();
  182. }.bind(this));
  183. }.bind(this));
  184. },
  185. // saveItemAs: function(item, process){
  186. // var id = item.id;
  187. // var name = item.name;
  188. //
  189. // process.alias = "";
  190. // var oldName = process.name;
  191. // this.app.restActions.listProcess(id, function(processJson){
  192. //
  193. // }.bind(this));
  194. // },
  195. _createElement: function(e){
  196. var createProcess = function(e, template){
  197. var options = {
  198. "template": template,
  199. "onQueryLoad": function(){
  200. this.actions = _self.app.restActions;
  201. this.application = _self.app.options.application;
  202. }
  203. };
  204. layout.desktop.openApplication(e, "process.ProcessDesigner", options);
  205. };
  206. var createTemplateMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  207. var createTemplateAreaNode = new Element("div", {"styles": this.css.createTemplateAreaNode}).inject(this.app.content);
  208. createTemplateAreaNode.fade("in");
  209. var createTemplateScrollNode = new Element("div", {"styles": this.css.createTemplateScrollNode}).inject(createTemplateAreaNode);
  210. var createTemplateContentNode = new Element("div", {"styles": this.css.createTemplateContentNode}).inject(createTemplateScrollNode);
  211. MWF.require("MWF.widget.ScrollBar", function(){
  212. new MWF.widget.ScrollBar(createTemplateScrollNode, {"indent": false});
  213. }.bind(this));
  214. var _self = this;
  215. var url = "/x_component_process_ProcessDesigner/$Process/template/templates.json";
  216. MWF.getJSON(url, function(json){
  217. json.each(function(template){
  218. var templateNode = new Element("div", {"styles": this.css.templateNode}).inject(createTemplateContentNode);
  219. var templateIconNode = new Element("div", {"styles": this.css.templateIconNode}).inject(templateNode);
  220. var templateTitleNode = new Element("div", {"styles": this.css.templateTitleNode, "text": template.title}).inject(templateNode);
  221. templateNode.store("template", template.name);
  222. var templateIconImgNode = new Element("img", {"styles": this.css.templateIconImgNode}).inject(templateIconNode);
  223. templateIconImgNode.set("src", "/x_component_process_ProcessDesigner/$Process/template/"+template.icon);
  224. templateNode.addEvents({
  225. "mouseover": function(){this.setStyles(_self.css.templateNode_over)},
  226. "mouseout": function(){this.setStyles(_self.css.templateNode)},
  227. "mousedown": function(){this.setStyles(_self.css.templateNode_down)},
  228. "mouseup": function(){this.setStyles(_self.css.templateNode_over)},
  229. "click": function(e){
  230. createProcess(e, this.retrieve("template"));
  231. createTemplateAreaNode.destroy();
  232. createTemplateMaskNode.destroy();
  233. }
  234. });
  235. }.bind(this))
  236. }.bind(this));
  237. createTemplateMaskNode.addEvent("click", function(){
  238. createTemplateAreaNode.destroy();
  239. createTemplateMaskNode.destroy();
  240. });
  241. var size = this.app.content.getSize();
  242. var y = (size.y - 262)/2;
  243. var x = (size.x - 828)/2;
  244. if (y<0) y=0;
  245. if (x<0) x=0;
  246. createTemplateAreaNode.setStyles({
  247. "top": ""+y+"px",
  248. "left": ""+x+"px"
  249. });
  250. },
  251. _loadItemDataList: function(callback){
  252. this.app.restActions.listProcess(this.app.options.application.id,callback);
  253. },
  254. _getItemObject: function(item){
  255. return new MWF.xApplication.process.ProcessManager.ProcessExplorer.Process(this, item)
  256. },
  257. deleteItems: function(){
  258. this.hideDeleteAction();
  259. while (this.deleteMarkItems.length){
  260. var item = this.deleteMarkItems.shift();
  261. if (this.deleteMarkItems.length){
  262. item.deleteProcess();
  263. }else{
  264. item.deleteProcess(function(){
  265. // this.reloadItems();
  266. //this.hideDeleteAction();
  267. }.bind(this));
  268. }
  269. }
  270. }
  271. });
  272. MWF.xApplication.process.ProcessManager.ProcessExplorer.Process = new Class({
  273. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  274. _open: function(e){
  275. var _self = this;
  276. var options = {
  277. "onQueryLoad": function(){
  278. this.actions = _self.explorer.actions;
  279. this.category = _self;
  280. this.options.id = _self.data.id;
  281. this.application = _self.explorer.app.options.application;
  282. }
  283. };
  284. this.explorer.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  285. },
  286. _getIcon: function(){
  287. var x = (Math.random()*49).toInt();
  288. return "process_icon_"+x+".png";
  289. },
  290. _getLnkPar: function(){
  291. return {
  292. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  293. "title": this.data.name,
  294. "par": "process.ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  295. };
  296. },
  297. // deleteItem: function(e){
  298. // var _self = this;
  299. // this.explorer.app.confirm("info", e, this.explorer.app.lp.process.deleteProcessTitle, this.explorer.app.lp.process.deleteProcess, 320, 110, function(){
  300. // _self.deleteProcess();
  301. // this.close();
  302. // },function(){
  303. // this.close();
  304. // });
  305. // },
  306. deleteProcess: function(callback){
  307. this.explorer.actions.deleteProcess(this.data.id, function(){
  308. this.node.destroy();
  309. if (callback) callback();
  310. }.bind(this));
  311. },
  312. saveItemAs: function(item){
  313. var id = item.id;
  314. var name = item.name;
  315. this.explorer.app.restActions.getProcess(this.data.id, function(json){
  316. var process = json.data;
  317. process.alias = "";
  318. var oldName = process.name;
  319. this.explorer.app.restActions.listProcess(id, function(processJson){
  320. var i=1;
  321. while (processJson.data.some(function(d){ return d.name==process.name })){
  322. process.name = oldName+"_copy"+i;
  323. i++;
  324. }
  325. process.application = id;
  326. process.applicationName = name;
  327. var oldIds = [];
  328. oldIds.push(process.id);
  329. if (process.begin) oldIds.push(process.begin.id);
  330. if (process.endList) process.endList.each(function(a){oldIds.push(a.id);});
  331. if (process.manualList) process.manualList.each(function(a){oldIds.push(a.id);});
  332. if (process.conditionList) process.conditionList.each(function(a){oldIds.push(a.id);});
  333. if (process.choiceList) process.choiceList.each(function(a){oldIds.push(a.id);});
  334. if (process.parallelList) process.parallelList.each(function(a){oldIds.push(a.id);});
  335. if (process.splitList) process.splitList.each(function(a){oldIds.push(a.id);});
  336. if (process.mergeList) process.mergeList.each(function(a){oldIds.push(a.id);});
  337. if (process.embedList) process.embedList.each(function(a){oldIds.push(a.id);});
  338. if (process.invokeList) process.invokeList.each(function(a){oldIds.push(a.id);});
  339. if (process.cancelList) process.cancelList.each(function(a){oldIds.push(a.id);});
  340. if (process.delayList) process.delayList.each(function(a){oldIds.push(a.id);});
  341. if (process.messageList) process.messageList.each(function(a){oldIds.push(a.id);});
  342. if (process.serviceList) process.serviceList.each(function(a){oldIds.push(a.id);});
  343. if (process.routeList) process.routeList.each(function(a){oldIds.push(a.id);});
  344. this.explorer.app.restActions.getId(oldIds.length, function(ids) {
  345. var checkUUIDs = ids.data;
  346. var processStr = JSON.encode(process);
  347. oldIds.each(function(oid, i){
  348. var reg = new RegExp(oid, "ig");
  349. processStr = processStr.replace(reg, checkUUIDs[i].id);
  350. }.bind(this));
  351. process = JSON.decode(processStr);
  352. process.isNewProcess = true;
  353. this.explorer.app.restActions.saveProcess(process, function(){
  354. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  355. }.bind(this));
  356. }.bind(this));
  357. }.bind(this));
  358. }.bind(this));
  359. }
  360. });