source: trunk/web/addons/job_monarch/lib/extjs/source/widgets/menu/CheckItem.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 4.0 KB
Line 
1/*
2 * Ext JS Library 2.2.1
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 */
17Ext.menu.CheckItem = function(config){
18    Ext.menu.CheckItem.superclass.constructor.call(this, config);
19    this.addEvents(
20        /**
21         * @event beforecheckchange
22         * Fires before the checked value is set, providing an opportunity to cancel if needed
23         * @param {Ext.menu.CheckItem} this
24         * @param {Boolean} checked The new checked value that will be set
25         */
26        "beforecheckchange" ,
27        /**
28         * @event checkchange
29         * Fires after the checked value has been set
30         * @param {Ext.menu.CheckItem} this
31         * @param {Boolean} checked The checked value that was set
32         */
33        "checkchange"
34    );
35    /**
36     * A function that handles the checkchange event.  The function is undefined by default, but if an implementation
37     * is provided, it will be called automatically when the checkchange event fires.
38     * @param {Ext.menu.CheckItem} this
39     * @param {Boolean} checked The checked value that was set
40     * @method checkHandler
41     */
42    if(this.checkHandler){
43        this.on('checkchange', this.checkHandler, this.scope);
44    }
45    Ext.menu.MenuMgr.registerCheckable(this);
46};
47Ext.extend(Ext.menu.CheckItem, Ext.menu.Item, {
48    /**
49     * @cfg {String} group
50     * All check items with the same group name will automatically be grouped into a single-select
51     * radio button group (defaults to '')
52     */
53    /**
54     * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
55     */
56    itemCls : "x-menu-item x-menu-check-item",
57    /**
58     * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
59     */
60    groupClass : "x-menu-group-item",
61
62    /**
63     * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false).  Note that
64     * if this checkbox is part of a radio group (group = true) only the last item in the group that is
65     * initialized with checked = true will be rendered as checked.
66     */
67    checked: false,
68
69    // private
70    ctype: "Ext.menu.CheckItem",
71
72    // private
73    onRender : function(c){
74        Ext.menu.CheckItem.superclass.onRender.apply(this, arguments);
75        if(this.group){
76            this.el.addClass(this.groupClass);
77        }
78        if(this.checked){
79            this.checked = false;
80            this.setChecked(true, true);
81        }
82    },
83
84    // private
85    destroy : function(){
86        Ext.menu.MenuMgr.unregisterCheckable(this);
87        Ext.menu.CheckItem.superclass.destroy.apply(this, arguments);
88    },
89
90    /**
91     * Set the checked state of this item
92     * @param {Boolean} checked The new checked value
93     * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
94     */
95    setChecked : function(state, suppressEvent){
96        if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
97            if(this.container){
98                this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
99            }
100            this.checked = state;
101            if(suppressEvent !== true){
102                this.fireEvent("checkchange", this, state);
103            }
104        }
105    },
106
107    // private
108    handleClick : function(e){
109       if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
110           this.setChecked(!this.checked);
111       }
112       Ext.menu.CheckItem.superclass.handleClick.apply(this, arguments);
113    }
114});
Note: See TracBrowser for help on using the repository browser.