ScriptExplorer.js 12 KB

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