2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.menu.CheckItem
\r
11 * @extends Ext.menu.Item
\r
12 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
\r
14 * Creates a new CheckItem
\r
15 * @param {Object} config Configuration options
\r
17 Ext.menu.CheckItem = function(config){
\r
18 Ext.menu.CheckItem.superclass.constructor.call(this, config);
\r
21 * @event beforecheckchange
\r
22 * Fires before the checked value is set, providing an opportunity to cancel if needed
\r
23 * @param {Ext.menu.CheckItem} this
\r
24 * @param {Boolean} checked The new checked value that will be set
\r
26 "beforecheckchange" ,
\r
28 * @event checkchange
\r
29 * Fires after the checked value has been set
\r
30 * @param {Ext.menu.CheckItem} this
\r
31 * @param {Boolean} checked The checked value that was set
\r
36 * A function that handles the checkchange event. The function is undefined by default, but if an implementation
\r
37 * is provided, it will be called automatically when the checkchange event fires.
\r
38 * @param {Ext.menu.CheckItem} this
\r
39 * @param {Boolean} checked The checked value that was set
\r
40 * @method checkHandler
\r
42 if(this.checkHandler){
\r
43 this.on('checkchange', this.checkHandler, this.scope);
\r
45 Ext.menu.MenuMgr.registerCheckable(this);
\r
47 Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
\r
49 * @cfg {String} group
\r
50 * All check items with the same group name will automatically be grouped into a single-select
\r
51 * radio button group (defaults to '')
\r
54 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
\r
56 itemCls : "x-menu-item x-menu-check-item",
\r
58 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
\r
60 groupClass : "x-menu-group-item",
\r
63 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
\r
64 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
\r
65 * initialized with checked = true will be rendered as checked.
\r
70 ctype: "Ext.menu.CheckItem",
\r
73 onRender : function(c){
\r
74 Ext.menu.CheckItem.superclass.onRender.apply(this, arguments);
\r
76 this.el.addClass(this.groupClass);
\r
79 this.checked = false;
\r
80 this.setChecked(true, true);
\r
85 destroy : function(){
\r
86 Ext.menu.MenuMgr.unregisterCheckable(this);
\r
87 Ext.menu.CheckItem.superclass.destroy.apply(this, arguments);
\r
91 * Set the checked state of this item
\r
92 * @param {Boolean} checked The new checked value
\r
93 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
\r
95 setChecked : function(state, suppressEvent){
\r
96 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
\r
98 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
\r
100 this.checked = state;
\r
101 if(suppressEvent !== true){
\r
102 this.fireEvent("checkchange", this, state);
\r
108 handleClick : function(e){
\r
109 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
\r
110 this.setChecked(!this.checked);
\r
112 Ext.menu.CheckItem.superclass.handleClick.apply(this, arguments);
\r