2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2015-06-13 17:34:09 +03:00
|
|
|
|
|
|
|
export default Ember.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',
|
2014-06-23 18:24:37 +04:00
|
|
|
|
2014-04-08 02:01:46 +04:00
|
|
|
uploadButtonDisabled: true,
|
2014-06-23 18:24:37 +04:00
|
|
|
|
2015-06-13 17:34:09 +03:00
|
|
|
onUpload: null,
|
|
|
|
onAdd: null,
|
|
|
|
|
|
|
|
shouldResetForm: true,
|
|
|
|
|
2014-04-08 02:01:46 +04:00
|
|
|
change: function (event) {
|
|
|
|
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: {
|
|
|
|
upload: function () {
|
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')) {
|
|
|
|
this.$().closest('form').get(0).reset();
|
|
|
|
}
|
2014-04-08 02:01:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|