QueryView.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  3. MWF.xApplication.Selector.QueryView = 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 = "queryview";
  19. this.className = "QueryView";
  20. },
  21. loadSelectItems: function(addToNext){
  22. this.queryAction.listApplication(function(json){
  23. if (json.data.length){
  24. json.data.each(function(data){
  25. if (data.viewList && data.viewList.length){
  26. var category = this._newItemCategory(data, this, this.itemAreaNode);
  27. data.viewList.each(function(d){
  28. d.applicationName = data.name;
  29. var item = this._newItem(d, this, category.children);
  30. this.items.push(item);
  31. }.bind(this));
  32. }
  33. }.bind(this));
  34. }
  35. }.bind(this));
  36. },
  37. _scrollEvent: function(y){
  38. return true;
  39. },
  40. _getChildrenItemIds: function(data){
  41. return data.viewList || [];
  42. },
  43. _newItemCategory: function(data, selector, item, level){
  44. return new MWF.xApplication.Selector.QueryView.ItemCategory(data, selector, item, level)
  45. },
  46. _listItemByKey: function(callback, failure, key){
  47. return false;
  48. },
  49. _getItem: function(callback, failure, id, async){
  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.QueryView.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.QueryView.Item(data, selector, container, level);
  62. }
  63. });
  64. MWF.xApplication.Selector.QueryView.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/view.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)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  86. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  87. return false;
  88. }.bind(this));
  89. if (selectedItem.length){
  90. this.selectedSingle();
  91. }
  92. },
  93. checkSelected: function(){
  94. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  95. if( item.data.id && this.data.id){
  96. return item.data.id === this.data.id;
  97. }else{
  98. return item.data.name === this.data.name;
  99. }
  100. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  101. }.bind(this));
  102. if (selectedItem.length){
  103. //selectedItem[0].item = this;
  104. selectedItem[0].addItem(this);
  105. this.selectedItem = selectedItem[0];
  106. this.setSelected();
  107. }
  108. }
  109. });
  110. MWF.xApplication.Selector.QueryView.ItemSelected = new Class({
  111. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  112. _getShowName: function(){
  113. return this.data.name;
  114. },
  115. _setIcon: function(){
  116. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/default/icon/view.png)");
  117. },
  118. check: function(){
  119. if (this.selector.items.length){
  120. var items = this.selector.items.filter(function(item, index){
  121. //return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  122. if( item.data.id && this.data.id){
  123. return item.data.id === this.data.id;
  124. }else{
  125. return item.data.name === this.data.name;
  126. }
  127. }.bind(this));
  128. this.items = items;
  129. if (items.length){
  130. items.each(function(item){
  131. item.selectedItem = this;
  132. item.setSelected();
  133. }.bind(this));
  134. }
  135. }
  136. }
  137. });
  138. MWF.xApplication.Selector.QueryView.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. });