/ext-4.0.7/src/grid/LockingView.js

https://bitbucket.org/srogerf/javascript · JavaScript · 184 lines · 130 code · 31 blank · 23 comment · 12 complexity · a729dd143aa7210b403f89f6afb1db73 MD5 · raw file

  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. /**
  10. * @class Ext.grid.LockingView
  11. * This class is used internally to provide a single interface when using
  12. * a locking grid. Internally, the locking grid creates two separate grids,
  13. * so this class is used to map calls appropriately.
  14. * @ignore
  15. */
  16. Ext.define('Ext.grid.LockingView', {
  17. mixins: {
  18. observable: 'Ext.util.Observable'
  19. },
  20. eventRelayRe: /^(beforeitem|beforecontainer|item|container|cell)/,
  21. constructor: function(config){
  22. var me = this,
  23. eventNames = [],
  24. eventRe = me.eventRelayRe,
  25. locked = config.locked.getView(),
  26. normal = config.normal.getView(),
  27. events,
  28. event;
  29. Ext.apply(me, {
  30. lockedView: locked,
  31. normalView: normal,
  32. lockedGrid: config.locked,
  33. normalGrid: config.normal,
  34. panel: config.panel
  35. });
  36. me.mixins.observable.constructor.call(me, config);
  37. // relay events
  38. events = locked.events;
  39. for (event in events) {
  40. if (events.hasOwnProperty(event) && eventRe.test(event)) {
  41. eventNames.push(event);
  42. }
  43. }
  44. me.relayEvents(locked, eventNames);
  45. me.relayEvents(normal, eventNames);
  46. normal.on({
  47. scope: me,
  48. itemmouseleave: me.onItemMouseLeave,
  49. itemmouseenter: me.onItemMouseEnter
  50. });
  51. locked.on({
  52. scope: me,
  53. itemmouseleave: me.onItemMouseLeave,
  54. itemmouseenter: me.onItemMouseEnter
  55. });
  56. },
  57. getGridColumns: function() {
  58. var cols = this.lockedGrid.headerCt.getGridColumns();
  59. return cols.concat(this.normalGrid.headerCt.getGridColumns());
  60. },
  61. getEl: function(column){
  62. return this.getViewForColumn(column).getEl();
  63. },
  64. getViewForColumn: function(column) {
  65. var view = this.lockedView,
  66. inLocked;
  67. view.headerCt.cascade(function(col){
  68. if (col === column) {
  69. inLocked = true;
  70. return false;
  71. }
  72. });
  73. return inLocked ? view : this.normalView;
  74. },
  75. onItemMouseEnter: function(view, record){
  76. var me = this,
  77. locked = me.lockedView,
  78. other = me.normalView,
  79. item;
  80. if (view.trackOver) {
  81. if (view !== locked) {
  82. other = locked;
  83. }
  84. item = other.getNode(record);
  85. other.highlightItem(item);
  86. }
  87. },
  88. onItemMouseLeave: function(view, record){
  89. var me = this,
  90. locked = me.lockedView,
  91. other = me.normalView;
  92. if (view.trackOver) {
  93. if (view !== locked) {
  94. other = locked;
  95. }
  96. other.clearHighlight();
  97. }
  98. },
  99. relayFn: function(name, args){
  100. args = args || [];
  101. var view = this.lockedView;
  102. view[name].apply(view, args || []);
  103. view = this.normalView;
  104. view[name].apply(view, args || []);
  105. },
  106. getSelectionModel: function(){
  107. return this.panel.getSelectionModel();
  108. },
  109. getStore: function(){
  110. return this.panel.store;
  111. },
  112. getNode: function(nodeInfo){
  113. // default to the normal view
  114. return this.normalView.getNode(nodeInfo);
  115. },
  116. getCell: function(record, column){
  117. var view = this.getViewForColumn(column),
  118. row;
  119. row = view.getNode(record);
  120. return Ext.fly(row).down(column.getCellSelector());
  121. },
  122. getRecord: function(node){
  123. var result = this.lockedView.getRecord(node);
  124. if (!node) {
  125. result = this.normalView.getRecord(node);
  126. }
  127. return result;
  128. },
  129. addElListener: function(eventName, fn, scope){
  130. this.relayFn('addElListener', arguments);
  131. },
  132. refreshNode: function(){
  133. this.relayFn('refreshNode', arguments);
  134. },
  135. refresh: function(){
  136. this.relayFn('refresh', arguments);
  137. },
  138. bindStore: function(){
  139. this.relayFn('bindStore', arguments);
  140. },
  141. addRowCls: function(){
  142. this.relayFn('addRowCls', arguments);
  143. },
  144. removeRowCls: function(){
  145. this.relayFn('removeRowCls', arguments);
  146. }
  147. });