DictionaryExplorer.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. MWF.xDesktop.requireApp("cms.ColumnManager", "Explorer", null, false);
  2. MWF.xApplication.cms.ColumnManager.DictionaryExplorer = new Class({
  3. Extends: MWF.xApplication.cms.ColumnManager.Explorer,
  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.getDictionary(item.data.id, function(json){
  30. json.data.elementType = "dictionary";
  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. // data.each(function(item){
  48. // if (item.elementType==="dictionary"){
  49. // this.saveItemAs(this.app.options.application, item);
  50. // }
  51. // }.bind(this));
  52. },
  53. pasteItem: function(data, i){
  54. if (i<data.length){
  55. var item = data[i];
  56. if (item.elementType==="dictionary"){
  57. this.saveItemAs(item, function(){
  58. i++;
  59. this.pasteItem(data, i);
  60. }.bind(this), function(){
  61. i++;
  62. this.pasteItem(data, i);
  63. }.bind(this), function(){
  64. this.reload();
  65. }.bind(this));
  66. }else{
  67. i++;
  68. this.pasteItem(data, i);
  69. }
  70. }else{
  71. this.reload();
  72. }
  73. },
  74. saveItemAs: function(data, success, failure, cancel){
  75. this.app.restActions.listDictionary(this.app.options.application.id, function(dJson){
  76. var i=1;
  77. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  78. if (someItems.length){
  79. var someItem = someItems[0];
  80. var lp = this.app.lp;
  81. var _self = this;
  82. var d1 = new Date().parse(data.updateTime);
  83. var d2 = new Date().parse(someItem.updateTime);
  84. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  85. 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>";
  86. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.updateTime+"</div>" +
  87. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  88. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  89. 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>";
  90. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.updateTime+"</div>" +
  91. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  92. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  93. // html += "<>"
  94. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  95. {
  96. "text": lp.copyConfirm_overwrite,
  97. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  98. },
  99. {
  100. "text": lp.copyConfirm_new,
  101. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  102. },
  103. {
  104. "text": lp.copyConfirm_skip,
  105. "action": function(){/*nothing*/ this.close(); if (success) success();}
  106. },
  107. {
  108. "text": lp.copyConfirm_cancel,
  109. "action": function(){this.close(); if (cancel) cancel();}
  110. }
  111. ]);
  112. }else{
  113. this.saveItemAsNew(dJson, data, success, failure)
  114. }
  115. }.bind(this), function(){if (failure) failure();}.bind(this));
  116. },
  117. saveItemAsUpdate: function(someItem, data, success, failure){
  118. data.id = someItem.id;
  119. data.application = someItem.application;
  120. data.applicationName = someItem.applicationName;
  121. data.name = someItem.name;
  122. data.alias = someItem.alias;
  123. this.app.restActions.saveDictionary(data, function(){
  124. if (success) success();
  125. }.bind(this), function(){
  126. if (failure) failure();
  127. }.bind(this));
  128. },
  129. saveItemAsNew: function(dJson, data, success, failure){
  130. var item = this.app.options.application;
  131. var id = item.id;
  132. var name = item.name;
  133. var oldName = data.name;
  134. var i=1;
  135. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  136. data.name = oldName+"_copy"+i;
  137. data.alias = oldName+"_copy"+i;
  138. i++;
  139. }
  140. data.id = "";
  141. data.application = id;
  142. data.applicationName = name;
  143. data.appId = id;
  144. data.appName = name;
  145. this.app.restActions.saveDictionary(data, function(){
  146. if (success) success();
  147. }.bind(this), function(){
  148. if (failure) failure();
  149. }.bind(this));
  150. },
  151. _createElement: function(e){
  152. var _self = this;
  153. var options = {
  154. "onQueryLoad": function(){
  155. this.actions = _self.app.restActions;
  156. this.application = _self.app.options.column;
  157. this.column = _self.app.options.column;
  158. },
  159. "onPostSave" : function(){
  160. _self.reload();
  161. }
  162. };
  163. this.app.desktop.openApplication(e, "cms.DictionaryDesigner", options);
  164. },
  165. _loadItemDataList: function(callback){
  166. this.actions.listDictionary(this.app.options.column.id,callback);
  167. },
  168. _getItemObject: function(item, index){
  169. return new MWF.xApplication.cms.ColumnManager.DictionaryExplorer.Dictionary(this, item, {index : index})
  170. },
  171. setTooltip: function(){
  172. this.options.tooltip = {
  173. "create": MWF.CMSCM.LP.dictionary.create,
  174. "search": MWF.CMSCM.LP.dictionary.search,
  175. "searchText": MWF.CMSCM.LP.dictionary.searchText,
  176. "noElement": MWF.CMSCM.LP.dictionary.noDictionaryNoticeText
  177. };
  178. },
  179. loadElementList: function(callback){
  180. this._loadItemDataList(function(json){
  181. if (json.data.length){
  182. json.data.each(function(item){
  183. var itemObj = this._getItemObject(item, this.itemArray.length + 1);
  184. itemObj.load();
  185. this.itemObject[ item.id ] = itemObj;
  186. this.itemArray.push( itemObj );
  187. }.bind(this));
  188. if( callback )callback();
  189. }else{
  190. var noElementNode = new Element("div", {
  191. "styles": this.css.noElementNode,
  192. "text": (this.options.noCreate) ? MWF.CMSCM.LP.dictionary.noDictionaryNoCreateNoticeText : this.options.tooltip.noElement
  193. }).inject(this.elementContentListNode);
  194. if (!this.options.noCreate){
  195. noElementNode.addEvent("click", function(e){
  196. this._createElement(e);
  197. }.bind(this));
  198. }
  199. }
  200. }.bind(this));
  201. },
  202. deleteItems: function(){
  203. while (this.deleteMarkItems.length){
  204. var item = this.deleteMarkItems.shift();
  205. if (this.deleteMarkItems.length){
  206. item.deleteDictionary();
  207. }else{
  208. item.deleteDictionary(function(){
  209. // this.reloadItems();
  210. this.hideDeleteAction();
  211. this.reload();
  212. }.bind(this));
  213. }
  214. }
  215. }
  216. });
  217. MWF.xApplication.cms.ColumnManager.DictionaryExplorer.Dictionary = new Class({
  218. Extends: MWF.xApplication.cms.ColumnManager.Explorer.Item,
  219. _customNodes: function(){},
  220. _open: function(e){
  221. var _self = this;
  222. var options = {
  223. "onQueryLoad": function(){
  224. this.actions = _self.explorer.actions;
  225. this.category = _self;
  226. this.options.id = _self.data.id;
  227. this.column = _self.explorer.app.options.column;
  228. this.application = _self.explorer.app.options.column;
  229. this.options.noModifyName = _self.explorer.options.noModifyName;
  230. this.options.readMode = _self.explorer.options.readMode
  231. }
  232. };
  233. this.explorer.app.desktop.openApplication(e, "cms.DictionaryDesigner", options);
  234. },
  235. _getIcon: function(){
  236. var x = (Math.random()*33).toInt();
  237. return "process_icon_"+x+".png";
  238. },
  239. _getLnkPar: function(){
  240. var par = {
  241. "icon": this.explorer.path+this.explorer.options.style+"/dictionaryIcon/lnk.png",
  242. "title": this.data.name,
  243. "par": "cms.DictionaryDesigner#{\"id\": \""+this.data.id +"\", \"application\" : "+ JSON.stringify(this.explorer.app.options.column) +"}"
  244. };
  245. return par
  246. },
  247. // deleteItem: function(e){
  248. // var _self = this;
  249. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  250. // _self.deleteForm();
  251. // this.close();
  252. // },function(){
  253. // this.close();
  254. // });
  255. // },
  256. deleteDictionary: function(callback){
  257. this.explorer.app.restActions.deleteDictionary(this.data.id, function(){
  258. this.node.destroy();
  259. if (callback) callback();
  260. }.bind(this));
  261. }
  262. });