Ghost/ghost/admin/app/components/gh-file-upload.js
Kevin Ansfield bd5f7a8daa 🐛 Fixed missing "file too large" text for import uploads (#867)
closes https://github.com/TryGhost/Ghost/issues/8660

- detect a `413` when uploading an import and show the appropriate message
- refactor `{{gh-file-upload}}` to use closure actions
- add test selectors to import errors HTML
- note: doesn't include tests because `{{gh-file-upload}}` doesn't rely on the file input's `change` event (as used by our other uploader components to facilitate testing) and browsers don't allow us to artificially set and submit files
2017-09-22 21:59:05 +02:00

38 lines
846 B
JavaScript

import Component from '@ember/component';
export default Component.extend({
_file: null,
acceptEncoding: null,
uploadButtonText: 'Text',
uploadButtonDisabled: true,
// closure actions
onUpload() {},
onAdd() {},
shouldResetForm: true,
change(event) {
this.set('uploadButtonDisabled', false);
this.onAdd();
this._file = event.target.files[0];
},
actions: {
upload() {
if (!this.get('uploadButtonDisabled') && this._file) {
this.onUpload(this._file);
}
// Prevent double post by disabling the button.
this.set('uploadButtonDisabled', true);
// Reset form
if (this.get('shouldResetForm')) {
this.$().closest('form')[0].reset();
}
}
}
});