]> git.proxmox.com Git - extjs.git/blame - extjs/modern/modern/src/field/FileInput.js
add extjs 6.0.1 sources
[extjs.git] / extjs / modern / modern / src / field / FileInput.js
CommitLineData
6527f429
DM
1/**\r
2 * @private\r
3 */\r
4Ext.define('Ext.field.FileInput', {\r
5 extend: 'Ext.field.Input',\r
6 xtype: 'fileinput',\r
7\r
8 /**\r
9 * @event change\r
10 * Fires just before the field blurs if the field value has changed\r
11 * @param {Ext.field.Text} this This field\r
12 * @param {Mixed} newValue The new value\r
13 * @param {Mixed} oldValue The original value\r
14 */\r
15\r
16 config: {\r
17 type: "file",\r
18 accept: null,\r
19 capture: null,\r
20 name: null,\r
21 multiple: false\r
22 },\r
23\r
24 /**\r
25 * @property {Object} Lookup of capture devices to accept types\r
26 * @private\r
27 */\r
28 captureLookup: {\r
29 video: "camcorder",\r
30 image: "camera",\r
31 audio: "microphone"\r
32 },\r
33\r
34 /**\r
35 * @private\r
36 */\r
37 initialize: function() {\r
38 var me = this;\r
39\r
40 me.callParent();\r
41\r
42 me.input.on({\r
43 scope: me,\r
44 change: 'onInputChange'\r
45 });\r
46 },\r
47\r
48 /**\r
49 * Returns the field data value.\r
50 * @return {String} value The field value.\r
51 */\r
52 getValue: function() {\r
53 var input = this.input;\r
54\r
55 if (input) {\r
56 this._value = input.dom.value;\r
57 }\r
58\r
59 return this._value;\r
60 },\r
61\r
62 /**\r
63 * Sets the internal value. Security restrictions prevent setting file values on the input element\r
64 * @cfg newValue {string} New Value\r
65 * @return {String}\r
66 */\r
67 setValue: function(newValue) {\r
68 var oldValue = this._value;\r
69 this._value = newValue;\r
70\r
71 if (String(this._value) != String(oldValue) && this.initialized) {\r
72 this.onChange(this, this._value, oldValue);\r
73 }\r
74\r
75 return this;\r
76 },\r
77\r
78 /**\r
79 * Returns the field files.\r
80 * @return {FileList} List of the files selected.\r
81 */\r
82 getFiles: function() {\r
83 var input = this.input;\r
84\r
85 if (input) {\r
86 this.$files = input.dom.files;\r
87 }\r
88\r
89 return this.$files;\r
90 },\r
91\r
92 /**\r
93 * @private\r
94 */\r
95 onInputChange: function(e) {\r
96 this.setValue(e.target.value);\r
97 },\r
98\r
99 /**\r
100 * Called when the value changes on this input item\r
101 * @cfg me {Ext.field.FileInput}\r
102 * @cfg value {String} new Value\r
103 * @cfg startValue {String} Original Value\r
104 */\r
105 onChange: function(me, value, startValue) {\r
106 this.fireEvent('change', me, value, startValue);\r
107 },\r
108\r
109 /**\r
110 * Called when the name being changed\r
111 * @cfg value new value\r
112 * @return {*}\r
113 */\r
114 applyName: function(value) {\r
115 if(this.getMultiple() && value.substr(-2, 2) !== "[]") {\r
116 value += "[]";\r
117 }else if((!this.getMultiple()) && value.substr(-2, 2) === "[]") {\r
118 value = value.substr(0, value.length-2)\r
119 }\r
120\r
121 return value;\r
122 },\r
123\r
124 /**\r
125 * Applies the multiple attribute to the input\r
126 * @cfg value {boolean}\r
127 * @return {boolean}\r
128 */\r
129 applyMultiple: function(value) {\r
130 this.updateFieldAttribute('multiple', value ? '' : null);\r
131 return value;\r
132 },\r
133\r
134 /**\r
135 * Called when the multiple property is updated. The name will automatically be toggled to an array if needed.\r
136 */\r
137 updateMultiple: function() {\r
138 var name = this.getName();\r
139 if(!Ext.isEmpty(name)) {\r
140 this.setName(name);\r
141 }\r
142 },\r
143\r
144 /**\r
145 * Updates the accept attribute with the {@link #accept} configuration.\r
146 */\r
147 applyAccept: function(value) {\r
148 switch (value) {\r
149 case "video":\r
150 case "audio":\r
151 case "image":\r
152 value = value + "/*";\r
153 break;\r
154 }\r
155\r
156 this.updateFieldAttribute('accept', value);\r
157 },\r
158\r
159 /**\r
160 * Updated the capture attribute with the {@ink capture} configuration\r
161 */\r
162 applyCapture: function(value) {\r
163 this.updateFieldAttribute('capture', value);\r
164 return value;\r
165 }\r
166});\r