InvokeExplorer.js 12 KB

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