QueryStat.js 5.5 KB

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