2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2021-10-18 15:46:29 +03:00
|
|
|
/* eslint-disable ghost/ember/alias-model-in-controller */
|
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
export default class FirstpromoterController extends Controller {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service notifications;
|
|
|
|
@service settings;
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
leaveSettingsTransition = null;
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
update(value) {
|
|
|
|
this.settings.set('firstpromoter', value);
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
save() {
|
|
|
|
this.save.perform();
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
toggleLeaveSettingsModal(transition) {
|
|
|
|
let leaveTransition = this.leaveSettingsTransition;
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
if (!transition && this.showLeaveSettingsModal) {
|
|
|
|
this.set('leaveSettingsTransition', null);
|
|
|
|
this.set('showLeaveSettingsModal', false);
|
|
|
|
return;
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
if (!leaveTransition || transition.targetName === leaveTransition.targetName) {
|
|
|
|
this.set('leaveSettingsTransition', transition);
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
// if a save is running, wait for it to finish then transition
|
|
|
|
if (this.save.isRunning) {
|
|
|
|
return this.save.last.then(() => {
|
|
|
|
transition.retry();
|
|
|
|
});
|
2021-10-18 15:46:29 +03:00
|
|
|
}
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
// we genuinely have unsaved data, show the modal
|
|
|
|
this.set('showLeaveSettingsModal', true);
|
|
|
|
}
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@action
|
|
|
|
leaveSettings() {
|
|
|
|
let transition = this.leaveSettingsTransition;
|
|
|
|
let settings = this.settings;
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
if (!transition) {
|
|
|
|
this.notifications.showAlert('Sorry, there was an error in the application. Please let the Ghost team know what happened.', {type: 'error'});
|
|
|
|
return;
|
2021-10-18 15:46:29 +03:00
|
|
|
}
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
// roll back changes on settings model
|
|
|
|
settings.rollbackAttributes();
|
|
|
|
|
|
|
|
return transition.retry();
|
|
|
|
}
|
|
|
|
|
|
|
|
@(task(function* () {
|
2021-10-18 15:46:29 +03:00
|
|
|
try {
|
|
|
|
yield this.settings.validate();
|
|
|
|
return yield this.settings.save();
|
|
|
|
} catch (error) {
|
|
|
|
this.notifications.showAPIError(error);
|
|
|
|
throw error;
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}).drop())
|
|
|
|
save;
|
|
|
|
}
|