Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / LockingView.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-grid-LockingView'>/**
19 </span> * @class Ext.grid.LockingView
20  * This class is used internally to provide a single interface when using
21  * a locking grid. Internally, the locking grid creates two separate grids,
22  * so this class is used to map calls appropriately.
23  * @ignore
24  */
25 Ext.define('Ext.grid.LockingView', {
26
27     mixins: {
28         observable: 'Ext.util.Observable'
29     },
30
31     eventRelayRe: /^(beforeitem|beforecontainer|item|container|cell)/,
32
33     constructor: function(config){
34         var me = this,
35             eventNames = [],
36             eventRe = me.eventRelayRe,
37             locked = config.locked.getView(),
38             normal = config.normal.getView(),
39             events,
40             event;
41
42         Ext.apply(me, {
43             lockedView: locked,
44             normalView: normal,
45             lockedGrid: config.locked,
46             normalGrid: config.normal,
47             panel: config.panel
48         });
49         me.mixins.observable.constructor.call(me, config);
50
51         // relay events
52         events = locked.events;
53         for (event in events) {
54             if (events.hasOwnProperty(event) &amp;&amp; eventRe.test(event)) {
55                 eventNames.push(event);
56             }
57         }
58         me.relayEvents(locked, eventNames);
59         me.relayEvents(normal, eventNames);
60
61         normal.on({
62             scope: me,
63             itemmouseleave: me.onItemMouseLeave,
64             itemmouseenter: me.onItemMouseEnter
65         });
66
67         locked.on({
68             scope: me,
69             itemmouseleave: me.onItemMouseLeave,
70             itemmouseenter: me.onItemMouseEnter
71         });
72     },
73
74     getGridColumns: function() {
75         var cols = this.lockedGrid.headerCt.getGridColumns();
76         return cols.concat(this.normalGrid.headerCt.getGridColumns());
77     },
78
79     getEl: function(column){
80         return this.getViewForColumn(column).getEl();
81     },
82
83     getViewForColumn: function(column) {
84         var view = this.lockedView,
85             inLocked;
86
87         view.headerCt.cascade(function(col){
88             if (col === column) {
89                 inLocked = true;
90                 return false;
91             }
92         });
93
94         return inLocked ? view : this.normalView;
95     },
96
97     onItemMouseEnter: function(view, record){
98         var me = this,
99             locked = me.lockedView,
100             other = me.normalView,
101             item;
102
103         if (view.trackOver) {
104             if (view !== locked) {
105                 other = locked;
106             }
107             item = other.getNode(record);
108             other.highlightItem(item);
109         }
110     },
111
112     onItemMouseLeave: function(view, record){
113         var me = this,
114             locked = me.lockedView,
115             other = me.normalView;
116
117         if (view.trackOver) {
118             if (view !== locked) {
119                 other = locked;
120             }
121             other.clearHighlight();
122         }
123     },
124
125     relayFn: function(name, args){
126         args = args || [];
127
128         var view = this.lockedView;
129         view[name].apply(view, args || []);
130         view = this.normalView;
131         view[name].apply(view, args || []);
132     },
133
134     getSelectionModel: function(){
135         return this.panel.getSelectionModel();
136     },
137
138     getStore: function(){
139         return this.panel.store;
140     },
141
142     getNode: function(nodeInfo){
143         // default to the normal view
144         return this.normalView.getNode(nodeInfo);
145     },
146
147     getCell: function(record, column){
148         var view = this.getViewForColumn(column),
149             row;
150
151         row = view.getNode(record);
152         return Ext.fly(row).down(column.getCellSelector());
153     },
154
155     getRecord: function(node){
156         var result = this.lockedView.getRecord(node);
157         if (!node) {
158             result = this.normalView.getRecord(node);
159         }
160         return result;
161     },
162
163     addElListener: function(eventName, fn, scope){
164         this.relayFn('addElListener', arguments);
165     },
166
167     refreshNode: function(){
168         this.relayFn('refreshNode', arguments);
169     },
170
171     refresh: function(){
172         this.relayFn('refresh', arguments);
173     },
174
175     bindStore: function(){
176         this.relayFn('bindStore', arguments);
177     },
178
179     addRowCls: function(){
180         this.relayFn('addRowCls', arguments);
181     },
182
183     removeRowCls: function(){
184         this.relayFn('removeRowCls', arguments);
185     }
186
187 });</pre>
188 </body>
189 </html>