Query.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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": MWF.xApplication.Selector.LP.selectView,
  9. "values": [],
  10. "names": [],
  11. "expand": false,
  12. "forceSearchInItem" : true
  13. },
  14. _init : function(){
  15. this.selectType = "query";
  16. this.className = "Query";
  17. },
  18. loadSelectItems: function(addToNext){
  19. this.queryAction.listApplication(function(json){
  20. if (json.data.length){
  21. json.data.each(function(data){
  22. data.applicationName = data.name;
  23. var item = this._newItem(data, this, this.itemAreaNode);
  24. this.items.push(item);
  25. }.bind(this));
  26. }
  27. }.bind(this));
  28. },
  29. _scrollEvent: function(y){
  30. return true;
  31. },
  32. _getChildrenItemIds: function(data){
  33. return data.viewList || [];
  34. },
  35. _newItemCategory: function(data, selector, item, level){
  36. return false;
  37. },
  38. _listItemByKey: function(callback, failure, key){
  39. return false;
  40. },
  41. _getItem: function(callback, failure, id, async){
  42. this.items.each( function( item ){
  43. if( id == item.data.id ){
  44. if (callback) callback.apply(this, [item.data]);
  45. }
  46. }.bind(this));
  47. //this.queryAction.getView(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.Query.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.Query.Item(data, selector, container, level);
  59. }
  60. });
  61. MWF.xApplication.Selector.Query.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/applicationicon.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.Query.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/applicationicon.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. //
  135. //MWF.xApplication.Selector.Query.ItemCategory = new Class({
  136. // Extends: MWF.xApplication.Selector.Person.ItemCategory,
  137. // _getShowName: function(){
  138. // return this.data.name;
  139. // },
  140. // createNode: function(){
  141. // this.node = new Element("div", {
  142. // "styles": this.selector.css.selectorItemCategory_department
  143. // }).inject(this.container);
  144. // },
  145. // _setIcon: function(){
  146. // this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/applicationicon.png)");
  147. // },
  148. // _hasChild: function(){
  149. // return (this.data.viewList && this.data.viewList.length);
  150. // },
  151. // check: function(){}
  152. //});