CMSCategory.js 5.7 KB

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