InvokeExplorer.js 12 KB

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