mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
85cce39af7
refs https://github.com/TryGhost/Team/issues/1734 refs https://github.com/TryGhost/Team/issues/559 refs https://github.com/TryGhost/Ghost/issues/14101 - switches to newer modal patterns ready for later Ember upgrades - cleaned up the `upload-image` modal which had multiple areas of code that were no longer being used - disabled `no-duplicate-landmark-elements` template lint rule as it's buggy and mostly gives false positives
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
export default class UploadImageModal extends Component {
|
|
@service notifications;
|
|
|
|
@tracked errorMessage;
|
|
@tracked isUploading = false;
|
|
@tracked url = '';
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.url = this._getModelProperty();
|
|
}
|
|
|
|
@action
|
|
fileUploaded(url) {
|
|
this.url = url;
|
|
}
|
|
|
|
@action
|
|
removeImage() {
|
|
this.url = '';
|
|
}
|
|
|
|
@task({drop: true})
|
|
*uploadImageTask() {
|
|
this._setModelProperty(this.url);
|
|
|
|
try {
|
|
yield this.args.data.model.save();
|
|
} catch (e) {
|
|
this.notifications.showAPIError(e, {key: 'image.upload'});
|
|
} finally {
|
|
this.args.close();
|
|
}
|
|
}
|
|
|
|
_getModelProperty() {
|
|
const {model, modelProperty} = this.args.data;
|
|
return model[modelProperty];
|
|
}
|
|
|
|
_setModelProperty(url) {
|
|
const {model, modelProperty} = this.args.data;
|
|
model[modelProperty] = url;
|
|
return url;
|
|
}
|
|
}
|