Upgrade to ExtJS 3.1.1 - Released 02/08/2010
[extjs.git] / src / widgets / menu / DateMenu.js
1 /*!
2  * Ext JS Library 3.1.1
3  * Copyright(c) 2006-2010 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**\r
8  * @class Ext.menu.DateMenu\r
9  * @extends Ext.menu.Menu\r
10  * <p>A menu containing an {@link Ext.DatePicker} Component.</p>\r
11  * <p>Notes:</p><div class="mdetail-params"><ul>\r
12  * <li>Although not listed here, the <b>constructor</b> for this class\r
13  * accepts all of the configuration options of <b>{@link Ext.DatePicker}</b>.</li>\r
14  * <li>If subclassing DateMenu, any configuration options for the DatePicker must be\r
15  * applied to the <tt><b>initialConfig</b></tt> property of the DateMenu.\r
16  * Applying {@link Ext.DatePicker DatePicker} configuration settings to\r
17  * <b><tt>this</tt></b> will <b>not</b> affect the DatePicker's configuration.</li>\r
18  * </ul></div>\r
19  * @xtype datemenu\r
20  */\r
21  Ext.menu.DateMenu = Ext.extend(Ext.menu.Menu, {\r
22     /** \r
23      * @cfg {Boolean} enableScrolling\r
24      * @hide \r
25      */\r
26     enableScrolling : false,\r
27     /**\r
28      * @cfg {Function} handler\r
29      * Optional. A function that will handle the select event of this menu.\r
30      * The handler is passed the following parameters:<div class="mdetail-params"><ul>\r
31      * <li><code>picker</code> : DatePicker<div class="sub-desc">The Ext.DatePicker.</div></li>\r
32      * <li><code>date</code> : Date<div class="sub-desc">The selected date.</div></li>\r
33      * </ul></div>\r
34      */\r
35     /**\r
36      * @cfg {Object} scope\r
37      * The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>\r
38      * function will be called.  Defaults to this DateMenu instance.\r
39      */    \r
40     /** \r
41      * @cfg {Boolean} hideOnClick\r
42      * False to continue showing the menu after a date is selected, defaults to true.\r
43      */\r
44     hideOnClick : true,\r
45     \r
46     /** \r
47      * @cfg {String} pickerId\r
48      * An id to assign to the underlying date picker. Defaults to <tt>null</tt>.\r
49      */\r
50     pickerId : null,\r
51     \r
52     /** \r
53      * @cfg {Number} maxHeight\r
54      * @hide \r
55      */\r
56     /** \r
57      * @cfg {Number} scrollIncrement\r
58      * @hide \r
59      */\r
60     /**\r
61      * The {@link Ext.DatePicker} instance for this DateMenu\r
62      * @property picker\r
63      * @type DatePicker\r
64      */\r
65     cls : 'x-date-menu',\r
66     \r
67     /**\r
68      * @event click\r
69      * @hide\r
70      */\r
71     \r
72     /**\r
73      * @event itemclick\r
74      * @hide\r
75      */\r
76 \r
77     initComponent : function(){\r
78         this.on('beforeshow', this.onBeforeShow, this);\r
79         if(this.strict = (Ext.isIE7 && Ext.isStrict)){\r
80             this.on('show', this.onShow, this, {single: true, delay: 20});\r
81         }\r
82         Ext.apply(this, {\r
83             plain: true,\r
84             showSeparator: false,\r
85             items: this.picker = new Ext.DatePicker(Ext.applyIf({\r
86                 internalRender: this.strict || !Ext.isIE,\r
87                 ctCls: 'x-menu-date-item',\r
88                 id: this.pickerId\r
89             }, this.initialConfig))\r
90         });\r
91         this.picker.purgeListeners();\r
92         Ext.menu.DateMenu.superclass.initComponent.call(this);\r
93         /**\r
94          * @event select\r
95          * Fires when a date is selected from the {@link #picker Ext.DatePicker}\r
96          * @param {DatePicker} picker The {@link #picker Ext.DatePicker}\r
97          * @param {Date} date The selected date\r
98          */\r
99         this.relayEvents(this.picker, ['select']);\r
100         this.on('show', this.picker.focus, this.picker);\r
101         this.on('select', this.menuHide, this);\r
102         if(this.handler){\r
103             this.on('select', this.handler, this.scope || this);\r
104         }\r
105     },\r
106 \r
107     menuHide : function() {\r
108         if(this.hideOnClick){\r
109             this.hide(true);\r
110         }\r
111     },\r
112 \r
113     onBeforeShow : function(){\r
114         if(this.picker){\r
115             this.picker.hideMonthPicker(true);\r
116         }\r
117     },\r
118 \r
119     onShow : function(){\r
120         var el = this.picker.getEl();\r
121         el.setWidth(el.getWidth()); //nasty hack for IE7 strict mode\r
122     }\r
123  });\r
124  Ext.reg('datemenu', Ext.menu.DateMenu);\r
125