1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/components/gh-file-upload.js
Kevin Ansfield 56ba6e2171 🐛 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

37 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();
}
}
}
});