ProcessExplorer.js 18 KB

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