mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 06:25:51 +03:00
508a473b43
closes https://github.com/TryGhost/Ghost/issues/7144 - allow the `accept` attr of `gh-file-uploader` and `gh-image-uploader` to be specified - allows a `validate` action to be passed into `gh-image-uploader` and `gh-file-uploader` components that runs after a file is selected and before the upload starts - adds a default `validate` action to `gh-image-uploader` and `gh-file-uploader` that triggers the normal `UnsupportedFileType` error when the selected file's mime-type does not match the `accept` attribute - adds mime type validation to labs importer (basic implementation, should be replaced with uploader components once they have been refactored)
37 lines
850 B
JavaScript
37 lines
850 B
JavaScript
import Component from 'ember-component';
|
|
|
|
export default Component.extend({
|
|
_file: null,
|
|
|
|
acceptEncoding: null,
|
|
uploadButtonText: 'Text',
|
|
uploadButtonDisabled: true,
|
|
|
|
onUpload: null,
|
|
onAdd: null,
|
|
|
|
shouldResetForm: true,
|
|
|
|
change(event) {
|
|
this.set('uploadButtonDisabled', false);
|
|
this.sendAction('onAdd');
|
|
this._file = event.target.files[0];
|
|
},
|
|
|
|
actions: {
|
|
upload() {
|
|
if (!this.get('uploadButtonDisabled') && this._file) {
|
|
this.sendAction('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();
|
|
}
|
|
}
|
|
}
|
|
});
|