Upgrade to ExtJS 4.0.7 - Released 10/19/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  * A menu containing an Ext.picker.Date Component.
17  *
18  * Notes:
19  *
20  * - Although not listed here, the **constructor** for this class accepts all of the
21  *   configuration options of **{@link Ext.picker.Date}**.
22  * - If subclassing DateMenu, any configuration options for the DatePicker must be applied
23  *   to the **initialConfig** property of the DateMenu. Applying {@link Ext.picker.Date Date Picker}
24  *   configuration settings to **this** will **not** affect the Date Picker's configuration.
25  *
26  * Example:
27  *
28  *     @example
29  *     var dateMenu = Ext.create('Ext.menu.DatePicker', {
30  *         handler: function(dp, date){
31  *             Ext.Msg.alert('Date Selected', 'You selected ' + Ext.Date.format(date, 'M j, Y'));
32  *         }
33  *     });
34  *
35  *     Ext.create('Ext.menu.Menu', {
36  *         width: 100,
37  *         height: 90,
38  *         floating: false,  // usually you want this set to True (default)
39  *         renderTo: Ext.getBody(),  // usually rendered by it's containing component
40  *         items: [{
41  *             text: 'choose a date',
42  *             menu: dateMenu
43  *         },{
44  *             iconCls: 'add16',
45  *             text: 'icon item'
46  *         },{
47  *             text: 'regular item'
48  *         }]
49  *     });
50  */
51  Ext.define('Ext.menu.DatePicker', {
52      extend: 'Ext.menu.Menu',
53
54      alias: 'widget.datemenu',
55
56      requires: [
57         'Ext.picker.Date'
58      ],
59
60     /**
61      * @cfg {Boolean} hideOnClick
62      * False to continue showing the menu after a date is selected.
63      */
64     hideOnClick : true,
65
66     /**
67      * @cfg {String} pickerId
68      * An id to assign to the underlying date picker.
69      */
70     pickerId : null,
71
72     /**
73      * @cfg {Number} maxHeight
74      * @hide
75      */
76
77     /**
78      * @property {Ext.picker.Date} picker
79      * The {@link Ext.picker.Date} instance for this DateMenu
80      */
81
82     /**
83      * @event click
84      * @hide
85      */
86
87     /**
88      * @event itemclick
89      * @hide
90      */
91
92     initComponent : function(){
93         var me = this;
94
95         Ext.apply(me, {
96             showSeparator: false,
97             plain: true,
98             border: false,
99             bodyPadding: 0, // remove the body padding from the datepicker menu item so it looks like 3.3
100             items: Ext.applyIf({
101                 cls: Ext.baseCSSPrefix + 'menu-date-item',
102                 id: me.pickerId,
103                 xtype: 'datepicker'
104             }, me.initialConfig)
105         });
106
107         me.callParent(arguments);
108
109         me.picker = me.down('datepicker');
110         /**
111          * @event select
112          * @alias Ext.picker.Date#select
113          */
114         me.relayEvents(me.picker, ['select']);
115
116         if (me.hideOnClick) {
117             me.on('select', me.hidePickerOnSelect, me);
118         }
119     },
120
121     hidePickerOnSelect: function() {
122         Ext.menu.Manager.hideAll();
123     }
124  });