DictionaryExplorer.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. initialize: function(node, actions, options){
  12. this.setOptions(options);
  13. this.setTooltip();
  14. this.path = "/x_component_cms_ColumnManager/$DictionaryExplorer/";
  15. this.cssPath = "/x_component_cms_ColumnManager/$DictionaryExplorer/"+this.options.style+"/css.wcss";
  16. this._loadCss();
  17. this.actions = actions;
  18. this.node = $(node);
  19. this.initData();
  20. },
  21. setContentSize: function(){
  22. var toolbarSize = this.toolbarNode.getSize();
  23. var nodeSize = this.node.getSize();
  24. var pt = this.elementContentNode.getStyle("padding-top").toFloat();
  25. var pb = this.elementContentNode.getStyle("padding-bottom").toFloat();
  26. var height = nodeSize.y-toolbarSize.y-pt-pb;
  27. this.elementContentNode.setStyle("height", ""+height+"px");
  28. if (this.options.noCreate) this.createElementNode.destroy();
  29. },
  30. showDeleteAction: function(){
  31. if (!this.deleteItemsAction){
  32. this.deleteItemsAction = new Element("div", {
  33. "styles": this.css.deleteItemsAction,
  34. "text": this.app.lp.deleteItems
  35. }).inject(this.node);
  36. this.deleteItemsAction.fade("in");
  37. this.deleteItemsAction.position({
  38. relativeTo: this.elementContentListNode,
  39. position: 'centerTop',
  40. edge: 'centerTop'
  41. });
  42. this.deleteItemsAction.addEvent("click", function(){
  43. var _self = this;
  44. this.app.confirm("warn", this.deleteItemsAction, MWF.CMSCM.LP.deleteElementTitle, MWF.CMSCM.LP.deleteElement, 300, 120, function(){
  45. _self.deleteItems();
  46. this.close();
  47. }, function(){
  48. this.close();
  49. });
  50. }.bind(this));
  51. }
  52. },
  53. _createElement: function(e){
  54. var _self = this;
  55. var options = {
  56. "onQueryLoad": function(){
  57. this.actions = _self.app.restActions;
  58. this.application = _self.app.options.column;
  59. this.column = _self.app.options.column;
  60. },
  61. "onPostSave" : function(){
  62. _self.reload();
  63. }
  64. };
  65. this.app.desktop.openApplication(e, "cms.DictionaryDesigner", options);
  66. },
  67. _loadItemDataList: function(callback){
  68. this.actions.listDictionary(this.app.options.column.id,callback);
  69. },
  70. _getItemObject: function(item){
  71. return new MWF.xApplication.cms.ColumnManager.DictionaryExplorer.Dictionary(this, item)
  72. },
  73. setTooltip: function(){
  74. this.options.tooltip = {
  75. "create": MWF.CMSCM.LP.dictionary.create,
  76. "search": MWF.CMSCM.LP.dictionary.search,
  77. "searchText": MWF.CMSCM.LP.dictionary.searchText,
  78. "noElement": MWF.CMSCM.LP.dictionary.noDictionaryNoticeText
  79. };
  80. },
  81. loadElementList: function(){
  82. this._loadItemDataList(function(json){
  83. if (json.data.length){
  84. json.data.each(function(item){
  85. var itemObj = this._getItemObject(item);
  86. itemObj.load();
  87. this.itemObject[ item.id ] = itemObj;
  88. this.itemArray.push( itemObj );
  89. }.bind(this));
  90. }else{
  91. var noElementNode = new Element("div", {
  92. "styles": this.css.noElementNode,
  93. "text": (this.options.noCreate) ? MWF.CMSCM.LP.dictionary.noDictionaryNoCreateNoticeText : this.options.tooltip.noElement
  94. }).inject(this.elementContentListNode);
  95. if (!this.options.noCreate){
  96. noElementNode.addEvent("click", function(e){
  97. this._createElement(e);
  98. }.bind(this));
  99. }
  100. }
  101. }.bind(this));
  102. },
  103. deleteItems: function(){
  104. while (this.deleteMarkItems.length){
  105. var item = this.deleteMarkItems.shift();
  106. if (this.deleteMarkItems.length){
  107. item.deleteDictionary();
  108. }else{
  109. item.deleteDictionary(function(){
  110. // this.reloadItems();
  111. this.hideDeleteAction();
  112. this.reload();
  113. }.bind(this));
  114. }
  115. }
  116. }
  117. });
  118. MWF.xApplication.cms.ColumnManager.DictionaryExplorer.Dictionary = new Class({
  119. Extends: MWF.xApplication.cms.ColumnManager.Explorer.Item,
  120. load: function(){
  121. this.node = new Element("div", {
  122. "styles": this.explorer.css.itemNode,
  123. "events": {
  124. "mouseover": function(){if (this.deleteActionNode) this.deleteActionNode.fade("in");}.bind(this),
  125. "mouseout": function(){if (this.deleteActionNode) this.deleteActionNode.fade("out");}.bind(this)
  126. }
  127. }).inject(this.container);
  128. if (this.data.name.icon) this.icon = this.data.name.icon;
  129. var iconUrl = this.explorer.path+""+this.explorer.options.style+"/processIcon/"+this.icon;
  130. var itemIconNode = new Element("div", {
  131. "styles": this.explorer.css.itemIconNode
  132. }).inject(this.node);
  133. itemIconNode.setStyle("background", "url("+iconUrl+") center center no-repeat");
  134. //new Element("img", {
  135. // "src": iconUrl, "border": "0"
  136. //}).inject(itemIconNode);
  137. itemIconNode.makeLnk({
  138. "par": this._getLnkPar()
  139. });
  140. if (!this.explorer.options.noDelete){
  141. this.deleteActionNode = new Element("div", {
  142. "styles": this.explorer.css.deleteActionNode
  143. }).inject(this.node);
  144. this.deleteActionNode.addEvent("click", function(e){
  145. this.deleteItem(e);
  146. }.bind(this));
  147. }
  148. var inforNode = new Element("div", {
  149. "styles": this.explorer.css.itemInforNode
  150. }).inject(this.node);
  151. var inforBaseNode = new Element("div", {
  152. "styles": this.explorer.css.itemInforBaseNode
  153. }).inject(inforNode);
  154. new Element("div", {
  155. "styles": this.explorer.css.itemTextTitleNode,
  156. "text": this.data.name,
  157. "title": this.data.name,
  158. "events": {
  159. "click": function(e){this._open(e);e.stopPropagation();}.bind(this)
  160. }
  161. }).inject(inforBaseNode);
  162. new Element("div", {
  163. "styles": this.explorer.css.itemTextAliasNode,
  164. "text": this.data.alias,
  165. "title": this.data.alias
  166. }).inject(inforBaseNode);
  167. new Element("div", {
  168. "styles": this.explorer.css.itemTextDateNode,
  169. "text": (this.data.updateTime || "")
  170. }).inject(inforBaseNode);
  171. new Element("div", {
  172. "styles": this.explorer.css.itemTextDescriptionNode,
  173. "text": this.data.description || "",
  174. "title": this.data.description || ""
  175. }).inject(inforNode);
  176. this._customNodes();
  177. this._isNew();
  178. },
  179. _customNodes: function(){},
  180. _open: function(e){
  181. var _self = this;
  182. var options = {
  183. "onQueryLoad": function(){
  184. this.actions = _self.explorer.actions;
  185. this.category = _self;
  186. this.options.id = _self.data.id;
  187. this.column = _self.explorer.app.options.column;
  188. this.application = _self.explorer.app.options.column;
  189. this.options.noModifyName = _self.explorer.options.noModifyName;
  190. this.options.readMode = _self.explorer.options.readMode
  191. }
  192. };
  193. this.explorer.app.desktop.openApplication(e, "cms.DictionaryDesigner", options);
  194. },
  195. _getIcon: function(){
  196. var x = (Math.random()*33).toInt();
  197. return "process_icon_"+x+".png";
  198. },
  199. _getLnkPar: function(){
  200. return {
  201. "icon": this.explorer.path+this.explorer.options.style+"/dictionaryIcon/lnk.png",
  202. "title": this.data.name,
  203. "par": "cms.DictionaryDesigner#{\"id\": \""+this.data.id+"\"}"
  204. };
  205. },
  206. // deleteItem: function(e){
  207. // var _self = this;
  208. // this.explorer.app.confirm("info", e, this.explorer.app.lp.form.deleteFormTitle, this.explorer.app.lp.form.deleteForm, 320, 110, function(){
  209. // _self.deleteForm();
  210. // this.close();
  211. // },function(){
  212. // this.close();
  213. // });
  214. // },
  215. deleteDictionary: function(callback){
  216. this.explorer.app.restActions.deleteDictionary(this.data.id, function(){
  217. this.node.destroy();
  218. if (callback) callback();
  219. }.bind(this));
  220. }
  221. });