InvokeExplorer.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. MWF.xDesktop.requireApp("process.ProcessManager", "Explorer", null, false);
  2. MWF.xApplication.service.ServiceManager.InvokeExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "tooltip": {
  8. "create": MWF.xApplication.service.ServiceManager.LP.invoke.create,
  9. "search": MWF.xApplication.service.ServiceManager.LP.invoke.search,
  10. "searchText": MWF.xApplication.service.ServiceManager.LP.invoke.searchText,
  11. "noElement": MWF.xApplication.service.ServiceManager.LP.invoke.noInvokeNoticeText
  12. }
  13. },
  14. createTitleElementNode: function() {
  15. this.titleElementNode = new Element("div", {
  16. "styles": this.css.titleElementNode,
  17. "text": "接口配置"
  18. }).inject(this.toolbarNode);
  19. },
  20. _createElement: function(e){
  21. var _self = this;
  22. var options = {
  23. "onQueryLoad": function(){
  24. this.actions = _self.app.restActions;
  25. this.application = _self.app.options.application;
  26. this.explorer = _self;
  27. }
  28. };
  29. this.app.desktop.openApplication(e, "service.InvokeDesigner", options);
  30. },
  31. _loadItemDataList: function(callback){
  32. this.app.restActions.listInvoke(callback);
  33. },
  34. _getItemObject: function(item){
  35. return new MWF.xApplication.service.ServiceManager.InvokeExplorer.Invoke(this, item)
  36. },
  37. deleteItems: function(){
  38. this.hideDeleteAction();
  39. while (this.deleteMarkItems.length){
  40. var item = this.deleteMarkItems.shift();
  41. if (this.deleteMarkItems.length){
  42. item.deleteInvoke();
  43. }else{
  44. item.deleteInvoke(function(){
  45. // this.reloadItems();
  46. //this.hideDeleteAction();
  47. }.bind(this));
  48. }
  49. }
  50. },
  51. keyCopy: function(e){
  52. if (this.selectMarkItems.length){
  53. var items = [];
  54. var i = 0;
  55. var checkItems = function(e){
  56. if (i>=this.selectMarkItems.length){
  57. if (items.length){
  58. var str = JSON.encode(items);
  59. if (e){
  60. e.clipboardData.setData('text/plain', str);
  61. }else {
  62. window.clipboardData.setData("Text", str);
  63. }
  64. this.app.notice(this.app.lp.copyed, "success");
  65. }
  66. }
  67. }.bind(this);
  68. this.selectMarkItems.each(function(item){
  69. this.app.restActions.getInvoke(item.data.id, function(json){
  70. json.data.elementType = "invoke";
  71. items.push(json.data);
  72. i++;
  73. checkItems(e);
  74. }.bind(this), null, false)
  75. }.bind(this));
  76. if (e) e.preventDefault();
  77. }
  78. },
  79. keyPaste: function(e){
  80. var dataStr = "";
  81. if (e){
  82. dataStr = e.clipboardData.getData('text/plain');
  83. }else{
  84. dataStr = window.clipboardData.getData("Text");
  85. }
  86. var data = JSON.decode(dataStr);
  87. this.pasteItem(data, 0);
  88. },
  89. pasteItem: function(data, i){
  90. if (i<data.length){
  91. var item = data[i];
  92. if (item.elementType==="invoke"){
  93. this.saveItemAs(item, function(){
  94. i++;
  95. this.pasteItem(data, i);
  96. }.bind(this), function(){
  97. i++;
  98. this.pasteItem(data, i);
  99. }.bind(this), function(){
  100. this.reload();
  101. }.bind(this));
  102. }else{
  103. i++;
  104. this.pasteItem(data, i);
  105. }
  106. }else{
  107. this.reload();
  108. }
  109. },
  110. saveItemAs: function(data, success, failure, cancel){
  111. this.app.restActions.listInvoke( function(dJson){
  112. var i=1;
  113. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  114. if (someItems.length){
  115. var someItem = someItems[0];
  116. var lp = this.app.lp;
  117. var _self = this;
  118. var d1 = new Date().parse(data.lastUpdateTime);
  119. var d2 = new Date().parse(someItem.lastUpdateTime);
  120. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  121. 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>";
  122. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.updateTime+"</div>" +
  123. //"<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(someItem.lastUpdatePerson)+"</div>" +
  124. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  125. 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>";
  126. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.updateTime+"</div>" +
  127. //"<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.lastUpdatePerson)+"</div>" +
  128. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  129. // html += "<>"
  130. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  131. {
  132. "text": lp.copyConfirm_overwrite,
  133. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  134. },
  135. {
  136. "text": lp.copyConfirm_new,
  137. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  138. },
  139. {
  140. "text": lp.copyConfirm_skip,
  141. "action": function(){/*nothing*/ this.close(); if (success) success();}
  142. },
  143. {
  144. "text": lp.copyConfirm_cancel,
  145. "action": function(){this.close(); if (cancel) cancel();}
  146. }
  147. ]);
  148. }else{
  149. this.saveItemAsNew(dJson, data, success, failure)
  150. }
  151. }.bind(this), function(){if (failure) failure();}.bind(this));
  152. },
  153. saveItemAsUpdate: function(someItem, data, success, failure){
  154. data.id = someItem.id;
  155. data.name = someItem.name;
  156. data.alias = someItem.alias;
  157. this.app.restActions.updateInvoke(someItem.id, data, function(){
  158. if (success) success();
  159. }.bind(this), function(){
  160. if (failure) failure();
  161. }.bind(this));
  162. },
  163. saveItemAsNew: function(dJson, data, success, failure){
  164. var oldName = data.name;
  165. var i=1;
  166. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  167. data.name = oldName+"_copy"+i;
  168. data.alias = oldName+"_copy"+i;
  169. i++;
  170. }
  171. data.id = "";
  172. data.id = "";
  173. this.app.restActions.createInvoke(data, function(){
  174. if (success) success();
  175. }.bind(this), function(){
  176. if (failure) failure();
  177. }.bind(this));
  178. }
  179. });
  180. MWF.xApplication.service.ServiceManager.InvokeExplorer.Invoke= new Class({
  181. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  182. createActionNode: function(){
  183. this.deleteActionNode = new Element("div", {
  184. "styles": this.css.deleteActionNode
  185. }).inject(this.node);
  186. this.deleteActionNode.addEvent("click", function(e){
  187. this.deleteItem(e);
  188. }.bind(this));
  189. },
  190. createTextNodes: function(){
  191. var titleNode = new Element("div", {
  192. "styles": this.css.itemTextTitleNode,
  193. "text": ( this.data.enable ? "" : "(禁用)" ) + this.data.name ,
  194. "title": this.data.name,
  195. "events": {
  196. "click": function(e){this._open(e);}.bind(this)
  197. }
  198. }).inject(this.node);
  199. if( !this.data.enable ){
  200. titleNode.setStyle("color","#999");
  201. }
  202. new Element("div", {
  203. "styles": this.css.itemTextDescriptionNode,
  204. "text": this.data.description || "",
  205. "title": this.data.description || ""
  206. }).inject(this.node);
  207. new Element("div", {
  208. "styles": this.css.itemTextDateNode,
  209. "text": (this.data.updateTime || "")
  210. }).inject(this.node);
  211. },
  212. _open: function(e){
  213. var _self = this;
  214. var options = {
  215. "onQueryLoad": function(){
  216. this.actions = _self.explorer.actions;
  217. this.category = _self;
  218. this.options.id = _self.data.id;
  219. }
  220. };
  221. this.explorer.app.desktop.openApplication(e, "service.InvokeDesigner", options);
  222. },
  223. _getIcon: function(){
  224. var x = (Math.random()*49).toInt();
  225. return "process_icon_"+x+".png";
  226. },
  227. _getLnkPar: function(){
  228. return {
  229. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  230. "title": this.data.name,
  231. "par": "service.InvokeDesigner#{\"id\": \""+this.data.id+"\"}"
  232. };
  233. },
  234. // deleteItem: function(e){
  235. // var _self = this;
  236. // this.explorer.app.confirm("info", e, this.explorer.app.lp.process.deleteProcessTitle, this.explorer.app.lp.process.deleteProcess, 320, 110, function(){
  237. // _self.deleteProcess();
  238. // this.close();
  239. // },function(){
  240. // this.close();
  241. // });
  242. // },
  243. deleteInvoke: function(callback){
  244. this.explorer.actions.deleteInvoke(this.data.id, function(){
  245. this.node.destroy();
  246. if (callback) callback();
  247. }.bind(this));
  248. }
  249. });