Query.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. loadSelectItems: function(addToNext){
  15. this.queryAction.listApplication(function(json){
  16. if (json.data.length){
  17. json.data.each(function(data){
  18. data.applicationName = data.name;
  19. var item = this._newItem(data, this, this.itemAreaNode);
  20. this.items.push(item);
  21. }.bind(this));
  22. }
  23. }.bind(this));
  24. },
  25. _scrollEvent: function(y){
  26. return true;
  27. },
  28. _getChildrenItemIds: function(data){
  29. return data.viewList || [];
  30. },
  31. _newItemCategory: function(data, selector, item, level){
  32. return false;
  33. },
  34. _listItemByKey: function(callback, failure, key){
  35. return false;
  36. },
  37. _getItem: function(callback, failure, id, async){
  38. this.items.each( function( item ){
  39. if( id == item.data.id ){
  40. if (callback) callback.apply(this, [item.data]);
  41. }
  42. }.bind(this));
  43. //this.queryAction.getView(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.Query.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.Query.Item(data, selector, container, level);
  55. }
  56. });
  57. MWF.xApplication.Selector.Query.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/applicationicon.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.Query.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/applicationicon.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. //
  131. //MWF.xApplication.Selector.Query.ItemCategory = new Class({
  132. // Extends: MWF.xApplication.Selector.Person.ItemCategory,
  133. // _getShowName: function(){
  134. // return this.data.name;
  135. // },
  136. // createNode: function(){
  137. // this.node = new Element("div", {
  138. // "styles": this.selector.css.selectorItemCategory_department
  139. // }).inject(this.container);
  140. // },
  141. // _setIcon: function(){
  142. // this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/applicationicon.png)");
  143. // },
  144. // _hasChild: function(){
  145. // return (this.data.viewList && this.data.viewList.length);
  146. // },
  147. // check: function(){}
  148. //});