Query.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.Query = 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 = "query";
  19. this.className = "Query";
  20. },
  21. loadSelectItems: function(addToNext){
  22. this.queryAction.listApplication(function(json){
  23. if (json.data.length){
  24. json.data.each(function(data){
  25. data.applicationName = data.name;
  26. var item = this._newItem(data, this, this.itemAreaNode);
  27. this.items.push(item);
  28. }.bind(this));
  29. }
  30. }.bind(this));
  31. },
  32. _scrollEvent: function(y){
  33. return true;
  34. },
  35. _getChildrenItemIds: function(data){
  36. return data.viewList || [];
  37. },
  38. _newItemCategory: function(data, selector, item, level){
  39. return false;
  40. },
  41. _listItemByKey: function(callback, failure, key){
  42. return false;
  43. },
  44. _getItem: function(callback, failure, id, async){
  45. this.items.each( function( item ){
  46. if( id == item.data.id ){
  47. if (callback) callback.apply(this, [item.data]);
  48. }
  49. }.bind(this));
  50. //this.queryAction.getView(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.Query.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.Query.Item(data, selector, container, level);
  62. }
  63. });
  64. MWF.xApplication.Selector.Query.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/applicationicon.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.Query.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/applicationicon.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. //
  138. //MWF.xApplication.Selector.Query.ItemCategory = new Class({
  139. // Extends: MWF.xApplication.Selector.Person.ItemCategory,
  140. // _getShowName: function(){
  141. // return this.data.name;
  142. // },
  143. // createNode: function(){
  144. // this.node = new Element("div", {
  145. // "styles": this.selector.css.selectorItemCategory_department
  146. // }).inject(this.container);
  147. // },
  148. // _setIcon: function(){
  149. // this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  150. // },
  151. // _hasChild: function(){
  152. // return (this.data.viewList && this.data.viewList.length);
  153. // },
  154. // check: function(){}
  155. //});