CMSCategory.js 6.7 KB

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