ScriptExplorer.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. MWF.xDesktop.requireApp("cms.ColumnManager", "DictionaryExplorer", null, false);
  2. MWF.xApplication.cms.ColumnManager.ScriptExplorer = new Class({
  3. Extends: MWF.xApplication.cms.ColumnManager.DictionaryExplorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "create": MWF.CMSCM.LP.dictionary.create,
  7. "search": MWF.CMSCM.LP.dictionary.search,
  8. "searchText": MWF.CMSCM.LP.dictionary.searchText,
  9. "noElement": MWF.CMSCM.LP.dictionary.noDictionaryNoticeText
  10. },
  11. keyCopy: function(e){
  12. if (this.selectMarkItems.length){
  13. var items = [];
  14. var i = 0;
  15. var checkItems = function(e){
  16. if (i>=this.selectMarkItems.length){
  17. if (items.length){
  18. var str = JSON.encode(items);
  19. if (e){
  20. e.clipboardData.setData('text/plain', str);
  21. }else {
  22. window.clipboardData.setData("Text", str);
  23. }
  24. this.app.notice(this.app.lp.copyed, "success");
  25. }
  26. }
  27. }.bind(this);
  28. this.selectMarkItems.each(function(item){
  29. this.app.restActions.getScript(item.data.id, function(json){
  30. json.data.elementType = "script";
  31. items.push(json.data);
  32. i++;
  33. checkItems(e);
  34. }.bind(this), null, false)
  35. }.bind(this));
  36. }
  37. },
  38. keyPaste: function(e){
  39. var dataStr = "";
  40. if (e){
  41. dataStr = e.clipboardData.getData('text/plain');
  42. }else{
  43. dataStr = window.clipboardData.getData("Text");
  44. }
  45. var data = JSON.decode(dataStr);
  46. this.pasteItem(data, 0);
  47. },
  48. pasteItem: function(data, i){
  49. if (i<data.length){
  50. var item = data[i];
  51. if (item.elementType==="script"){
  52. this.saveItemAs(item, function(){
  53. i++;
  54. this.pasteItem(data, i);
  55. }.bind(this), function(){
  56. i++;
  57. this.pasteItem(data, i);
  58. }.bind(this), function(){
  59. this.reload();
  60. }.bind(this));
  61. }else{
  62. i++;
  63. this.pasteItem(data, i);
  64. }
  65. }else{
  66. this.reload();
  67. }
  68. },
  69. saveItemAs: function(data, success, failure, cancel){
  70. this.app.restActions.listScript(this.app.options.application.id, function(dJson){
  71. var i=1;
  72. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  73. if (someItems.length){
  74. var someItem = someItems[0];
  75. var lp = this.app.lp;
  76. var _self = this;
  77. var d1 = new Date().parse(data.lastUpdateTime);
  78. var d2 = new Date().parse(someItem.lastUpdateTime);
  79. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  80. 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>";
  81. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.lastUpdateTime+"</div>" +
  82. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(someItem.lastUpdatePerson)+"</div>" +
  83. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  84. 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>";
  85. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.lastUpdateTime+"</div>" +
  86. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'>"+MWF.name.cn(data.lastUpdatePerson)+"</div>" +
  87. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  88. // html += "<>"
  89. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  90. {
  91. "text": lp.copyConfirm_overwrite,
  92. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  93. },
  94. {
  95. "text": lp.copyConfirm_new,
  96. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  97. },
  98. {
  99. "text": lp.copyConfirm_skip,
  100. "action": function(){/*nothing*/ this.close(); if (success) success();}
  101. },
  102. {
  103. "text": lp.copyConfirm_cancel,
  104. "action": function(){this.close(); if (cancel) cancel();}
  105. }
  106. ]);
  107. }else{
  108. this.saveItemAsNew(dJson, data, success, failure)
  109. }
  110. }.bind(this), function(){if (failure) failure();}.bind(this));
  111. },
  112. saveItemAsUpdate: function(someItem, data, success, failure){
  113. data.id = someItem.id;
  114. data.name = someItem.name;
  115. data.alias = someItem.alias;
  116. data.isNewScript = false;
  117. data.application = someItem.application;
  118. data.applicationName = someItem.applicationName;
  119. this.app.restActions.saveScript(data, function(){
  120. if (success) success();
  121. }.bind(this), function(){
  122. if (failure) failure();
  123. }.bind(this));
  124. },
  125. saveItemAsNew: function(dJson, data, success, failure){
  126. var item = this.app.options.application;
  127. var id = item.id;
  128. var name = item.name;
  129. var oldName = data.name;
  130. var i=1;
  131. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  132. data.name = oldName+"_copy"+i;
  133. data.alias = oldName+"_copy"+i;
  134. i++;
  135. }
  136. data.id = "";
  137. data.isNewScript = true;
  138. data.application = id;
  139. data.applicationName = name;
  140. this.app.restActions.saveScript(data, function(){
  141. if (success) success();
  142. }.bind(this), function(){
  143. if (failure) failure();
  144. }.bind(this));
  145. },
  146. _createElement: function(e){
  147. var _self = this;
  148. var options = {
  149. "onQueryLoad": function(){
  150. this.actions = _self.app.restActions;
  151. //_self.app.options.application = _self.app.options.application || _self.app.options.column;
  152. this.application = _self.app.options.application || _self.app.application || _self.app.options.column || _self.app.column;
  153. this.column = this.application;
  154. this.explorer = _self;
  155. },
  156. "onPostSave" : function(){
  157. _self.reload();
  158. }
  159. };
  160. this.app.desktop.openApplication(e, "cms.ScriptDesigner", options);
  161. },
  162. _loadItemDataList: function(callback){
  163. var id = "";
  164. if (this.app.application) id = this.app.application.id;
  165. if (this.app.options.application) id = this.app.options.application.id;
  166. this.actions.listScript(id,callback);
  167. },
  168. _getItemObject: function(item, index){
  169. return new MWF.xApplication.cms.ColumnManager.ScriptExplorer.Script(this, item, {index : index})
  170. },
  171. setTooltip: function(){
  172. this.options.tooltip = {
  173. "create": MWF.CMSCM.LP.script.create,
  174. "search": MWF.CMSCM.LP.script.search,
  175. "searchText": MWF.CMSCM.LP.script.searchText,
  176. "noElement": MWF.CMSCM.LP.script.noScriptNoticeText
  177. };
  178. },
  179. deleteItems: function(){
  180. while (this.deleteMarkItems.length){
  181. var item = this.deleteMarkItems.shift();
  182. if (this.deleteMarkItems.length){
  183. item.deleteScript();
  184. }else{
  185. item.deleteScript(function(){
  186. // this.reloadItems();
  187. this.hideDeleteAction();
  188. this.reload();
  189. }.bind(this));
  190. }
  191. }
  192. }
  193. });
  194. MWF.xApplication.cms.ColumnManager.ScriptExplorer.Script = new Class({
  195. Extends: MWF.xApplication.cms.ColumnManager.DictionaryExplorer.Dictionary,
  196. _customNodes: function(){
  197. if (!this.data.validated){
  198. new Element("div", {"styles": this.explorer.css.itemErrorNode}).inject(this.node);
  199. this.node.setStyle("background-color", "#f9e8e8");
  200. }
  201. },
  202. _open: function(e){
  203. var _self = this;
  204. var options = {
  205. "onQueryLoad": function(){
  206. this.actions = _self.explorer.actions;
  207. this.category = _self;
  208. this.options.id = _self.data.id;
  209. this.application = _self.explorer.app.options.application || _self.explorer.app.options.column;
  210. this.column = _self.explorer.app.options.application || _self.explorer.app.options.column;
  211. this.explorer = _self.explorer
  212. }
  213. };
  214. this.explorer.app.desktop.openApplication(e, "cms.ScriptDesigner", options);
  215. },
  216. _getIcon: function(){
  217. var x = (Math.random()*33).toInt();
  218. return "process_icon_"+x+".png";
  219. },
  220. _getLnkPar: function(){
  221. return {
  222. "icon": this.explorer.path+this.explorer.options.style+"/scriptIcon/lnk.png",
  223. "title": this.data.name,
  224. "par": "cms.ScriptDesigner#{\"id\": \""+this.data.id+"\", \"application\": "+ JSON.stringify(this.explorer.app.options.application ||this.explorer.app.options.column)+"}"
  225. };
  226. },
  227. // deleteItem: function(e){
  228. // var _self = this;
  229. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  230. // _self.deleteForm();
  231. // this.close();
  232. // },function(){
  233. // this.close();
  234. // });
  235. // },
  236. deleteScript: function(callback){
  237. this.explorer.app.restActions.deleteScript(this.data.id, function(){
  238. this.node.destroy();
  239. if (callback) callback();
  240. }.bind(this));
  241. }
  242. });