]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/src/menu/DatePicker.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / src / menu / DatePicker.js
CommitLineData
6527f429
DM
1/**\r
2 * A menu containing an Ext.picker.Date Component.\r
3 *\r
4 * Notes:\r
5 *\r
6 * - Although not listed here, the **constructor** for this class accepts all of the\r
7 * configuration options of **{@link Ext.picker.Date}**.\r
8 * - If subclassing DateMenu, any configuration options for the DatePicker must be applied\r
9 * to the **initialConfig** property of the DateMenu. Applying {@link Ext.picker.Date Date Picker}\r
10 * configuration settings to **this** will **not** affect the Date Picker's configuration.\r
11 *\r
12 * Example:\r
13 *\r
14 * @example\r
15 * var dateMenu = Ext.create('Ext.menu.DatePicker', {\r
16 * handler: function(dp, date){\r
17 * Ext.Msg.alert('Date Selected', 'You selected ' + Ext.Date.format(date, 'M j, Y'));\r
18 * }\r
19 * });\r
20 *\r
21 * Ext.create('Ext.menu.Menu', {\r
22 * items: [{\r
23 * text: 'Choose a date',\r
24 * menu: dateMenu\r
25 * },{\r
26 * iconCls: 'add16',\r
27 * text: 'Icon item'\r
28 * },{\r
29 * text: 'Regular item'\r
30 * }]\r
31 * }).showAt([5, 5]);\r
32 */\r
33 Ext.define('Ext.menu.DatePicker', {\r
34 extend: 'Ext.menu.Menu',\r
35\r
36 alias: 'widget.datemenu',\r
37\r
38 requires: [\r
39 'Ext.picker.Date'\r
40 ],\r
41 \r
42 ariaRole: 'dialog',\r
43 \r
44 //<locale>\r
45 /**\r
46 * @cfg {String} ariaLabel ARIA label for the Date Picker menu\r
47 */\r
48 ariaLabel: 'Date picker',\r
49 //</locale>\r
50\r
51 /**\r
52 * @cfg {Boolean} hideOnClick\r
53 * False to continue showing the menu after a date is selected.\r
54 */\r
55 hideOnClick: true,\r
56\r
57 /**\r
58 * @cfg {String} pickerId\r
59 * An id to assign to the underlying date picker.\r
60 */\r
61 pickerId: null,\r
62 \r
63 /**\r
64 * @cfg {Object} [pickerCfg] Date picker configuration. This config\r
65 * takes priority over {@link #pickerId}.\r
66\r
67 /**\r
68 * @cfg {Number} maxHeight\r
69 * @private\r
70 */\r
71\r
72 /**\r
73 * @property {Ext.picker.Date} picker\r
74 * The {@link Ext.picker.Date} instance for this DateMenu\r
75 */\r
76 \r
77 // DatePicker menu is a special case; Date picker does all key handling\r
78 // except the Esc key which is also handled unlike the ordinary menu\r
79 enableFocusableContainer: false,\r
80\r
81 initComponent: function() {\r
82 var me = this,\r
83 cfg, pickerConfig;\r
84 \r
85 if (me.pickerCfg) {\r
86 pickerConfig = Ext.apply({\r
87 cls: Ext.baseCSSPrefix + 'menu-date-item',\r
88 margin: 0,\r
89 border: false,\r
90 id: me.pickerId,\r
91 xtype: 'datepicker'\r
92 }, me.pickerCfg);\r
93 }\r
94 else {\r
95 // Need to keep this insanity for backwards compat :(\r
96 cfg = Ext.apply({}, me.initialConfig);\r
97 \r
98 // Ensure we clear any listeners so they aren't duplicated\r
99 delete cfg.listeners;\r
100 \r
101 pickerConfig = Ext.applyIf({\r
102 cls: Ext.baseCSSPrefix + 'menu-date-item',\r
103 margin: 0,\r
104 border: false,\r
105 id: me.pickerId,\r
106 xtype: 'datepicker'\r
107 }, cfg);\r
108 }\r
109 \r
110 Ext.apply(me, {\r
111 showSeparator: false,\r
112 plain: true,\r
113 bodyPadding: 0, // remove the body padding from the datepicker menu item so it looks like 3.3\r
114 items: [pickerConfig]\r
115 });\r
116\r
117 me.callParent();\r
118\r
119 me.picker = me.down('datepicker');\r
120 \r
121 /**\r
122 * @event select\r
123 * @inheritdoc Ext.picker.Date#select\r
124 */\r
125 me.relayEvents(me.picker, ['select']);\r
126\r
127 if (me.hideOnClick) {\r
128 me.on('select', me.hidePickerOnSelect, me);\r
129 }\r
130 },\r
131 \r
132 onEscapeKey: function(e) {\r
133 // Unlike the other menus, DatePicker menu should not close completely on Esc key.\r
134 // This is because ordinary menu items will allow using Left arrow key to return\r
135 // to the parent menu; however in the Date picker left arrow is used to navigate\r
136 // in the calendar. So we use Esc key to return to the parent menu instead.\r
137 if (this.floating && this.ownerCmp && this.ownerCmp.focus) {\r
138 this.ownerCmp.focus();\r
139 }\r
140 },\r
141\r
142 hidePickerOnSelect: function() {\r
143 Ext.menu.Manager.hideAll();\r
144 }\r
145 });\r
146