CMSCategory.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Identity", null, false);
  3. MWF.xApplication.Selector.CMSCategory = new Class({
  4. Extends: MWF.xApplication.Selector.Identity,
  5. options: {
  6. "style": "default",
  7. "count": 0,
  8. "title": MWF.xApplication.Selector.LP.selectCMSCategory,
  9. "values": [],
  10. "names": [],
  11. "expand": false,
  12. "forceSearchInItem" : true
  13. },
  14. loadSelectItems: function(addToNext){
  15. this.cmsAction.listCMSApplication(function(json){
  16. if (json.data.length){
  17. json.data.each(function(data){
  18. data.name = data.appName;
  19. var category = this._newItemCategory(data, this, this.itemAreaNode);
  20. }.bind(this));
  21. }
  22. }.bind(this));
  23. },
  24. _scrollEvent: function(y){
  25. return true;
  26. },
  27. _getChildrenItemIds: function(){
  28. return null;
  29. },
  30. _newItemCategory: function(data, selector, item, level){
  31. return new MWF.xApplication.Selector.CMSCategory.ItemCategory(data, selector, item, level)
  32. },
  33. _listItemByKey: function(callback, failure, key){
  34. return false;
  35. },
  36. _getItem: function(callback, failure, id, async){
  37. //this.action.getDepartment(function(json){
  38. // if (callback) callback.apply(this, [json]);
  39. //}.bind(this), failure, id, async);
  40. },
  41. _newItemSelected: function(data, selector, item){
  42. return new MWF.xApplication.Selector.CMSCategory.ItemSelected(data, selector, item)
  43. },
  44. _listItemByPinyin: function(callback, failure, key){
  45. return false;
  46. },
  47. _newItem: function(data, selector, container, level){
  48. return new MWF.xApplication.Selector.CMSCategory.Item(data, selector, container, level);
  49. }
  50. });
  51. MWF.xApplication.Selector.CMSCategory.Item = new Class({
  52. Extends: MWF.xApplication.Selector.Identity.Item,
  53. _getShowName: function(){
  54. return this.data.name;
  55. },
  56. _setIcon: function(){
  57. var style = "default";
  58. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/processicon.png)");
  59. },
  60. loadSubItem: function(){
  61. return false;
  62. // this.children = new Element("div", {
  63. // "styles": this.selector.css.selectorItemCategoryChildrenNode
  64. // }).inject(this.node, "after");
  65. // this.children.setStyle("display", "block");
  66. //// if (!this.selector.options.expand) this.children.setStyle("display", "none");
  67. //
  68. // this.selector.action.listProcess(function(subJson){
  69. // subJson.data.each(function(subData){
  70. // var category = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  71. // }.bind(this));
  72. // }.bind(this), null, this.data.id);
  73. },
  74. getData: function(callback){
  75. if (callback) callback();
  76. },
  77. checkSelectedSingle: function(){
  78. var selectedItem = this.selector.options.values.filter(function(item, index){
  79. if (typeOf(item)==="object"){
  80. //return (this.data.id === item.id) || (this.data.name === item.name);
  81. if( this.data.id && item.id ){
  82. return this.data.id === item.id;
  83. }else{
  84. return this.data.name === item.name;
  85. }
  86. }
  87. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  88. return false;
  89. }.bind(this));
  90. if (selectedItem.length){
  91. this.selectedSingle();
  92. }
  93. },
  94. checkSelected: function(){
  95. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  96. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  97. if( item.data.id && this.data.id){
  98. return item.data.id === this.data.id;
  99. }else{
  100. return item.data.name === this.data.name;
  101. }
  102. }.bind(this));
  103. if (selectedItem.length){
  104. //selectedItem[0].item = this;
  105. selectedItem[0].addItem(this);
  106. this.selectedItem = selectedItem[0];
  107. this.setSelected();
  108. }
  109. }
  110. });
  111. MWF.xApplication.Selector.CMSCategory.ItemSelected = new Class({
  112. Extends: MWF.xApplication.Selector.Identity.ItemSelected,
  113. getData: function(callback){
  114. if (callback) callback();
  115. },
  116. _getShowName: function(){
  117. return this.data.name;
  118. },
  119. _setIcon: function(){
  120. var style = "default";
  121. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/processicon.png)");
  122. },
  123. check: function(){
  124. if (this.selector.items.length){
  125. var items = this.selector.items.filter(function(item, index){
  126. if( item.data.id && this.data.id){
  127. return item.data.id === this.data.id;
  128. }else{
  129. return item.data.name === this.data.name;
  130. }
  131. }.bind(this));
  132. this.items = items;
  133. if (items.length){
  134. items.each(function(item){
  135. item.selectedItem = this;
  136. item.setSelected();
  137. }.bind(this));
  138. }
  139. }
  140. }
  141. });
  142. MWF.xApplication.Selector.CMSCategory.ItemCategory = new Class({
  143. Extends: MWF.xApplication.Selector.Identity.ItemCategory,
  144. _setIcon: function(){
  145. var style = "default";
  146. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/applicationicon.png)");
  147. },
  148. loadSub: function(callback){
  149. if (!this.loaded){
  150. this.selector.cmsAction.listCMSCategory(function(subJson){
  151. subJson.data.each(function(subData){
  152. subData.name = subData.categoryName;
  153. subData.applicationName = this.data.name;
  154. subData.application = this.data.id;
  155. var category = this.selector._newItem(subData, this.selector, this.children, this.level+1);
  156. this.selector.items.push( category );
  157. }.bind(this));
  158. this.loaded = true;
  159. if (callback) callback();
  160. }.bind(this), null, this.data.id);
  161. }else{
  162. if (callback) callback();
  163. }
  164. },
  165. _hasChild: function(){
  166. return (this.data.wrapOutCategoryList && this.data.wrapOutCategoryList.length);
  167. },
  168. check: function(){}
  169. });