InvokeExplorer.js 12 KB

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