QueryTable.js 6.3 KB

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