/* * Based on: * Ext JS Library 1.1.1 * Copyright(c) 2006-2007, Ext JS, LLC. * * Originally Released Under LGPL - original licence link has changed is not relivant. * * Fork - LGPL * <script type="text/javascript"> */ /** * @class Roo.menu.CheckItem * @extends Roo.menu.Item * Adds a menu item that contains a checkbox by default, but can also be part of a radio group. * @constructor * Creates a new CheckItem * @param {Object} config Configuration options */ Roo.menu.CheckItem = function(config){ Roo.menu.CheckItem.superclass.constructor.call(this, config); this.addEvents({ /** * @event beforecheckchange * Fires before the checked value is set, providing an opportunity to cancel if needed * @param {Roo.menu.CheckItem} this * @param {Boolean} checked The new checked value that will be set */ "beforecheckchange" : true, /** * @event checkchange * Fires after the checked value has been set * @param {Roo.menu.CheckItem} this * @param {Boolean} checked The checked value that was set */ "checkchange" : true }); if(this.checkHandler){ this.on('checkchange', this.checkHandler, this.scope); } }; Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, { /** * @cfg {String} group * All check items with the same group name will automatically be grouped into a single-select * radio button group (defaults to '') */ /** * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item") */ itemCls : "x-menu-item x-menu-check-item", /** * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item") */ groupClass : "x-menu-group-item", /** * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that * if this checkbox is part of a radio group (group = true) only the last item in the group that is * initialized with checked = true will be rendered as checked. */ checked: false, // private ctype: "Roo.menu.CheckItem", // private onRender : function(c){ Roo.menu.CheckItem.superclass.onRender.apply(this, arguments); if(this.group){ this.el.addClass(this.groupClass); } Roo.menu.MenuMgr.registerCheckable(this); if(this.checked){ this.checked = false; this.setChecked(true, true); } }, // private destroy : function(){ if(this.rendered){ Roo.menu.MenuMgr.unregisterCheckable(this); } Roo.menu.CheckItem.superclass.destroy.apply(this, arguments); }, /** * Set the checked state of this item * @param {Boolean} checked The new checked value * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false) */ setChecked : function(state, suppressEvent){ if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){ if(this.container){ this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked"); } this.checked = state; if(suppressEvent !== true){ this.fireEvent("checkchange", this, state); } } }, // private handleClick : function(e){ if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item this.setChecked(!this.checked); } Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments); } });