InvokeExplorer.js 12 KB

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