2021-01-28 18:25:21 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modal-base';
|
2021-03-02 20:10:01 +03:00
|
|
|
import {action} from '@ember/object';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2020-05-11 13:37:35 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2021-01-22 15:28:05 +03:00
|
|
|
|
2021-01-28 18:25:21 +03:00
|
|
|
export default ModalComponent.extend({
|
2017-10-30 12:38:01 +03:00
|
|
|
config: service(),
|
|
|
|
notifications: service(),
|
2018-01-11 01:57:43 +03:00
|
|
|
settings: service(),
|
2021-02-17 18:39:51 +03:00
|
|
|
|
|
|
|
willDestroyElement() {
|
2021-02-17 18:48:23 +03:00
|
|
|
// reset any unsaved changes when closing
|
|
|
|
this.settings.rollbackAttributes();
|
2021-01-28 18:25:21 +03:00
|
|
|
},
|
|
|
|
|
2021-03-02 20:10:01 +03:00
|
|
|
registerPreviewIframe: action(function (element) {
|
|
|
|
this.previewIframe = element;
|
|
|
|
}),
|
2021-02-15 13:17:31 +03:00
|
|
|
|
2021-03-02 20:10:01 +03:00
|
|
|
replacePreviewContents: action(function (html) {
|
|
|
|
if (this.previewIframe) {
|
|
|
|
this.previewIframe.contentWindow.document.open();
|
|
|
|
this.previewIframe.contentWindow.document.write(html);
|
|
|
|
this.previewIframe.contentWindow.document.close();
|
2021-02-17 18:39:51 +03:00
|
|
|
}
|
2021-03-02 20:10:01 +03:00
|
|
|
}),
|
2019-12-04 07:14:45 +03:00
|
|
|
|
2021-02-15 13:17:31 +03:00
|
|
|
saveTask: task(function* () {
|
2018-01-11 20:43:23 +03:00
|
|
|
try {
|
2021-03-09 21:25:06 +03:00
|
|
|
if (this.get('settings.errors').length !== 0) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-17 18:48:23 +03:00
|
|
|
yield this.settings.save();
|
|
|
|
this.closeModal();
|
|
|
|
return true;
|
2018-01-11 20:43:23 +03:00
|
|
|
} catch (error) {
|
|
|
|
if (error) {
|
2021-03-02 20:10:01 +03:00
|
|
|
this.notifications.showAPIError(error);
|
2018-01-11 20:43:23 +03:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
2021-03-02 20:10:01 +03:00
|
|
|
})
|
2021-02-15 13:17:31 +03:00
|
|
|
});
|