QueryStat.js 5.7 KB

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