2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
|
|
|
export default Component.extend({
|
2014-04-08 02:01:46 +04:00
|
|
|
_file: null,
|
2014-06-23 18:24:37 +04:00
|
|
|
|
2016-08-22 14:45:33 +03:00
|
|
|
acceptEncoding: null,
|
2014-04-08 02:01:46 +04:00
|
|
|
uploadButtonText: 'Text',
|
|
|
|
uploadButtonDisabled: true,
|
2014-06-23 18:24:37 +04:00
|
|
|
|
2018-01-11 20:43:23 +03:00
|
|
|
shouldResetForm: true,
|
|
|
|
|
2017-09-22 22:59:05 +03:00
|
|
|
// closure actions
|
|
|
|
onUpload() {},
|
|
|
|
onAdd() {},
|
2015-06-13 17:34:09 +03:00
|
|
|
|
2014-04-08 02:01:46 +04:00
|
|
|
actions: {
|
2015-10-28 14:36:45 +03:00
|
|
|
upload() {
|
2019-03-06 16:53:54 +03:00
|
|
|
if (!this.uploadButtonDisabled && this._file) {
|
2017-09-22 22:59:05 +03:00
|
|
|
this.onUpload(this._file);
|
2014-04-08 02:01:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent double post by disabling the button.
|
|
|
|
this.set('uploadButtonDisabled', true);
|
2015-06-13 17:34:09 +03:00
|
|
|
|
|
|
|
// Reset form
|
2019-03-06 16:53:54 +03:00
|
|
|
if (this.shouldResetForm) {
|
2020-01-10 18:12:39 +03:00
|
|
|
this.element.closest('form').reset();
|
2015-06-13 17:34:09 +03:00
|
|
|
}
|
2014-04-08 02:01:46 +04:00
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
change(event) {
|
|
|
|
this.set('uploadButtonDisabled', false);
|
|
|
|
this.onAdd();
|
|
|
|
this._file = event.target.files[0];
|
2014-04-08 02:01:46 +04:00
|
|
|
}
|
|
|
|
});
|