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({
|
2021-06-07 18:36:21 +03:00
|
|
|
didInsertElement() {
|
2021-07-15 17:27:29 +03:00
|
|
|
this._super(...arguments);
|
2021-06-07 18:36:21 +03:00
|
|
|
this.onInsert?.(this.element.querySelector('input[type="file"]'));
|
|
|
|
},
|
|
|
|
|
2016-05-27 15:27:46 +03:00
|
|
|
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;
|
2021-06-16 19:56:25 +03:00
|
|
|
|
|
|
|
const clone = input.cloneNode(true);
|
|
|
|
input.parentNode.replaceChild(clone, input);
|
|
|
|
|
|
|
|
return clone;
|
2016-05-27 15:27:46 +03:00
|
|
|
}
|
|
|
|
});
|