Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
27 jpm 1
/*
2
 * Ext JS Library 2.0.2
3
 * Copyright(c) 2006-2008, 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
 */
17
Ext.form.Checkbox = Ext.extend(Ext.form.Field,  {
18
    /**
19
     * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
20
     */
21
    focusClass : undefined,
22
    /**
23
     * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
24
     */
25
    fieldClass: "x-form-field",
26
    /**
27
     * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
28
     */
29
    checked: false,
30
    /**
31
     * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
32
     * {tag: "input", type: "checkbox", autocomplete: "off"})
33
     */
34
    defaultAutoCreate : { tag: "input", type: 'checkbox', autocomplete: "off"},
35
    /**
36
     * @cfg {String} boxLabel The text that appears beside the checkbox
37
     */
38
    /**
39
     * @cfg {String} inputValue The value that should go into the generated input element's value attribute
40
     */
41
 
42
	// private
43
    initComponent : function(){
44
        Ext.form.Checkbox.superclass.initComponent.call(this);
45
        this.addEvents(
46
            /**
47
             * @event check
48
             * Fires when the checkbox is checked or unchecked.
49
             * @param {Ext.form.Checkbox} this This checkbox
50
             * @param {Boolean} checked The new checked value
51
             */
52
            'check'
53
        );
54
    },
55
 
56
    // private
57
    onResize : function(){
58
        Ext.form.Checkbox.superclass.onResize.apply(this, arguments);
59
        if(!this.boxLabel){
60
            this.el.alignTo(this.wrap, 'c-c');
61
        }
62
    },
63
 
64
    // private
65
    initEvents : function(){
66
        Ext.form.Checkbox.superclass.initEvents.call(this);
67
        this.el.on("click", this.onClick,  this);
68
        this.el.on("change", this.onClick,  this);
69
    },
70
 
71
	// private
72
    getResizeEl : function(){
73
        return this.wrap;
74
    },
75
 
76
    // private
77
    getPositionEl : function(){
78
        return this.wrap;
79
    },
80
 
81
    /**
82
     * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
83
     * @method
84
     */
85
    markInvalid : Ext.emptyFn,
86
    /**
87
     * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
88
     * @method
89
     */
90
    clearInvalid : Ext.emptyFn,
91
 
92
    // private
93
    onRender : function(ct, position){
94
        Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
95
        if(this.inputValue !== undefined){
96
            this.el.dom.value = this.inputValue;
97
        }
98
        this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
99
        if(this.boxLabel){
100
            this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
101
        }
102
        if(this.checked){
103
            this.setValue(true);
104
        }else{
105
            this.checked = this.el.dom.checked;
106
        }
107
    },
108
 
109
    // private
110
    onDestroy : function(){
111
        if(this.wrap){
112
            this.wrap.remove();
113
        }
114
        Ext.form.Checkbox.superclass.onDestroy.call(this);
115
    },
116
 
117
    // private
118
    initValue : Ext.emptyFn,
119
 
120
    /**
121
     * Returns the checked state of the checkbox.
122
     * @return {Boolean} True if checked, else false
123
     */
124
    getValue : function(){
125
        if(this.rendered){
126
            return this.el.dom.checked;
127
        }
128
        return false;
129
    },
130
 
131
	// private
132
    onClick : function(){
133
        if(this.el.dom.checked != this.checked){
134
            this.setValue(this.el.dom.checked);
135
        }
136
    },
137
 
138
    /**
139
     * Sets the checked state of the checkbox.
140
     * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
141
     */
142
    setValue : function(v){
143
        this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
144
        if(this.el && this.el.dom){
145
            this.el.dom.checked = this.checked;
146
            this.el.dom.defaultChecked = this.checked;
147
        }
148
        this.fireEvent("check", this, this.checked);
149
    }
150
});
151
Ext.reg('checkbox', Ext.form.Checkbox);