2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import {action} from '@ember/object';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
export default class GhFileUpload extends Component {
|
|
|
|
_file = null;
|
|
|
|
acceptEncoding = null;
|
|
|
|
uploadButtonText = 'Text';
|
|
|
|
uploadButtonDisabled = true;
|
|
|
|
shouldResetForm = true;
|
2018-01-11 20:43:23 +03:00
|
|
|
|
2017-09-22 22:59:05 +03:00
|
|
|
// closure actions
|
2022-02-01 12:34:03 +03:00
|
|
|
onUpload() {}
|
2015-06-13 17:34:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
onAdd() {}
|
2014-04-08 02:01:46 +04:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
upload() {
|
|
|
|
if (!this.uploadButtonDisabled && this._file) {
|
|
|
|
this.onUpload(this._file);
|
|
|
|
}
|
2015-06-13 17:34:09 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
// Prevent double post by disabling the button.
|
|
|
|
this.set('uploadButtonDisabled', true);
|
|
|
|
|
|
|
|
// Reset form
|
|
|
|
if (this.shouldResetForm) {
|
|
|
|
this.element.closest('form').reset();
|
2014-04-08 02:01:46 +04:00
|
|
|
}
|
2022-02-01 12:34:03 +03: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
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|