QueryTable.js 5.7 KB

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