ScriptExplorer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. },
  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.scriptConfig
  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.ScriptDesigner", options);
  49. },
  50. setTooltip: function(){
  51. this.options.tooltip = {
  52. "create": MWF.xApplication.service.ServiceManager.LP.script.create,
  53. "search": MWF.xApplication.service.ServiceManager.LP.script.search,
  54. "searchText": MWF.xApplication.service.ServiceManager.LP.script.searchText,
  55. "noElement": MWF.xApplication.service.ServiceManager.LP.script.noScriptNoticeText
  56. };
  57. },
  58. loadElementList: function(){
  59. if( MWF.AC.isServiceManager() ){
  60. this._loadItemDataList(function(json){
  61. if (json.data.length){
  62. json.data.each(function(item){
  63. var itemObj = this._getItemObject(item);
  64. itemObj.load()
  65. }.bind(this));
  66. }else{
  67. var noElementNode = new Element("div.noElementNode", {
  68. "styles": this.css.noElementNode,
  69. "text": this.options.tooltip.noElement
  70. }).inject(this.elementContentListNode);
  71. noElementNode.addEvent("click", function(e){
  72. this._createElement(e);
  73. }.bind(this));
  74. }
  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.script.noPermission
  84. }).inject(this.elementContentListNode);
  85. }
  86. },
  87. _loadItemDataList: function(callback){
  88. this.app.restActions.listScript(callback);
  89. },
  90. _getItemObject: function(item){
  91. return new MWF.xApplication.service.ServiceManager.ScriptExplorer.Script(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.deleteScript();
  99. }else{
  100. item.deleteScript(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.getScript(item.data.id, function(json){
  126. json.data.elementType = "script";
  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==="script"){
  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.listScript(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.lastUpdateTime+"</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.lastUpdateTime+"</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. data.isNewScript = false;
  214. this.app.restActions.updateScript(data, function(){
  215. if (success) success();
  216. }.bind(this), function(){
  217. if (failure) failure();
  218. }.bind(this));
  219. },
  220. saveItemAsNew: function(dJson, data, success, failure){
  221. var oldName = data.name;
  222. var i=1;
  223. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  224. data.name = oldName+"_copy"+i;
  225. data.alias = oldName+"_copy"+i;
  226. i++;
  227. }
  228. data.id = "";
  229. data.isNewScript = true;
  230. this.app.restActions.addScript(data, function(){
  231. if (success) success();
  232. }.bind(this), function(){
  233. if (failure) failure();
  234. }.bind(this));
  235. }
  236. });
  237. MWF.xApplication.service.ServiceManager.ScriptExplorer.Script = new Class({
  238. Extends: MWF.xApplication.process.ProcessManager.DictionaryExplorer.Dictionary,
  239. _customNodes: function(){
  240. if (!this.data.validated){
  241. new Element("div", {"styles": this.explorer.css.itemErrorNode}).inject(this.node);
  242. this.node.setStyle("background-color", "#f9e8e8");
  243. }
  244. },
  245. _open: function(e){
  246. var _self = this;
  247. var options = {
  248. "appId": "service.ScriptDesigner"+_self.data.id,
  249. "id": _self.data.id,
  250. "onQueryLoad": function(){
  251. this.actions = _self.explorer.actions;
  252. this.category = _self;
  253. this.options.id = _self.data.id;
  254. }
  255. };
  256. this.explorer.app.desktop.openApplication(e, "service.ScriptDesigner", options);
  257. },
  258. _getIcon: function(){
  259. //var x = (Math.random()*33).toInt();
  260. //return "process_icon_"+x+".png";
  261. return "script.png";
  262. },
  263. _getLnkPar: function(){
  264. return {
  265. "icon": this.explorer.path+this.explorer.options.style+"/scriptIcon/lnk.png",
  266. "title": this.data.name,
  267. "par": "service.ScriptDesigner#{\"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.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  273. // _self.deleteForm();
  274. // this.close();
  275. // },function(){
  276. // this.close();
  277. // });
  278. // },
  279. deleteScript: function(callback){
  280. this.explorer.app.restActions.removeScript(this.data.id, function(){
  281. this.node.destroy();
  282. if (callback) callback();
  283. }.bind(this));
  284. }
  285. });