QueryTable.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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") return (this.data.id === item.id) || (this.data.name === item.name) ;
  75. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  76. return false;
  77. }.bind(this));
  78. if (selectedItem.length){
  79. this.selectedSingle();
  80. }
  81. },
  82. checkSelected: function(){
  83. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  84. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  85. }.bind(this));
  86. if (selectedItem.length){
  87. //selectedItem[0].item = this;
  88. selectedItem[0].addItem(this);
  89. this.selectedItem = selectedItem[0];
  90. this.setSelected();
  91. }
  92. }
  93. });
  94. MWF.xApplication.Selector.QueryTable.ItemSelected = new Class({
  95. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  96. _getShowName: function(){
  97. return this.data.name;
  98. },
  99. _setIcon: function(){
  100. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/table.png)");
  101. },
  102. check: function(){
  103. if (this.selector.items.length){
  104. var items = this.selector.items.filter(function(item, index){
  105. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  106. }.bind(this));
  107. this.items = items;
  108. if (items.length){
  109. items.each(function(item){
  110. item.selectedItem = this;
  111. item.setSelected();
  112. }.bind(this));
  113. }
  114. }
  115. }
  116. });
  117. MWF.xApplication.Selector.QueryTable.ItemCategory = new Class({
  118. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  119. _getShowName: function(){
  120. return this.data.name;
  121. },
  122. createNode: function(){
  123. this.node = new Element("div", {
  124. "styles": this.selector.css.selectorItemCategory_department
  125. }).inject(this.container);
  126. },
  127. _setIcon: function(){
  128. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/applicationicon.png)");
  129. },
  130. _hasChild: function(){
  131. return (this.data.tableList && this.data.tableList.length);
  132. },
  133. check: function(){}
  134. });