2016-05-27 15:27:46 +03:00
|
|
|
import XFileInput from 'emberx-file-input/components/x-file-input';
|
|
|
|
|
2017-11-22 20:04:48 +03:00
|
|
|
// TODO: remove this override and use {{x-file-input}} directly once we've
|
|
|
|
// upgraded to emberx-file-input@1.2.0
|
2016-05-27 15:27:46 +03:00
|
|
|
|
|
|
|
export default XFileInput.extend({
|
|
|
|
change(e) {
|
2019-03-06 16:53:54 +03:00
|
|
|
let action = this.action;
|
2017-12-12 14:53:35 +03:00
|
|
|
let files = this.files(e);
|
|
|
|
|
|
|
|
if (files.length && action) {
|
|
|
|
action(files, this.resetInput.bind(this));
|
2017-11-25 02:18:35 +03:00
|
|
|
}
|
2017-11-22 20:04:48 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets files from event object.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @private
|
|
|
|
* @param {$.Event || Event}
|
|
|
|
*/
|
|
|
|
files(e) {
|
|
|
|
return (e.originalEvent || e).testingFiles || e.target.files;
|
2020-06-12 15:44:58 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the value of the input so you can select the same file
|
|
|
|
* multiple times.
|
|
|
|
*
|
|
|
|
* NOTE: fixes reset in Firefox which doesn't reset like other browsers
|
|
|
|
* when doing input.value = null;
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
resetInput() {
|
|
|
|
let input = this.element.querySelector('.x-file--input');
|
|
|
|
input.removeAttribute('value');
|
|
|
|
input.value = null;
|
|
|
|
input.parentNode.replaceChild(input.cloneNode(true), input);
|
2016-05-27 15:27:46 +03:00
|
|
|
}
|
|
|
|
});
|