Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / menu / DatePicker.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16  * @class Ext.menu.DatePicker
17  * @extends Ext.menu.Menu
18  * <p>A menu containing an {@link Ext.picker.Date} Component.</p>
19  * <p>Notes:</p><div class="mdetail-params"><ul>
20  * <li>Although not listed here, the <b>constructor</b> for this class
21  * accepts all of the configuration options of <b>{@link Ext.picker.Date}</b>.</li>
22  * <li>If subclassing DateMenu, any configuration options for the DatePicker must be
23  * applied to the <tt><b>initialConfig</b></tt> property of the DateMenu.
24  * Applying {@link Ext.picker.Date DatePicker} configuration settings to
25  * <b><tt>this</tt></b> will <b>not</b> affect the DatePicker's configuration.</li>
26  * </ul></div>
27  *
28  * {@img Ext.menu.DatePicker/Ext.menu.DatePicker.png Ext.menu.DatePicker component}
29  *
30  * __Example Usage__
31  *
32  *     var dateMenu = Ext.create('Ext.menu.DatePicker', {
33  *         handler: function(dp, date){
34  *             Ext.Msg.alert('Date Selected', 'You choose {0}.', Ext.Date.format(date, 'M j, Y'));
35  *         }
36  *     });
37  *  
38  *     Ext.create('Ext.menu.Menu', {
39  *         width: 100,
40  *         height: 90,
41  *         floating: false,  // usually you want this set to True (default)
42  *         renderTo: Ext.getBody(),  // usually rendered by it's containing component
43  *         items: [{
44  *             text: 'choose a date',
45  *             menu: dateMenu
46  *         },{
47  *             iconCls: 'add16',
48  *             text: 'icon item'
49  *         },{
50  *             text: 'regular item'
51  *         }]
52  *     });
53  *
54  * @author Nicolas Ferrero
55  */
56  Ext.define('Ext.menu.DatePicker', {
57      extend: 'Ext.menu.Menu',
58
59      alias: 'widget.datemenu',
60
61      requires: [
62         'Ext.picker.Date'
63      ],
64
65     /**
66      * @cfg {Boolean} hideOnClick
67      * False to continue showing the menu after a date is selected, defaults to true.
68      */
69     hideOnClick : true,
70
71     /**
72      * @cfg {String} pickerId
73      * An id to assign to the underlying date picker. Defaults to <tt>null</tt>.
74      */
75     pickerId : null,
76
77     /**
78      * @cfg {Number} maxHeight
79      * @hide
80      */
81
82     /**
83      * The {@link Ext.picker.Date} instance for this DateMenu
84      * @property picker
85      * @type Ext.picker.Date
86      */
87
88     /**
89      * @event click
90      * @hide
91      */
92
93     /**
94      * @event itemclick
95      * @hide
96      */
97
98     initComponent : function(){
99         var me = this;
100
101         Ext.apply(me, {
102             showSeparator: false,
103             plain: true,
104             border: false,
105             bodyPadding: 0, // remove the body padding from the datepicker menu item so it looks like 3.3
106             items: Ext.applyIf({
107                 cls: Ext.baseCSSPrefix + 'menu-date-item',
108                 id: me.pickerId,
109                 xtype: 'datepicker'
110             }, me.initialConfig)
111         });
112
113         me.callParent(arguments);
114
115         me.picker = me.down('datepicker');
116         /**
117          * @event select
118          * Fires when a date is selected from the {@link #picker Ext.picker.Date}
119          * @param {Ext.picker.Date} picker The {@link #picker Ext.picker.Date}
120          * @param {Date} date The selected date
121          */
122         me.relayEvents(me.picker, ['select']);
123
124         if (me.hideOnClick) {
125             me.on('select', me.hidePickerOnSelect, me);
126         }
127     },
128
129     hidePickerOnSelect: function() {
130         Ext.menu.Manager.hideAll();
131     }
132  });