QueryTable.js 5.9 KB

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