AgentExplorer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. MWF.xDesktop.requireApp("process.ProcessManager", "Explorer", null, false);
  2. MWF.xApplication.service.ServiceManager.AgentExplorer = 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.agent.create,
  9. "search": MWF.xApplication.service.ServiceManager.LP.agent.search,
  10. "searchText": MWF.xApplication.service.ServiceManager.LP.agent.searchText,
  11. "noElement": MWF.xApplication.service.ServiceManager.LP.agent.noAgentNoticeText
  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.agentConfig
  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.AgentDesigner", 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.agent.noPermission
  76. }).inject(this.elementContentListNode);
  77. }
  78. },
  79. _loadItemDataList: function(callback){
  80. this.app.restActions.listAgent(callback);
  81. },
  82. _getItemObject: function(item){
  83. return new MWF.xApplication.service.ServiceManager.AgentExplorer.Agent(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.deleteAgent();
  91. }else{
  92. item.deleteAgent(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.getAgent(item.data.id, function(json){
  118. json.data.elementType = "agent";
  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==="agent"){
  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.listAgent( 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.updateAgent(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. this.app.restActions.createAgent(data, function(){
  221. if (success) success();
  222. }.bind(this), function(){
  223. if (failure) failure();
  224. }.bind(this));
  225. }
  226. });
  227. MWF.xApplication.service.ServiceManager.AgentExplorer.Agent= new Class({
  228. Extends: MWF.xApplication.process.ProcessManager.Explorer.Item,
  229. createActionNode: function(){
  230. this.deleteActionNode = new Element("div", {
  231. "styles": this.css.deleteActionNode
  232. }).inject(this.node);
  233. this.deleteActionNode.addEvent("click", function(e){
  234. this.deleteItem(e);
  235. }.bind(this));
  236. },
  237. createTextNodes: function(){
  238. var titleNode = new Element("div", {
  239. "styles": this.css.itemTextTitleNode,
  240. "text": ( this.data.enable ? "" : "("+MWF.xApplication.service.ServiceManager.LP.disable+")" ) + this.data.name ,
  241. "title": this.data.name,
  242. "events": {
  243. "click": function(e){this._open(e);}.bind(this)
  244. }
  245. }).inject(this.node);
  246. if( !this.data.enable ){
  247. titleNode.setStyle("color","#999");
  248. }
  249. new Element("div", {
  250. "styles": this.css.itemTextDescriptionNode,
  251. "text": this.data.description || "",
  252. "title": this.data.description || ""
  253. }).inject(this.node);
  254. new Element("div", {
  255. "styles": this.css.itemTextDateNode,
  256. "text": (this.data.updateTime || "")
  257. }).inject(this.node);
  258. },
  259. _open: function(e){
  260. var _self = this;
  261. var options = {
  262. "appId": "service.AgentDesigner"+_self.data.id,
  263. "id": _self.data.id,
  264. "onQueryLoad": function(){
  265. this.actions = _self.explorer.actions;
  266. this.category = _self;
  267. this.options.id = _self.data.id;
  268. }
  269. };
  270. this.explorer.app.desktop.openApplication(e, "service.AgentDesigner", options);
  271. },
  272. _getIcon: function(){
  273. var x = (Math.random()*49).toInt();
  274. return "process_icon_"+x+".png";
  275. },
  276. _getLnkPar: function(){
  277. return {
  278. "icon": this.explorer.path+this.explorer.options.style+"/processIcon/lnk.png",
  279. "title": this.data.name,
  280. "par": "service.AgentDesigner#{\"id\": \""+this.data.id+"\"}"
  281. };
  282. },
  283. // deleteItem: function(e){
  284. // var _self = this;
  285. // this.explorer.app.confirm("info", e, this.explorer.app.lp.process.deleteProcessTitle, this.explorer.app.lp.process.deleteProcess, 320, 110, function(){
  286. // _self.deleteProcess();
  287. // this.close();
  288. // },function(){
  289. // this.close();
  290. // });
  291. // },
  292. deleteAgent: function(callback){
  293. this.explorer.actions.deleteAgent(this.data.id, function(){
  294. this.node.destroy();
  295. if (callback) callback();
  296. }.bind(this));
  297. }
  298. });