2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-04-08 02:01:46 +04:00
|
|
|
var FileUpload = Ember.Component.extend({
|
|
|
|
_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
|
|
|
|
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
|
|
|
|
|
|
|
onUpload: 'onUpload',
|
|
|
|
|
2014-04-08 02:01:46 +04:00
|
|
|
actions: {
|
|
|
|
upload: function () {
|
2014-06-23 18:24:37 +04:00
|
|
|
if (!this.uploadButtonDisabled && this._file) {
|
|
|
|
this.sendAction('onUpload', this._file);
|
2014-04-08 02:01:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent double post by disabling the button.
|
|
|
|
this.set('uploadButtonDisabled', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default FileUpload;
|