CMSCategory.js 6.6 KB

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