2020-01-30 18:35:36 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modal-base';
|
2020-02-03 19:27:42 +03:00
|
|
|
import {resetQueryParams} from 'ghost-admin/helpers/reset-query-params';
|
2020-01-30 18:35:36 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {task, timeout} from 'ember-concurrency';
|
|
|
|
|
|
|
|
export default ModalComponent.extend({
|
|
|
|
customViews: service(),
|
2020-02-03 19:27:42 +03:00
|
|
|
router: service(),
|
2020-01-30 18:35:36 +03:00
|
|
|
|
|
|
|
delayedModelColor: '',
|
|
|
|
|
|
|
|
confirm() {},
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.set('model', this.customViews.editView());
|
|
|
|
this._setDelayedModelColor.perform();
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
changeColor(event) {
|
|
|
|
let color = event.target.value;
|
|
|
|
this.set('model.color', color);
|
|
|
|
this.set('delayedModelColor', color);
|
|
|
|
},
|
|
|
|
|
|
|
|
confirm() {
|
|
|
|
return this.saveTask.perform();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
saveTask: task(function* () {
|
|
|
|
let view = yield this.customViews.saveViewTask.perform(this.model);
|
|
|
|
this.send('closeModal');
|
|
|
|
return view;
|
|
|
|
}),
|
|
|
|
|
|
|
|
deleteTask: task(function* () {
|
|
|
|
let view = yield this.customViews.deleteViewTask.perform(this.model);
|
2020-02-03 19:27:42 +03:00
|
|
|
let routeName = this.router.currentRouteName;
|
2020-01-30 18:35:36 +03:00
|
|
|
this.send('closeModal');
|
2020-02-03 19:27:42 +03:00
|
|
|
this.router.transitionTo(routeName, {queryParams: resetQueryParams(routeName)});
|
2020-01-30 18:35:36 +03:00
|
|
|
return view;
|
|
|
|
}),
|
|
|
|
|
|
|
|
// this is a hack to get around radio buttons not working with liquid-fire.
|
|
|
|
// The DOM is duplicated whilst animating-in so browsers end up setting the
|
|
|
|
// checked property on the temporary DOM. Delaying the value being set
|
|
|
|
// allows us to ensure we're updating the checked property after animation
|
|
|
|
_setDelayedModelColor: task(function* () {
|
|
|
|
yield timeout(200);
|
|
|
|
this.set('delayedModelColor', this.model.color);
|
|
|
|
})
|
|
|
|
});
|