2016-06-30 21:14:25 +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
|
|
|
|
2014-04-08 02:01:46 +04:00
|
|
|
uploadButtonText: 'Text',
|
|
|
|
uploadButtonDisabled: true,
|
2014-06-23 18:24:37 +04:00
|
|
|
|
2015-06-13 17:34:09 +03:00
|
|
|
onUpload: null,
|
|
|
|
onAdd: null,
|
|
|
|
|
|
|
|
shouldResetForm: true,
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
change(event) {
|
2014-04-08 02:01:46 +04:00
|
|
|
this.set('uploadButtonDisabled', false);
|
|
|
|
this.sendAction('onAdd');
|
|
|
|
this._file = event.target.files[0];
|
|
|
|
},
|
2014-06-23 18:24:37 +04:00
|
|
|
|
2014-04-08 02:01:46 +04:00
|
|
|
actions: {
|
2015-10-28 14:36:45 +03:00
|
|
|
upload() {
|
2015-06-13 17:34:09 +03:00
|
|
|
if (!this.get('uploadButtonDisabled') && this._file) {
|
2014-06-23 18:24:37 +04:00
|
|
|
this.sendAction('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
|
|
|
|
if (this.get('shouldResetForm')) {
|
2015-10-28 14:36:45 +03:00
|
|
|
this.$().closest('form')[0].reset();
|
2015-06-13 17:34:09 +03:00
|
|
|
}
|
2014-04-08 02:01:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|