QueryView.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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": 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. if (data.viewList && data.viewList.length){
  18. var category = this._newItemCategory(data, this, this.itemAreaNode);
  19. data.viewList.each(function(d){
  20. d.applicationName = data.name;
  21. var item = this._newItem(d, this, category.children);
  22. this.items.push(item);
  23. }.bind(this));
  24. }
  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 new MWF.xApplication.Selector.QueryView.ItemCategory(data, selector, item, level)
  37. },
  38. _listItemByKey: function(callback, failure, key){
  39. return false;
  40. },
  41. _getItem: function(callback, failure, id, async){
  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.QueryView.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.QueryView.Item(data, selector, container, level);
  54. }
  55. });
  56. MWF.xApplication.Selector.QueryView.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/view.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)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  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.QueryView.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/view.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. }.bind(this));
  115. this.items = items;
  116. if (items.length){
  117. items.each(function(item){
  118. item.selectedItem = this;
  119. item.setSelected();
  120. }.bind(this));
  121. }
  122. }
  123. }
  124. });
  125. MWF.xApplication.Selector.QueryView.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. });