ProcessExplorer.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. debugger;
  114. var isSameApp = process.application === someItem.application;
  115. process.id = someItem.id;
  116. process.name = someItem.name;
  117. process.alias = someItem.alias;
  118. process.category = someItem.category || "";
  119. process.application = someItem.application;
  120. process.applicationName = someItem.applicationName;
  121. process.isNewProcess = false;
  122. var checkActivity = function(a) {
  123. a.process = process.id;
  124. if(a.form && !isSameApp)a.form="";
  125. }
  126. if (process.begin) {
  127. process.begin.process = process.id;
  128. if(process.begin.form && !isSameApp)process.begin.form="";
  129. }
  130. if (process.endList) process.endList.each(function(a){ checkActivity(a); });
  131. if (process.agentList) process.agentList.each(function(a){ checkActivity(a); });
  132. if (process.manualList) process.manualList.each(function(a){ checkActivity(a); });
  133. if (process.conditionList) process.conditionList.each(function(a){ checkActivity(a); });
  134. if (process.choiceList) process.choiceList.each(function(a){ checkActivity(a); });
  135. if (process.parallelList) process.parallelList.each(function(a){ checkActivity(a); });
  136. if (process.splitList) process.splitList.each(function(a){ checkActivity(a); });
  137. if (process.mergeList) process.mergeList.each(function(a){ checkActivity(a); });
  138. if (process.embedList) process.embedList.each(function(a){ checkActivity(a); });
  139. if (process.publishList) process.publishList.each(function(a){ checkActivity(a); });
  140. if (process.invokeList) process.invokeList.each(function(a){ checkActivity(a); });
  141. if (process.cancelList) process.cancelList.each(function(a){ checkActivity(a); });
  142. if (process.delayList) process.delayList.each(function(a){ checkActivity(a); });
  143. if (process.messageList) process.messageList.each(function(a){ checkActivity(a); });
  144. if (process.serviceList) process.serviceList.each(function(a){ checkActivity(a); });
  145. if (process.routeList) process.routeList.each(function(a){ checkActivity(a); });
  146. this.app.restActions.saveProcess(process, function(){
  147. if (success) success();
  148. }.bind(this), function(){
  149. if (failure) failure();
  150. }.bind(this));
  151. },
  152. saveItemAsNew: function(processJson, process, success, failure){
  153. debugger;
  154. var item = this.app.options.application;
  155. var id = item.id;
  156. var name = item.name;
  157. var isSameApp = process.application === id;
  158. process.alias = "";
  159. var oldName = process.name;
  160. var i=1;
  161. while (processJson.data.some(function(d){ return d.name==process.name })){
  162. process.name = oldName+"_copy"+i;
  163. i++;
  164. }
  165. process.application = id;
  166. process.applicationName = name;
  167. var oldIds = [];
  168. oldIds.push(process.id);
  169. var checkActivity = function(a) {
  170. oldIds.push(a.id);
  171. if(a.form && !isSameApp)a.form="";
  172. };
  173. if (process.begin) {
  174. oldIds.push(process.begin.id);
  175. if(process.begin.form && !isSameApp)process.begin.form="";
  176. }
  177. if (process.endList) process.endList.each(function(a){ checkActivity(a); });
  178. if (process.agentList) process.agentList.each(function(a){ checkActivity(a); });
  179. if (process.manualList) process.manualList.each(function(a){ checkActivity(a); });
  180. if (process.conditionList) process.conditionList.each(function(a){ checkActivity(a); });
  181. if (process.choiceList) process.choiceList.each(function(a){ checkActivity(a); });
  182. if (process.parallelList) process.parallelList.each(function(a){ checkActivity(a); });
  183. if (process.splitList) process.splitList.each(function(a){ checkActivity(a); });
  184. if (process.mergeList) process.mergeList.each(function(a){ checkActivity(a); });
  185. if (process.embedList) process.embedList.each(function(a){ checkActivity(a); });
  186. if (process.publishList) process.publishList.each(function(a){ checkActivity(a); });
  187. if (process.invokeList) process.invokeList.each(function(a){ checkActivity(a); });
  188. if (process.cancelList) process.cancelList.each(function(a){ checkActivity(a); });
  189. if (process.delayList) process.delayList.each(function(a){ checkActivity(a); });
  190. if (process.messageList) process.messageList.each(function(a){ checkActivity(a); });
  191. if (process.serviceList) process.serviceList.each(function(a){ checkActivity(a); });
  192. if (process.routeList) process.routeList.each(function(a){ checkActivity(a); });
  193. if (!isSameApp){
  194. process.isNewProcess = true;
  195. this.app.restActions.saveProcess(process, function(){
  196. if (success) success();
  197. }.bind(this), function(){
  198. if (failure) failure();
  199. }.bind(this));
  200. }else{
  201. this.app.restActions.getId(oldIds.length, function(ids) {
  202. var checkUUIDs = ids.data;
  203. var processStr = JSON.encode(process);
  204. oldIds.each(function(oid, i){
  205. var reg = new RegExp(oid, "ig");
  206. processStr = processStr.replace(reg, checkUUIDs[i].id);
  207. }.bind(this));
  208. process = JSON.decode(processStr);
  209. process.isNewProcess = true;
  210. this.app.restActions.saveProcess(process, function(){
  211. if (success) success();
  212. }.bind(this), function(){
  213. if (failure) failure();
  214. }.bind(this));
  215. }.bind(this));
  216. }
  217. },
  218. // saveItemAs: function(item, process){
  219. // var id = item.id;
  220. // var name = item.name;
  221. //
  222. // process.alias = "";
  223. // var oldName = process.name;
  224. // this.app.restActions.listProcess(id, function(processJson){
  225. //
  226. // }.bind(this));
  227. // },
  228. _createElement: function(e){
  229. var createProcess = function(e, template){
  230. var options = {
  231. "template": template,
  232. "application":{
  233. "name": _self.app.options.application.name,
  234. "id": _self.app.options.application.id
  235. },
  236. "onQueryLoad": function(){
  237. this.actions = _self.app.restActions;
  238. this.application = _self.app.options.application;
  239. }
  240. };
  241. layout.desktop.openApplication(e, "process.ProcessDesigner", options);
  242. };
  243. var createTemplateMaskNode = new Element("div", {"styles": this.css.createTemplateMaskNode}).inject(this.app.content);
  244. var createTemplateAreaNode = new Element("div", {"styles": this.css.createTemplateAreaNode}).inject(this.app.content);
  245. createTemplateAreaNode.fade("in");
  246. var createTemplateScrollNode = new Element("div", {"styles": this.css.createTemplateScrollNode}).inject(createTemplateAreaNode);
  247. var createTemplateContentNode = new Element("div", {"styles": this.css.createTemplateContentNode}).inject(createTemplateScrollNode);
  248. MWF.require("MWF.widget.ScrollBar", function(){
  249. new MWF.widget.ScrollBar(createTemplateScrollNode, {"indent": false});
  250. }.bind(this));
  251. var _self = this;
  252. var url = "../x_component_process_ProcessDesigner/$Process/template/templates.json";
  253. MWF.getJSON(url, function(json){
  254. json.each(function(template){
  255. var templateNode = new Element("div", {"styles": this.css.templateNode}).inject(createTemplateContentNode);
  256. var templateIconNode = new Element("div", {"styles": this.css.templateIconNode}).inject(templateNode);
  257. var templateTitleNode = new Element("div", {"styles": this.css.templateTitleNode, "text": template.title}).inject(templateNode);
  258. templateNode.store("template", template.name);
  259. var templateIconImgNode = new Element("img", {"styles": this.css.templateIconImgNode}).inject(templateIconNode);
  260. templateIconImgNode.set("src", "../x_component_process_ProcessDesigner/$Process/template/"+template.icon);
  261. templateNode.addEvents({
  262. "mouseover": function(){this.setStyles(_self.css.templateNode_over)},
  263. "mouseout": function(){this.setStyles(_self.css.templateNode)},
  264. "mousedown": function(){this.setStyles(_self.css.templateNode_down)},
  265. "mouseup": function(){this.setStyles(_self.css.templateNode_over)},
  266. "click": function(e){
  267. createProcess(e, this.retrieve("template"));
  268. createTemplateAreaNode.destroy();
  269. createTemplateMaskNode.destroy();
  270. }
  271. });
  272. }.bind(this))
  273. }.bind(this));
  274. createTemplateMaskNode.addEvent("click", function(){
  275. createTemplateAreaNode.destroy();
  276. createTemplateMaskNode.destroy();
  277. });
  278. var size = this.app.content.getSize();
  279. var y = (size.y - 262)/2;
  280. var x = (size.x - 828)/2;
  281. if (y<0) y=0;
  282. if (x<0) x=0;
  283. createTemplateAreaNode.setStyles({
  284. "top": ""+y+"px",
  285. "left": ""+x+"px"
  286. });
  287. },
  288. _loadItemDataList: function(callback){
  289. this.app.restActions.listProcess(this.app.options.application.id,callback);
  290. },
  291. _getItemObject: function(item){
  292. return new MWF.xApplication.process.ProcessManager.ProcessExplorer.Process(this, item)
  293. },
  294. showDeleteAction: function(){
  295. if (!this.deleteItemsAction){
  296. this.deleteItemsAction = new Element("div", {
  297. "styles": this.css.deleteItemsAction,
  298. "text": this.app.lp.deleteItems
  299. }).inject(this.node);
  300. this.deleteItemsAction.fade("in");
  301. this.deleteItemsAction.position({
  302. relativeTo: this.elementContentListNode,
  303. position: 'centerTop',
  304. edge: 'centerTop',
  305. "offset": {"y": this.elementContentNode.getScroll().y}
  306. });
  307. this.deleteItemsAction.addEvent("click", function(){
  308. var _self = this;
  309. this.app.confirm("warn", this.deleteItemsAction, MWF.APPPM.LP.deleteProcessTitle, MWF.APPPM.LP.deleteProcess, 430, 120, function(){
  310. _self.deleteItems();
  311. this.close();
  312. }, function(){
  313. this.close();
  314. });
  315. }.bind(this));
  316. }
  317. },
  318. deleteItems: function(){
  319. this.hideDeleteAction();
  320. while (this.deleteMarkItems.length){
  321. var item = this.deleteMarkItems.shift();
  322. if (this.deleteMarkItems.length){
  323. item.deleteProcess();
  324. }else{
  325. item.deleteProcess(function(){
  326. // this.reloadItems();
  327. //this.hideDeleteAction();
  328. }.bind(this));
  329. }
  330. }
  331. }
  332. });
  333. MWF.xApplication.process.ProcessManager.ProcessExplorer.Process = new Class({
  334. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  335. _open: function(e){
  336. var _self = this;
  337. var options = {
  338. "appId": "process.ProcessDesigner"+_self.data.id,
  339. "id": _self.data.id,
  340. // "application": _self.explorer.app.options.application.id,
  341. "application":{
  342. "name": _self.explorer.app.options.application.name,
  343. "id": _self.explorer.app.options.application.id
  344. },
  345. "onQueryLoad": function(){
  346. this.actions = _self.explorer.actions;
  347. this.category = _self;
  348. this.options.id = _self.data.id;
  349. this.application = _self.explorer.app.options.application;
  350. }
  351. };
  352. this.explorer.app.desktop.openApplication(e, "process.ProcessDesigner", options);
  353. },
  354. _getIcon: function(){
  355. var x = (Math.random()*49).toInt();
  356. return "process_icon_"+x+".png";
  357. },
  358. _getLnkPar: function(){
  359. return {
  360. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  361. "title": this.data.name,
  362. "par": "process.ProcessDesigner#{\"id\": \""+this.data.id+"\"}"
  363. };
  364. },
  365. // deleteItem: function(e){
  366. // var _self = this;
  367. // this.explorer.app.confirm("info", e, this.explorer.app.lp.process.deleteProcessTitle, this.explorer.app.lp.process.deleteProcess, 320, 110, function(){
  368. // _self.deleteProcess();
  369. // this.close();
  370. // },function(){
  371. // this.close();
  372. // });
  373. // },
  374. deleteProcess: function(callback){
  375. this.explorer.actions.deleteProcess(this.data.id, function(){
  376. this.node.destroy();
  377. if (callback) callback();
  378. }.bind(this));
  379. },
  380. saveas: function(){
  381. MWF.xDesktop.requireApp("Selector", "package", function(){
  382. var selector = new MWF.O2Selector(this.explorer.app.content, {
  383. "title": this.explorer.app.lp.copyto,
  384. "count": 1,
  385. "type": "Application",
  386. "values": [this.explorer.app.options.application],
  387. "onComplete": function(items){
  388. items.each(function(item){
  389. this.saveItemAs(item.data);
  390. }.bind(this));
  391. }.bind(this)
  392. });
  393. }.bind(this));
  394. },
  395. saveItemAs: function(item){
  396. var id = item.id;
  397. var name = item.name;
  398. this.explorer.app.restActions.getProcess(this.data.id, function(json){
  399. var process = json.data;
  400. process.alias = "";
  401. var oldName = process.name;
  402. this.explorer.app.restActions.listProcess(id, function(processJson){
  403. var i=1;
  404. while (processJson.data.some(function(d){ return d.name==process.name })){
  405. process.name = oldName+"_copy"+i;
  406. i++;
  407. }
  408. var isSameApp = process.application === id;
  409. process.application = id;
  410. process.applicationName = name;
  411. var oldIds = [];
  412. oldIds.push(process.id);
  413. var checkActivity = function(a) {
  414. oldIds.push(a.id);
  415. if(a.form && !isSameApp)a.form="";
  416. };
  417. if (process.begin) {
  418. oldIds.push(process.begin.id);
  419. if(process.begin.form && !isSameApp)process.begin.form="";
  420. }
  421. if (process.endList) process.endList.each(function(a){ checkActivity(a); });
  422. if (process.agentList) process.agentList.each(function(a){ checkActivity(a); });
  423. if (process.manualList) process.manualList.each(function(a){ checkActivity(a); });
  424. if (process.conditionList) process.conditionList.each(function(a){ checkActivity(a); });
  425. if (process.choiceList) process.choiceList.each(function(a){ checkActivity(a); });
  426. if (process.parallelList) process.parallelList.each(function(a){ checkActivity(a); });
  427. if (process.splitList) process.splitList.each(function(a){ checkActivity(a); });
  428. if (process.mergeList) process.mergeList.each(function(a){ checkActivity(a); });
  429. if (process.embedList) process.embedList.each(function(a){ checkActivity(a); });
  430. if (process.publishList) process.publishList.each(function(a){ checkActivity(a); });
  431. if (process.invokeList) process.invokeList.each(function(a){ checkActivity(a); });
  432. if (process.cancelList) process.cancelList.each(function(a){ checkActivity(a); });
  433. if (process.delayList) process.delayList.each(function(a){ checkActivity(a); });
  434. if (process.messageList) process.messageList.each(function(a){ checkActivity(a); });
  435. if (process.serviceList) process.serviceList.each(function(a){ checkActivity(a); });
  436. if (process.routeList) process.routeList.each(function(a){ checkActivity(a); });
  437. this.explorer.app.restActions.getId(oldIds.length, function(ids) {
  438. var checkUUIDs = ids.data;
  439. var processStr = JSON.encode(process);
  440. oldIds.each(function(oid, i){
  441. var reg = new RegExp(oid, "ig");
  442. processStr = processStr.replace(reg, checkUUIDs[i].id);
  443. }.bind(this));
  444. process = JSON.decode(processStr);
  445. process.isNewProcess = true;
  446. this.explorer.app.restActions.saveProcess(process, function(){
  447. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  448. }.bind(this));
  449. }.bind(this));
  450. }.bind(this));
  451. }.bind(this));
  452. }
  453. });