DictionaryExplorer.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. _createElement: function(e){
  12. var _self = this;
  13. var options = {
  14. "onQueryLoad": function(){
  15. this.actions = _self.app.restActions;
  16. this.application = _self.app.options.column;
  17. this.column = _self.app.options.column;
  18. },
  19. "onPostSave" : function(){
  20. _self.reload();
  21. }
  22. };
  23. this.app.desktop.openApplication(e, "cms.DictionaryDesigner", options);
  24. },
  25. _loadItemDataList: function(callback){
  26. this.actions.listDictionary(this.app.options.column.id,callback);
  27. },
  28. _getItemObject: function(item, index){
  29. return new MWF.xApplication.cms.ColumnManager.DictionaryExplorer.Dictionary(this, item, {index : index})
  30. },
  31. setTooltip: function(){
  32. this.options.tooltip = {
  33. "create": MWF.CMSCM.LP.dictionary.create,
  34. "search": MWF.CMSCM.LP.dictionary.search,
  35. "searchText": MWF.CMSCM.LP.dictionary.searchText,
  36. "noElement": MWF.CMSCM.LP.dictionary.noDictionaryNoticeText
  37. };
  38. },
  39. loadElementList: function(callback){
  40. this._loadItemDataList(function(json){
  41. if (json.data.length){
  42. json.data.each(function(item){
  43. var itemObj = this._getItemObject(item, this.itemArray.length + 1);
  44. itemObj.load();
  45. this.itemObject[ item.id ] = itemObj;
  46. this.itemArray.push( itemObj );
  47. }.bind(this));
  48. if( callback )callback();
  49. }else{
  50. var noElementNode = new Element("div", {
  51. "styles": this.css.noElementNode,
  52. "text": (this.options.noCreate) ? MWF.CMSCM.LP.dictionary.noDictionaryNoCreateNoticeText : this.options.tooltip.noElement
  53. }).inject(this.elementContentListNode);
  54. if (!this.options.noCreate){
  55. noElementNode.addEvent("click", function(e){
  56. this._createElement(e);
  57. }.bind(this));
  58. }
  59. }
  60. }.bind(this));
  61. },
  62. deleteItems: function(){
  63. while (this.deleteMarkItems.length){
  64. var item = this.deleteMarkItems.shift();
  65. if (this.deleteMarkItems.length){
  66. item.deleteDictionary();
  67. }else{
  68. item.deleteDictionary(function(){
  69. // this.reloadItems();
  70. this.hideDeleteAction();
  71. this.reload();
  72. }.bind(this));
  73. }
  74. }
  75. },
  76. keyCopy: function(e){
  77. if (this.selectMarkItems.length){
  78. var items = [];
  79. var i = 0;
  80. var checkItems = function(e){
  81. if (i>=this.selectMarkItems.length){
  82. if (items.length){
  83. var str = JSON.encode(items);
  84. if (e){
  85. e.clipboardData.setData('text/plain', str);
  86. }else {
  87. window.clipboardData.setData("Text", str);
  88. }
  89. this.app.notice(this.app.lp.copyed, "success");
  90. }
  91. }
  92. }.bind(this);
  93. this.selectMarkItems.each(function(item){
  94. this.app.restActions.getDictionary(item.data.id, function(json){
  95. json.data.elementType = "dictionary";
  96. items.push(json.data);
  97. i++;
  98. checkItems(e);
  99. }.bind(this), null, false)
  100. }.bind(this));
  101. }
  102. },
  103. keyPaste: function(e){
  104. var dataStr = "";
  105. if (e){
  106. dataStr = e.clipboardData.getData('text/plain');
  107. }else{
  108. dataStr = window.clipboardData.getData("Text");
  109. }
  110. var data = JSON.decode(dataStr);
  111. this.pasteItem(data, 0);
  112. // data.each(function(item){
  113. // if (item.elementType==="dictionary"){
  114. // this.saveItemAs(this.app.options.application, item);
  115. // }
  116. // }.bind(this));
  117. },
  118. pasteItem: function(data, i){
  119. if (i<data.length){
  120. var item = data[i];
  121. if (item.elementType==="dictionary"){
  122. this.saveItemAs(item, function(){
  123. i++;
  124. this.pasteItem(data, i);
  125. }.bind(this), function(){
  126. i++;
  127. this.pasteItem(data, i);
  128. }.bind(this), function(){
  129. this.reload();
  130. }.bind(this));
  131. }else{
  132. i++;
  133. this.pasteItem(data, i);
  134. }
  135. }else{
  136. this.reload();
  137. }
  138. },
  139. saveItemAs: function(data, success, failure, cancel){
  140. this.app.restActions.listDictionary(this.app.options.application.id, function(dJson){
  141. dJson.data = dJson.data || [];
  142. var i=1;
  143. var someItems = dJson.data.filter(function(d){ return d.id===data.id });
  144. if (someItems.length){
  145. var someItem = someItems[0];
  146. var lp = this.app.lp;
  147. var _self = this;
  148. var d1 = new Date().parse(data.updateTime);
  149. var d2 = new Date().parse(someItem.updateTime);
  150. var html = "<div>"+lp.copyConfirmInfor+"</div>";
  151. 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>";
  152. html += "<div style='font-size:12px; color: #666666; float: left'>"+someItem.updateTime+"</div>" +
  153. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  154. "<div style='color: red; float: right;'>"+((d1>=d2) ? "": lp.copynew)+"</div></div>";
  155. 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>";
  156. html += "<div style='font-size:12px; color: #666666; float: left;'>"+data.updateTime+"</div>" +
  157. "<div style='font-size:12px; color: #666666; float: left; margin-left: 20px;'></div>" +
  158. "<div style='color: red; float: right;'>"+((d1<=d2) ? "": lp.copynew)+"</div></div>";
  159. // html += "<>"
  160. this.app.dlg("inofr", null, this.app.lp.copyConfirmTitle, {"html": html}, 500, 290, [
  161. {
  162. "text": lp.copyConfirm_overwrite,
  163. "action": function(){_self.saveItemAsUpdate(someItem, data, success, failure);this.close();}
  164. },
  165. {
  166. "text": lp.copyConfirm_new,
  167. "action": function(){_self.saveItemAsNew(dJson, data, success, failure);this.close();}
  168. },
  169. {
  170. "text": lp.copyConfirm_skip,
  171. "action": function(){/*nothing*/ this.close(); if (success) success();}
  172. },
  173. {
  174. "text": lp.copyConfirm_cancel,
  175. "action": function(){this.close(); if (cancel) cancel();}
  176. }
  177. ]);
  178. }else{
  179. this.saveItemAsNew(dJson, data, success, failure)
  180. }
  181. }.bind(this), function(){if (failure) failure();}.bind(this));
  182. },
  183. saveItemAsUpdate: function(someItem, data, success, failure){
  184. data.id = someItem.id;
  185. data.application = someItem.appId || someItem.application ;
  186. data.applicationName = someItem.appName || someItem.applicationName;
  187. data.appId = data.application;
  188. data.appName = data.applicationName;
  189. data.name = someItem.name;
  190. data.alias = someItem.alias;
  191. this.app.restActions.saveDictionary(data, function(){
  192. if (success) success();
  193. }.bind(this), function(){
  194. if (failure) failure();
  195. }.bind(this));
  196. },
  197. saveItemAsNew: function(dJson, data, success, failure){
  198. var item = this.app.options.application;
  199. var id = item.id;
  200. var name = item.name;
  201. var oldName = data.name;
  202. var i=1;
  203. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  204. data.name = oldName+"_copy"+i;
  205. data.alias = oldName+"_copy"+i;
  206. i++;
  207. }
  208. data.id = "";
  209. data.application = id;
  210. data.applicationName = name;
  211. data.appId = id;
  212. data.appName = name;
  213. delete data.createTime;
  214. delete data.updateTime;
  215. delete data.elementType;
  216. this.app.restActions.saveDictionary(data, function(){
  217. if (success) success();
  218. }.bind(this), function(){
  219. if (failure) failure();
  220. }.bind(this));
  221. }
  222. });
  223. MWF.xApplication.cms.ColumnManager.DictionaryExplorer.Dictionary = new Class({
  224. Extends: MWF.xApplication.cms.ColumnManager.Explorer.Item,
  225. //load: function(){
  226. // if( this.options.index % 2 == 0 ){
  227. // this.itemNodeCss = this.explorer.css.itemNode_even
  228. // }else{
  229. // this.itemNodeCss = this.explorer.css.itemNode
  230. // }
  231. // this.node = new Element("div", {
  232. // "styles": this.itemNodeCss,
  233. // "events": {
  234. // "click": function(e){this._open(e);e.stopPropagation();}.bind(this),
  235. // "mouseover": function(){
  236. // if( !this.isSelected )this.node.setStyles( this.explorer.css.itemNode_over )
  237. // }.bind(this),
  238. // "mouseout": function(){
  239. // if( !this.isSelected )this.node.setStyles( this.itemNodeCss )
  240. // }.bind(this)
  241. // }
  242. // }).inject(this.container,this.options.where);
  243. //
  244. //
  245. // if (this.data.icon) this.icon = this.data.icon;
  246. // var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  247. //
  248. // var itemIconNode = new Element("div", {
  249. // "styles": this.explorer.css.itemIconNode
  250. // }).inject(this.node);
  251. // itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  252. // //new Element("img", {
  253. // // "src": iconUrl, "border": "0"
  254. // //}).inject(itemIconNode);
  255. //
  256. // itemIconNode.makeLnk({
  257. // "par": this._getLnkPar()
  258. // });
  259. //
  260. // itemIconNode.addEvent("click", function(e){
  261. // this.toggleSelected();
  262. // e.stopPropagation();
  263. // }.bind(this));
  264. //
  265. // this.actionsArea = new Element("div.actionsArea",{
  266. // styles : this.explorer.css.actionsArea
  267. // }).inject(this.node);
  268. // if (!this.explorer.options.noDelete){
  269. // this.deleteActionNode = new Element("div.deleteAction", {
  270. // "styles": this.explorer.css.deleteAction
  271. // }).inject(this.actionsArea);
  272. // this.deleteActionNode.addEvent("click", function(e){
  273. // this.deleteItem(e);
  274. // e.stopPropagation();
  275. // }.bind(this));
  276. // this.deleteActionNode.addEvents({
  277. // "mouseover" : function(ev){
  278. // this.deleteActionNode.setStyles( this.explorer.css.deleteAction_over )
  279. // }.bind(this),
  280. // "mouseout" : function(ev){
  281. // this.deleteActionNode.setStyles( this.explorer.css.deleteAction )
  282. // }.bind(this)
  283. // })
  284. // }
  285. //
  286. //
  287. // var inforNode = new Element("div.itemInforNode", {
  288. // "styles": this.explorer.css.itemInforNode
  289. // }).inject(this.node);
  290. // var inforBaseNode = new Element("div.itemInforBaseNode", {
  291. // "styles": this.explorer.css.itemInforBaseNode
  292. // }).inject(inforNode);
  293. //
  294. // new Element("div.itemTextTitleNode", {
  295. // "styles": this.explorer.css.itemTextTitleNode,
  296. // "text": this.data.name,
  297. // "title": this.data.name
  298. // }).inject(inforBaseNode);
  299. //
  300. // new Element("div.itemTextAliasNode", {
  301. // "styles": this.explorer.css.itemTextAliasNode,
  302. // "text": this.data.alias,
  303. // "title": this.data.alias
  304. // }).inject(inforBaseNode);
  305. // new Element("div.itemTextDateNode", {
  306. // "styles": this.explorer.css.itemTextDateNode,
  307. // "text": (this.data.updateTime || "")
  308. // }).inject(inforBaseNode);
  309. //
  310. // new Element("div.itemTextDescriptionNode", {
  311. // "styles": this.explorer.css.itemTextDescriptionNode,
  312. // "text": this.data.description || "",
  313. // "title": this.data.description || ""
  314. // }).inject(inforBaseNode);
  315. //
  316. //
  317. //},
  318. _customNodes: function(){},
  319. _open: function(e){
  320. var _self = this;
  321. var options = {
  322. "onQueryLoad": function(){
  323. this.actions = _self.explorer.actions;
  324. this.category = _self;
  325. this.options.id = _self.data.id;
  326. this.column = _self.explorer.app.options.column;
  327. this.application = _self.explorer.app.options.column;
  328. this.options.noModifyName = _self.explorer.options.noModifyName;
  329. this.options.readMode = _self.explorer.options.readMode
  330. }
  331. };
  332. this.explorer.app.desktop.openApplication(e, "cms.DictionaryDesigner", options);
  333. },
  334. _getIcon: function(){
  335. var x = (Math.random()*33).toInt();
  336. return "process_icon_"+x+".png";
  337. },
  338. _getLnkPar: function(){
  339. var par = {
  340. "icon": this.explorer.path+this.explorer.options.style+"/dictionaryIcon/lnk.png",
  341. "title": this.data.name,
  342. "par": "cms.DictionaryDesigner#{\"id\": \""+this.data.id +"\", \"application\" : "+ JSON.stringify(this.explorer.app.options.column) +"}"
  343. };
  344. return par
  345. },
  346. // deleteItem: function(e){
  347. // var _self = this;
  348. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  349. // _self.deleteForm();
  350. // this.close();
  351. // },function(){
  352. // this.close();
  353. // });
  354. // },
  355. deleteDictionary: function(callback){
  356. this.explorer.app.restActions.removeDictionary(this.data.id, function(){
  357. this.node.destroy();
  358. if (callback) callback();
  359. }.bind(this));
  360. },
  361. saveItemAs: function(item){
  362. var id = item.id;
  363. var name = item.name || item.appName;
  364. this.explorer.app.restActions.getDictionary(this.data.id, function(json){
  365. var data = json.data;
  366. var oldName = data.name;
  367. this.explorer.app.restActions.listDictionary(id, function(dJson){
  368. dJson.data = dJson.data || [];
  369. var i=1;
  370. while (dJson.data.some(function(d){ return d.name==data.name || d.alias==data.name })){
  371. data.name = oldName+"_copy"+i;
  372. data.alias = oldName+"_copy"+i;
  373. i++;
  374. }
  375. data.id = "";
  376. data.appId = id;
  377. data.appName = name;
  378. data.application = id;
  379. data.applicationName = name;
  380. delete data.createTime;
  381. delete data.updateTime;
  382. this.explorer.app.restActions.saveDictionary(data, function(){
  383. if (id == this.explorer.app.options.application.id) this.explorer.reload();
  384. }.bind(this));
  385. }.bind(this));
  386. }.bind(this));
  387. }
  388. });