~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/web/extjs/source/widgets/form/Checkbox.js

  • Committer: parra
  • Date: 2010-03-15 15:56:56 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1448
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 3.0 RC2
 
3
 * Copyright(c) 2006-2009, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
10
 * @class Ext.form.Checkbox
 
11
 * @extends Ext.form.Field
 
12
 * Single checkbox field.  Can be used as a direct replacement for traditional checkbox fields.
 
13
 * @constructor
 
14
 * Creates a new Checkbox
 
15
 * @param {Object} config Configuration options
 
16
 * @xtype checkbox
 
17
 */
 
18
Ext.form.Checkbox = Ext.extend(Ext.form.Field,  {
 
19
    /**
 
20
     * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
 
21
     */
 
22
    focusClass : undefined,
 
23
    /**
 
24
     * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
 
25
     */
 
26
    fieldClass: "x-form-field",
 
27
    /**
 
28
     * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
 
29
     */
 
30
    checked: false,
 
31
    /**
 
32
     * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
 
33
     * {tag: "input", type: "checkbox", autocomplete: "off"})
 
34
     */
 
35
    defaultAutoCreate : { tag: "input", type: 'checkbox', autocomplete: "off"},
 
36
    /**
 
37
     * @cfg {String} boxLabel The text that appears beside the checkbox
 
38
     */
 
39
    /**
 
40
     * @cfg {String} inputValue The value that should go into the generated input element's value attribute
 
41
     */
 
42
    /**
 
43
     * @cfg {Function} handler A function called when the {@link #checked} value changes (can be used instead of 
 
44
     * handling the check event). The handler is passed the following parameters:
 
45
     * <div class="mdetail-params"><ul>
 
46
     * <li><b>checkbox</b> : Ext.form.Checkbox<div class="sub-desc">The Checkbox being toggled.</div></li>
 
47
     * <li><b>checked</b> : Boolean<div class="sub-desc">The new checked state of the checkbox.</div></li>
 
48
     * </ul></div>
 
49
     */
 
50
    /**
 
51
     * @cfg {Object} scope An object to use as the scope ("this" reference) of the {@link #handler} function
 
52
     * (defaults to this Checkbox).
 
53
     */
 
54
 
 
55
        // private
 
56
    initComponent : function(){
 
57
        Ext.form.Checkbox.superclass.initComponent.call(this);
 
58
        this.addEvents(
 
59
            /**
 
60
             * @event check
 
61
             * Fires when the checkbox is checked or unchecked.
 
62
             * @param {Ext.form.Checkbox} this This checkbox
 
63
             * @param {Boolean} checked The new checked value
 
64
             */
 
65
            'check'
 
66
        );
 
67
    },
 
68
 
 
69
    // private
 
70
    onResize : function(){
 
71
        Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
 
72
        if(!this.boxLabel){
 
73
            this.el.alignTo(this.wrap, 'c-c');
 
74
        }
 
75
    },
 
76
 
 
77
    // private
 
78
    initEvents : function(){
 
79
        Ext.form.Checkbox.superclass.initEvents.call(this);
 
80
        this.mon(this.el, 'click', this.onClick, this);
 
81
        this.mon(this.el, 'change', this.onClick, this);
 
82
    },
 
83
 
 
84
        // private
 
85
    getResizeEl : function(){
 
86
        return this.wrap;
 
87
    },
 
88
 
 
89
    // private
 
90
    getPositionEl : function(){
 
91
        return this.wrap;
 
92
    },
 
93
 
 
94
    /**
 
95
     * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
 
96
     * @method
 
97
     */
 
98
    markInvalid : Ext.emptyFn,
 
99
    /**
 
100
     * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
 
101
     * @method
 
102
     */
 
103
    clearInvalid : Ext.emptyFn,
 
104
 
 
105
    // private
 
106
    onRender : function(ct, position){
 
107
        Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
 
108
        if(this.inputValue !== undefined){
 
109
            this.el.dom.value = this.inputValue;
 
110
        }
 
111
        this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
 
112
        if(this.boxLabel){
 
113
            this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
 
114
        }
 
115
        if(this.checked){
 
116
            this.setValue(true);
 
117
        }else{
 
118
            this.checked = this.el.dom.checked;
 
119
        }
 
120
    },
 
121
 
 
122
    // private
 
123
    onDestroy : function(){
 
124
        Ext.destroy(this.wrap);
 
125
        Ext.form.Checkbox.superclass.onDestroy.call(this);
 
126
    },
 
127
 
 
128
    // private
 
129
    initValue : Ext.emptyFn,
 
130
 
 
131
    /**
 
132
     * Returns the checked state of the checkbox.
 
133
     * @return {Boolean} True if checked, else false
 
134
     */
 
135
    getValue : function(){
 
136
        if(this.rendered){
 
137
            return this.el.dom.checked;
 
138
        }
 
139
        return false;
 
140
    },
 
141
 
 
142
        // private
 
143
    onClick : function(){
 
144
        if(this.el.dom.checked != this.checked){
 
145
            this.setValue(this.el.dom.checked);
 
146
        }
 
147
    },
 
148
 
 
149
    /**
 
150
     * Sets the checked state of the checkbox.
 
151
     * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
 
152
     * @return {Ext.form.Field} this
 
153
     */
 
154
    setValue : function(v){
 
155
        var checked = this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
 
156
        if(this.el && this.el.dom){
 
157
            this.el.dom.checked = checked;
 
158
            this.el.dom.defaultChecked = checked;
 
159
        }
 
160
        this.fireEvent("check", this, checked);
 
161
        if(this.handler){
 
162
            this.handler.call(this.scope || this, this, checked);
 
163
        }
 
164
        return this;
 
165
    }
 
166
});
 
167
Ext.reg('checkbox', Ext.form.Checkbox);
 
 
b'\\ No newline at end of file'