PageRenderTime 32ms CodeModel.GetById 18ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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