Query.js 5.2 KB

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