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