DictionaryExplorer.js 17 KB

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