Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / grid / CellEditor.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 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.
11
12 If 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.CellEditor
17  * @extends Ext.Editor
18  * Internal utility class that provides default configuration for cell editing.
19  * @ignore
20  */
21 Ext.define('Ext.grid.CellEditor', {
22     extend: 'Ext.Editor',
23     constructor: function(config) {
24         config = Ext.apply({}, config);
25         
26         if (config.field) {
27             config.field.monitorTab = false;
28         }
29         if (!Ext.isDefined(config.autoSize)) {
30             config.autoSize = {
31                 width: 'boundEl'
32             };
33         }
34         this.callParent([config]);
35     },
36     
37     /**
38      * @private
39      * Hide the grid cell when editor is shown.
40      */
41     onShow: function() {
42         var first = this.boundEl.first();
43         if (first) {
44             first.hide();
45         }
46         this.callParent(arguments);
47     },
48     
49     /**
50      * @private
51      * Show grid cell when editor is hidden.
52      */
53     onHide: function() {
54         var first = this.boundEl.first();
55         if (first) {
56             first.show();
57         }
58         this.callParent(arguments);
59     },
60     
61     /**
62      * @private
63      * Fix checkbox blur when it is clicked.
64      */
65     afterRender: function() {
66         this.callParent(arguments);
67         var field = this.field;
68         if (field.isXType('checkboxfield')) {
69             field.mon(field.inputEl, 'mousedown', this.onCheckBoxMouseDown, this);
70             field.mon(field.inputEl, 'click', this.onCheckBoxClick, this);
71         }
72     },
73     
74     /**
75      * @private
76      * Because when checkbox is clicked it loses focus  completeEdit is bypassed.
77      */
78     onCheckBoxMouseDown: function() {
79         this.completeEdit = Ext.emptyFn;
80     },
81     
82     /**
83      * @private
84      * Restore checkbox focus and completeEdit method.
85      */
86     onCheckBoxClick: function() {
87         delete this.completeEdit;
88         this.field.focus(false, 10);
89     },
90     
91     alignment: "tl-tl",
92     hideEl : false,
93     cls: Ext.baseCSSPrefix + "small-editor " + Ext.baseCSSPrefix + "grid-editor",
94     shim: false,
95     shadow: false
96 });