]> git.proxmox.com Git - extjs.git/blame - extjs/modern/modern/src/field/Picker.js
add extjs 6.0.1 sources
[extjs.git] / extjs / modern / modern / src / field / Picker.js
CommitLineData
6527f429
DM
1/**\r
2 * An abstract class for fields that have a single trigger which opens a "picker" popup \r
3 * above the field. It provides a base implementation for toggling the picker's \r
4 * visibility when the trigger is tapped.\r
5 *\r
6 * You would not normally use this class directly, but instead use it as the parent \r
7 * class for a specific picker field implementation.\r
8 */\r
9Ext.define('Ext.field.Picker', {\r
10 extend: 'Ext.field.Text',\r
11\r
12 config: {\r
13\r
14 /**\r
15 * @cfg {Object} component\r
16 * @accessor\r
17 * @hide\r
18 */\r
19 component: {\r
20 useMask: true\r
21 },\r
22\r
23 /**\r
24 * @cfg {Boolean} clearIcon\r
25 * @hide\r
26 * @accessor\r
27 */\r
28 clearIcon: false,\r
29\r
30 /**\r
31 * @cfg {String/Boolean} usePicker\r
32 * `true` if you want this component to always use a {@link Ext.picker.Picker}.\r
33 * `false` if you want it to use a popup overlay {@link Ext.List}.\r
34 * `auto` if you want to show a {@link Ext.picker.Picker} only on phones.\r
35 */\r
36 usePicker: 'auto',\r
37\r
38 /**\r
39 * @cfg {Object} defaultPhonePickerConfig\r
40 * The default configuration for the picker component when you are on a phone.\r
41 * @private\r
42 */\r
43 defaultPhonePickerConfig: null,\r
44\r
45 /**\r
46 * @cfg {Object} defaultTabletPickerConfig\r
47 * The default configuration for the picker component when you are on a tablet.\r
48 * @private\r
49 */\r
50 defaultTabletPickerConfig: null,\r
51\r
52 /**\r
53 * @cfg {String} pickerSlotAlign\r
54 * The alignment of text in the picker created by this Select\r
55 * @private\r
56 */\r
57 pickerSlotAlign: 'center'\r
58 },\r
59\r
60 /**\r
61 * @private\r
62 */\r
63 initialize: function() {\r
64 var me = this,\r
65 component = me.getComponent();\r
66\r
67 me.callParent();\r
68\r
69 component.on({\r
70 scope: me,\r
71 masktap: 'onMaskTap'\r
72 });\r
73\r
74 component.doMaskTap = Ext.emptyFn;\r
75 },\r
76\r
77 /**\r
78 * @private\r
79 */\r
80 updateDefaultPhonePickerConfig: function(newConfig) {\r
81 var phonePicker = this.phonePicker;\r
82 if (phonePicker) {\r
83 phonePicker.setConfig(newConfig);\r
84 }\r
85 },\r
86\r
87 /**\r
88 * @private\r
89 */\r
90 updateDefaultTabletPickerConfig: function(newConfig) {\r
91 var tabletPicker = this.tabletPicker;\r
92 if (tabletPicker) {\r
93 tabletPicker.setConfig(newConfig);\r
94 }\r
95 },\r
96\r
97 /**\r
98 * @private\r
99 * Checks if the value is `auto`. If it is, it only uses the picker if the current device type\r
100 * is a phone.\r
101 */\r
102 applyUsePicker: function(usePicker) {\r
103 if (usePicker === 'auto') {\r
104 usePicker = Ext.os.deviceType === 'Phone';\r
105 }\r
106\r
107 return Boolean(usePicker);\r
108 },\r
109\r
110 syncEmptyCls: Ext.emptyFn,\r
111\r
112 /**\r
113 * @private\r
114 */\r
115 onMaskTap: function() {\r
116 if (!this.getDisabled()) {\r
117 this.onFocus();\r
118 }\r
119\r
120 return false;\r
121 },\r
122\r
123 /**\r
124 * @private\r
125 */\r
126 updateDisabled: function(disabled) {\r
127 var component = this.getComponent();\r
128 if (component) {\r
129 component.setDisabled(disabled);\r
130 }\r
131 Ext.Component.prototype.updateDisabled.apply(this, arguments);\r
132 },\r
133\r
134 /**\r
135 * @private\r
136 */\r
137 setDisabled: function() {\r
138 Ext.Component.prototype.setDisabled.apply(this, arguments);\r
139 },\r
140\r
141 onFocus: function(e) {\r
142 if (this.getDisabled()) {\r
143 return false;\r
144 }\r
145\r
146 var component = this.getComponent();\r
147 this.fireEvent('focus', this, e);\r
148\r
149 if (Ext.os.is.Android4) {\r
150 component.input.dom.focus();\r
151 }\r
152 component.input.dom.blur();\r
153\r
154 this.isFocused = true;\r
155\r
156 this.showPicker();\r
157 },\r
158\r
159 destroy: function() {\r
160 var me = this;\r
161\r
162 me.callParent();\r
163\r
164 me.tabletPicker = me.phonePicker = Ext.destroy(me.tabletPicker, me.phonePicker);\r
165 }\r
166});\r