Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / menu / DatePicker.js
1 /**
2  * @class Ext.menu.DatePicker
3  * @extends Ext.menu.Menu
4  * <p>A menu containing an {@link Ext.picker.Date} Component.</p>
5  * <p>Notes:</p><div class="mdetail-params"><ul>
6  * <li>Although not listed here, the <b>constructor</b> for this class
7  * accepts all of the configuration options of <b>{@link Ext.picker.Date}</b>.</li>
8  * <li>If subclassing DateMenu, any configuration options for the DatePicker must be
9  * applied to the <tt><b>initialConfig</b></tt> property of the DateMenu.
10  * Applying {@link Ext.picker.Date DatePicker} configuration settings to
11  * <b><tt>this</tt></b> will <b>not</b> affect the DatePicker's configuration.</li>
12  * </ul></div>
13  * {@img Ext.menu.DatePicker/Ext.menu.DatePicker.png Ext.menu.DatePicker component}
14  * __Example Usage__
15      var dateMenu = Ext.create('Ext.menu.DatePicker', {
16         handler: function(dp, date){
17             Ext.Msg.alert('Date Selected', 'You choose {0}.', Ext.Date.format(date, 'M j, Y'));
18
19         }
20     });
21
22     Ext.create('Ext.menu.Menu', {
23                 width: 100,
24                 height: 90,
25                 floating: false,  // usually you want this set to True (default)
26                 renderTo: Ext.getBody(),  // usually rendered by it's containing component
27                 items: [{
28                     text: 'choose a date',
29                     menu: dateMenu
30                 },{
31             iconCls: 'add16',
32                     text: 'icon item'
33                 },{
34                     text: 'regular item'
35                 }]
36         });
37
38  * @xtype datemenu
39  * @author Nicolas Ferrero
40  */
41  Ext.define('Ext.menu.DatePicker', {
42      extend: 'Ext.menu.Menu',
43
44      alias: 'widget.datemenu',
45
46      requires: [
47         'Ext.picker.Date'
48      ],
49
50     /**
51      * @cfg {Boolean} hideOnClick
52      * False to continue showing the menu after a date is selected, defaults to true.
53      */
54     hideOnClick : true,
55
56     /**
57      * @cfg {String} pickerId
58      * An id to assign to the underlying date picker. Defaults to <tt>null</tt>.
59      */
60     pickerId : null,
61
62     /**
63      * @cfg {Number} maxHeight
64      * @hide
65      */
66
67     /**
68      * The {@link Ext.picker.Date} instance for this DateMenu
69      * @property picker
70      * @type Ext.picker.Date
71      */
72
73     /**
74      * @event click
75      * @hide
76      */
77
78     /**
79      * @event itemclick
80      * @hide
81      */
82
83     initComponent : function(){
84         var me = this;
85
86         Ext.apply(me, {
87             showSeparator: false,
88             plain: true,
89             items: Ext.applyIf({
90                 cls: Ext.baseCSSPrefix + 'menu-date-item',
91                 id: me.pickerId,
92                 xtype: 'datepicker'
93             }, me.initialConfig)
94         });
95
96         me.callParent(arguments);
97
98         me.picker = me.down('datepicker');
99         /**
100          * @event select
101          * Fires when a date is selected from the {@link #picker Ext.picker.Date}
102          * @param {Ext.picker.Date} picker The {@link #picker Ext.picker.Date}
103          * @param {Date} date The selected date
104          */
105         me.relayEvents(me.picker, ['select']);
106
107         if (me.hideOnClick) {
108             me.on('select', me.hidePickerOnSelect, me);
109         }
110     },
111
112     hidePickerOnSelect: function() {
113         Ext.menu.Manager.hideAll();
114     }
115  });