~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/extjs/source/widgets/menu/CheckItem.js

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
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.menu.CheckItem
 
11
 * @extends Ext.menu.Item
 
12
 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
 
13
 * @constructor
 
14
 * Creates a new CheckItem
 
15
 * @param {Object} config Configuration options
 
16
 * @xtype menucheckitem
 
17
 */
 
18
Ext.menu.CheckItem = function(config){
 
19
    Ext.menu.CheckItem.superclass.constructor.call(this, config);
 
20
    this.addEvents(
 
21
        /**
 
22
         * @event beforecheckchange
 
23
         * Fires before the checked value is set, providing an opportunity to cancel if needed
 
24
         * @param {Ext.menu.CheckItem} this
 
25
         * @param {Boolean} checked The new checked value that will be set
 
26
         */
 
27
        "beforecheckchange" ,
 
28
        /**
 
29
         * @event checkchange
 
30
         * Fires after the checked value has been set
 
31
         * @param {Ext.menu.CheckItem} this
 
32
         * @param {Boolean} checked The checked value that was set
 
33
         */
 
34
        "checkchange"
 
35
    );
 
36
    /**
 
37
     * A function that handles the checkchange event.  The function is undefined by default, but if an implementation
 
38
     * is provided, it will be called automatically when the checkchange event fires.
 
39
     * @param {Ext.menu.CheckItem} this
 
40
     * @param {Boolean} checked The checked value that was set
 
41
     * @method checkHandler
 
42
     */
 
43
    if(this.checkHandler){
 
44
        this.on('checkchange', this.checkHandler, this.scope);
 
45
    }
 
46
    Ext.menu.MenuMgr.registerCheckable(this);
 
47
};
 
48
Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
 
49
    /**
 
50
     * @cfg {String} group
 
51
     * All check items with the same group name will automatically be grouped into a single-select
 
52
     * radio button group (defaults to '')
 
53
     */
 
54
    /**
 
55
     * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
 
56
     */
 
57
    itemCls : "x-menu-item x-menu-check-item",
 
58
    /**
 
59
     * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
 
60
     */
 
61
    groupClass : "x-menu-group-item",
 
62
 
 
63
    /**
 
64
     * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false).  Note that
 
65
     * if this checkbox is part of a radio group (group = true) only the last item in the group that is
 
66
     * initialized with checked = true will be rendered as checked.
 
67
     */
 
68
    checked: false,
 
69
 
 
70
    // private
 
71
    ctype: "Ext.menu.CheckItem",
 
72
 
 
73
    // private
 
74
    onRender : function(c){
 
75
        Ext.menu.CheckItem.superclass.onRender.apply(this, arguments);
 
76
        if(this.group){
 
77
            this.el.addClass(this.groupClass);
 
78
        }
 
79
        if(this.checked){
 
80
            this.checked = false;
 
81
            this.setChecked(true, true);
 
82
        }
 
83
    },
 
84
 
 
85
    // private
 
86
    destroy : function(){
 
87
        Ext.menu.MenuMgr.unregisterCheckable(this);
 
88
        Ext.menu.CheckItem.superclass.destroy.apply(this, arguments);
 
89
    },
 
90
 
 
91
    /**
 
92
     * Set the checked state of this item
 
93
     * @param {Boolean} checked The new checked value
 
94
     * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
 
95
     */
 
96
    setChecked : function(state, suppressEvent){
 
97
        if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
 
98
            if(this.container){
 
99
                this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
 
100
            }
 
101
            this.checked = state;
 
102
            if(suppressEvent !== true){
 
103
                this.fireEvent("checkchange", this, state);
 
104
            }
 
105
        }
 
106
    },
 
107
 
 
108
    // private
 
109
    handleClick : function(e){
 
110
       if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
 
111
           this.setChecked(!this.checked);
 
112
       }
 
113
       Ext.menu.CheckItem.superclass.handleClick.apply(this, arguments);
 
114
    }
 
115
});
 
116
Ext.reg('menucheckitem', Ext.menu.CheckItem);
 
 
b'\\ No newline at end of file'