QueryStat.js 5.6 KB

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