Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / CheckItem.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-menu-CheckItem'>/**
19 </span> * @class Ext.menu.CheckItem
20  * @extends Ext.menu.Item
21  *
22  * A menu item that contains a togglable checkbox by default, but that can also be a part of a radio group.
23  *
24  * {@img Ext.menu.CheckItem/Ext.menu.CheckItem.png Ext.menu.CheckItem component}
25  *
26  * __Example Usage__
27  *
28  *     Ext.create('Ext.menu.Menu', {
29  *         width: 100,
30  *         height: 110,
31  *         floating: false,  // usually you want this set to True (default)
32  *         renderTo: Ext.getBody(),  // usually rendered by it's containing component
33  *         items: [{
34  *             xtype: 'menucheckitem',
35  *             text: 'select all'
36  *         },{
37  *             xtype: 'menucheckitem',
38  *             text: 'select specific',
39  *         },{
40  *             iconCls: 'add16',
41  *             text: 'icon item'
42  *         },{
43  *             text: 'regular item'
44  *         }]
45  *     }); 
46  *     
47  */
48 Ext.define('Ext.menu.CheckItem', {
49     extend: 'Ext.menu.Item',
50     alias: 'widget.menucheckitem',
51
52 <span id='Ext-menu-CheckItem-cfg-checkedCls'>    /**
53 </span>     * @cfg {String} checkedCls
54      * The CSS class used by {@link #cls} to show the checked state.
55      * Defaults to `Ext.baseCSSPrefix + 'menu-item-checked'`.
56      * @markdown
57      */
58     checkedCls: Ext.baseCSSPrefix + 'menu-item-checked',
59 <span id='Ext-menu-CheckItem-cfg-uncheckedCls'>    /**
60 </span>     * @cfg {String} uncheckedCls
61      * The CSS class used by {@link #cls} to show the unchecked state.
62      * Defaults to `Ext.baseCSSPrefix + 'menu-item-unchecked'`.
63      * @markdown
64      */
65     uncheckedCls: Ext.baseCSSPrefix + 'menu-item-unchecked',
66 <span id='Ext-menu-CheckItem-cfg-groupCls'>    /**
67 </span>     * @cfg {String} groupCls
68      * The CSS class applied to this item's icon image to denote being a part of a radio group.
69      * Defaults to `Ext.baseCSSClass + 'menu-group-icon'`.
70      * Any specified {@link #iconCls} overrides this.
71      * @markdown
72      */
73     groupCls: Ext.baseCSSPrefix + 'menu-group-icon',
74
75 <span id='Ext-menu-CheckItem-cfg-hideOnClick'>    /**
76 </span>     * @cfg {Boolean} hideOnClick
77      * Whether to not to hide the owning menu when this item is clicked.
78      * Defaults to `false` for checkbox items, and to `true` for radio group items.
79      * @markdown
80      */
81     hideOnClick: false,
82
83     afterRender: function() {
84         var me = this;
85         this.callParent();
86         me.checked = !me.checked;
87         me.setChecked(!me.checked, true);
88     },
89
90     initComponent: function() {
91         var me = this;
92         me.addEvents(
93 <span id='Ext-menu-CheckItem-event-beforecheckchange'>            /**
94 </span>             * @event beforecheckchange
95              * Fires before a change event. Return false to cancel.
96              * @param {Ext.menu.CheckItem} this
97              * @param {Boolean} checked
98              */
99             'beforecheckchange',
100
101 <span id='Ext-menu-CheckItem-event-checkchange'>            /**
102 </span>             * @event checkchange
103              * Fires after a change event.
104              * @param {Ext.menu.CheckItem} this
105              * @param {Boolean} checked
106              */
107             'checkchange'
108         );
109
110         me.callParent(arguments);
111
112         Ext.menu.Manager.registerCheckable(me);
113
114         if (me.group) {
115             if (!me.iconCls) {
116                 me.iconCls = me.groupCls;
117             }
118             if (me.initialConfig.hideOnClick !== false) {
119                 me.hideOnClick = true;
120             }
121         }
122     },
123
124 <span id='Ext-menu-CheckItem-method-disableCheckChange'>    /**
125 </span>     * Disables just the checkbox functionality of this menu Item. If this menu item has a submenu, that submenu
126      * will still be accessible
127      */
128     disableCheckChange: function() {
129         var me = this;
130
131         if (me.iconEl) {
132             me.iconEl.addCls(me.disabledCls);
133         }
134         me.checkChangeDisabled = true;
135     },
136
137 <span id='Ext-menu-CheckItem-method-enableCheckChange'>    /**
138 </span>     * Reenables the checkbox functionality of this menu item after having been disabled by {@link #disableCheckChange}
139      */
140     enableCheckChange: function() {
141         var me = this;
142
143         me.iconEl.removeCls(me.disabledCls);
144         me.checkChangeDisabled = false;
145     },
146
147     onClick: function(e) {
148         var me = this;
149         if(!me.disabled &amp;&amp; !me.checkChangeDisabled &amp;&amp; !(me.checked &amp;&amp; me.group)) {
150             me.setChecked(!me.checked);
151         }
152         this.callParent([e]);
153     },
154
155     onDestroy: function() {
156         Ext.menu.Manager.unregisterCheckable(this);
157         this.callParent(arguments);
158     },
159
160 <span id='Ext-menu-CheckItem-method-setChecked'>    /**
161 </span>     * Sets the checked state of the item
162      * @param {Boolean} checked True to check, false to uncheck
163      * @param {Boolean} suppressEvents (optional) True to prevent firing the checkchange events. Defaults to `false`.
164      * @markdown
165      */
166     setChecked: function(checked, suppressEvents) {
167         var me = this;
168         if (me.checked !== checked &amp;&amp; (suppressEvents || me.fireEvent('beforecheckchange', me, checked) !== false)) {
169             if (me.el) {
170                 me.el[checked  ? 'addCls' : 'removeCls'](me.checkedCls)[!checked ? 'addCls' : 'removeCls'](me.uncheckedCls);
171             }
172             me.checked = checked;
173             Ext.menu.Manager.onCheckChange(me, checked);
174             if (!suppressEvents) {
175                 Ext.callback(me.checkHandler, me.scope, [me, checked]);
176                 me.fireEvent('checkchange', me, checked);
177             }
178         }
179     }
180 });
181 </pre>
182 </body>
183 </html>