DictionaryExplorer.js 16 KB

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