ScriptExplorer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. MWF.xDesktop.requireApp("process.ProcessManager", "DictionaryExplorer", null, false);
  2. MWF.xApplication.service.ServiceManager.ScriptExplorer = new Class({
  3. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "tooltip": {
  8. "create": MWF.xApplication.service.ServiceManager.LP.script.create,
  9. "search": MWF.xApplication.service.ServiceManager.LP.script.search,
  10. "searchText": MWF.xApplication.service.ServiceManager.LP.script.searchText,
  11. "noElement": MWF.xApplication.service.ServiceManager.LP.script.noScriptNoticeText
  12. },
  13. "categoryEnable": false,
  14. "itemStyle": "line",
  15. "name": "service.ScriptExplorer",
  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.scriptConfig
  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.ScriptDesigner", options);
  52. },
  53. setTooltip: function(){
  54. this.options.tooltip = {
  55. "create": MWF.xApplication.service.ServiceManager.LP.script.create,
  56. "search": MWF.xApplication.service.ServiceManager.LP.script.search,
  57. "searchText": MWF.xApplication.service.ServiceManager.LP.script.searchText,
  58. "noElement": MWF.xApplication.service.ServiceManager.LP.script.noScriptNoticeText
  59. };
  60. },
  61. loadElementList: function(){
  62. this.itemList = [];
  63. if( MWF.AC.isServiceManager() ){
  64. this._loadItemDataList(function(json){
  65. if (json.data.length){
  66. this.checkSort(json.data);
  67. json.data.each(function(item){
  68. var itemObj = this._getItemObject(item);
  69. itemObj.load();
  70. this.checkShow(itemObj);
  71. this.itemList.push(itemObj);
  72. }.bind(this));
  73. }else{
  74. var noElementNode = new Element("div.noElementNode", {
  75. "styles": this.css.noElementNode,
  76. "text": this.options.tooltip.noElement
  77. }).inject(this.elementContentListNode);
  78. noElementNode.addEvent("click", function(e){
  79. this._createElement(e);
  80. }.bind(this));
  81. }
  82. this.loadTopNode();
  83. if( !this.isSetContentSize ){
  84. this.setContentSize();
  85. this.isSetContentSize = true;
  86. }
  87. }.bind(this));
  88. }else{
  89. var noElementNode = new Element("div.noElementNode", {
  90. "styles": this.css.noElementNode,
  91. "text": MWF.xApplication.service.ServiceManager.LP.script.noPermission
  92. }).inject(this.elementContentListNode);
  93. }
  94. },
  95. _loadItemDataList: function(callback){
  96. this.app.restActions.listScript(callback);
  97. },
  98. _getItemObject: function(item){
  99. return new MWF.xApplication.service.ServiceManager.ScriptExplorer.Script(this, item)
  100. },
  101. deleteItems: function(){
  102. this.hideDeleteAction();
  103. while (this.deleteMarkItems.length){
  104. var item = this.deleteMarkItems.shift();
  105. if (this.deleteMarkItems.length){
  106. item.deleteScript();
  107. }else{
  108. item.deleteScript(function(){
  109. // this.reloadItems();
  110. //this.hideDeleteAction();
  111. }.bind(this));
  112. }
  113. }
  114. },
  115. keyCopy: function(e){
  116. if (this.selectMarkItems.length){
  117. var items = [];
  118. var i = 0;
  119. var checkItems = function(e){
  120. if (i>=this.selectMarkItems.length){
  121. if (items.length){
  122. var str = JSON.encode(items);
  123. if (e){
  124. e.clipboardData.setData('text/plain', str);
  125. }else {
  126. window.clipboardData.setData("Text", str);
  127. }
  128. this.app.notice(this.app.lp.copyed, "success");
  129. }
  130. }
  131. }.bind(this);
  132. this.selectMarkItems.each(function(item){
  133. this.app.restActions.getScript(item.data.id, function(json){
  134. json.data.elementType = "script";
  135. items.push(json.data);
  136. i++;
  137. checkItems(e);
  138. }.bind(this), null, false)
  139. }.bind(this));
  140. if (e) e.preventDefault();
  141. }
  142. },
  143. keyPaste: function(e){
  144. var dataStr = "";
  145. if (e){
  146. dataStr = e.clipboardData.getData('text/plain');
  147. }else{
  148. dataStr = window.clipboardData.getData("Text");
  149. }
  150. var data = JSON.decode(dataStr);
  151. this.pasteItem(data, 0);
  152. },
  153. pasteItem: function(data, i){
  154. if (i<data.length){
  155. var item = data[i];
  156. if (item.elementType==="script"){
  157. this.saveItemAs(item, function(){
  158. i++;
  159. this.pasteItem(data, i);
  160. }.bind(this), function(){
  161. i++;
  162. this.pasteItem(data, i);
  163. }.bind(this), function(){
  164. this.reload();
  165. }.bind(this));
  166. }else{
  167. i++;
  168. this.pasteItem(data, i);
  169. }
  170. }else{
  171. this.reload();
  172. }
  173. },
  174. saveItemAs: function(data, success, failure, cancel){
  175. this.app.restActions.listScript(function(dJson){
  176. var i=1;
  177. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  178. if (someItems.length){
  179. var someItem = someItems[0];
  180. var lp = this.app.lp;
  181. var _self = this;
  182. var d1 = new Date().parse(data.lastUpdateTime);
  183. var d2 = new Date().parse(someItem.lastUpdateTime);
  184. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  185. 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>";
  186. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.lastUpdateTime+"</div>" +
  187. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(someItem.lastUpdatePerson)+"</div>" +
  188. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  189. 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>";
  190. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.lastUpdateTime+"</div>" +
  191. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.lastUpdatePerson)+"</div>" +
  192. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  193. // html += "<>"
  194. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  195. {
  196. "text": lp.copyConfirm_overwrite,
  197. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  198. },
  199. {
  200. "text": lp.copyConfirm_new,
  201. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  202. },
  203. {
  204. "text": lp.copyConfirm_skip,
  205. "action": function(){/*nothing*/ this.close(); if (success) success();}
  206. },
  207. {
  208. "text": lp.copyConfirm_cancel,
  209. "action": function(){this.close(); if (cancel) cancel();}
  210. }
  211. ]);
  212. }else{
  213. this.saveItemAsNew(dJson, data, success, failure)
  214. }
  215. }.bind(this), function(){if (failure) failure();}.bind(this));
  216. },
  217. saveItemAsUpdate: function(someItem, data, success, failure){
  218. data.id = someItem.id;
  219. data.name = someItem.name;
  220. data.alias = someItem.alias;
  221. data.isNewScript = false;
  222. this.app.restActions.updateScript(data, function(){
  223. if (success) success();
  224. }.bind(this), function(){
  225. if (failure) failure();
  226. }.bind(this));
  227. },
  228. saveItemAsNew: function(dJson, data, success, failure){
  229. var oldName = data.name;
  230. var i=1;
  231. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  232. data.name = oldName+"_copy"+i;
  233. data.alias = oldName+"_copy"+i;
  234. i++;
  235. }
  236. data.id = "";
  237. data.isNewScript = true;
  238. this.app.restActions.addScript(data, function(){
  239. if (success) success();
  240. }.bind(this), function(){
  241. if (failure) failure();
  242. }.bind(this));
  243. }
  244. });
  245. MWF.xApplication.service.ServiceManager.ScriptExplorer.Script = new Class({
  246. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary,
  247. _customNodes: function(){
  248. if (!this.data.validated){
  249. new Element("div", {"styles": this.explorer.css.itemErrorNode}).inject(this.node);
  250. this.node.setStyle("background-color", "#f9e8e8");
  251. }
  252. },
  253. _open: function(e){
  254. var _self = this;
  255. var options = {
  256. "appId": "service.ScriptDesigner"+_self.data.id,
  257. "id": _self.data.id,
  258. "onQueryLoad": function(){
  259. this.actions = _self.explorer.actions;
  260. this.category = _self;
  261. this.options.id = _self.data.id;
  262. }
  263. };
  264. this.explorer.app.desktop.openApplication(e, "service.ScriptDesigner", options);
  265. },
  266. _getIcon: function(){
  267. //var x = (Math.random()*33).toInt();
  268. //return "process_icon_"+x+".png";
  269. return "script.png";
  270. },
  271. _getLnkPar: function(){
  272. return {
  273. "icon": this.explorer.path+this.explorer.options.style+"/scriptIcon/lnk.png",
  274. "title": this.data.name,
  275. "par": "service.ScriptDesigner#{\"id\": \""+this.data.id+"\"}"
  276. };
  277. },
  278. // deleteItem: function(e){
  279. // var _self = this;
  280. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  281. // _self.deleteForm();
  282. // this.close();
  283. // },function(){
  284. // this.close();
  285. // });
  286. // },
  287. deleteScript: function(callback){
  288. this.explorer.app.restActions.removeScript(this.data.id, function(){
  289. this.node.destroy();
  290. if (callback) callback();
  291. }.bind(this));
  292. }
  293. });