4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
13 * @class Roo.menu.CheckItem
14 * @extends Roo.menu.Item
15 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
17 * Creates a new CheckItem
18 * @param {Object} config Configuration options
20 Roo.menu.CheckItem = function(config){
21 Roo.menu.CheckItem.superclass.constructor.call(this, config);
24 * @event beforecheckchange
25 * Fires before the checked value is set, providing an opportunity to cancel if needed
26 * @param {Roo.menu.CheckItem} this
27 * @param {Boolean} checked The new checked value that will be set
29 "beforecheckchange" : true,
32 * Fires after the checked value has been set
33 * @param {Roo.menu.CheckItem} this
34 * @param {Boolean} checked The checked value that was set
38 if(this.checkHandler){
39 this.on('checkchange', this.checkHandler, this.scope);
42 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
45 * All check items with the same group name will automatically be grouped into a single-select
46 * radio button group (defaults to '')
49 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
51 itemCls : "x-menu-item x-menu-check-item",
53 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
55 groupClass : "x-menu-group-item",
58 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
59 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
60 * initialized with checked = true will be rendered as checked.
65 ctype: "Roo.menu.CheckItem",
68 onRender : function(c){
69 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
71 this.el.addClass(this.groupClass);
73 Roo.menu.MenuMgr.registerCheckable(this);
76 this.setChecked(true, true);
83 Roo.menu.MenuMgr.unregisterCheckable(this);
85 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
89 * Set the checked state of this item
90 * @param {Boolean} checked The new checked value
91 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
93 setChecked : function(state, suppressEvent){
94 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
96 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
99 if(suppressEvent !== true){
100 this.fireEvent("checkchange", this, state);
106 handleClick : function(e){
107 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
108 this.setChecked(!this.checked);
110 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);