2021-10-11 17:24:46 +03:00
|
|
|
import Controller from '@ember/controller';
|
2021-10-13 15:22:49 +03:00
|
|
|
import {action} from '@ember/object';
|
2021-10-11 17:24:46 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2021-10-12 17:19:27 +03:00
|
|
|
import {task} from 'ember-concurrency-decorators';
|
2021-10-13 15:22:49 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2021-10-11 17:24:46 +03:00
|
|
|
|
2021-10-12 17:19:27 +03:00
|
|
|
export default class SettingsDesignIndexController extends Controller {
|
2021-10-11 17:24:46 +03:00
|
|
|
@service config;
|
2021-10-12 17:19:27 +03:00
|
|
|
@service customThemeSettings;
|
|
|
|
@service notifications;
|
2021-10-11 17:24:46 +03:00
|
|
|
@service settings;
|
2021-10-12 17:19:27 +03:00
|
|
|
@service themeManagement;
|
|
|
|
|
2021-10-13 15:22:49 +03:00
|
|
|
@tracked previewSize = 'desktop';
|
|
|
|
|
|
|
|
get isDesktopPreview() {
|
|
|
|
return this.previewSize === 'desktop';
|
|
|
|
}
|
|
|
|
|
|
|
|
get isMobilePreview() {
|
|
|
|
return this.previewSize === 'mobile';
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
setPreviewSize(size) {
|
|
|
|
this.previewSize = size;
|
|
|
|
}
|
|
|
|
|
2021-10-19 13:59:34 +03:00
|
|
|
@action
|
|
|
|
saveFromKeyboard() {
|
|
|
|
document.activeElement.blur?.();
|
|
|
|
return this.saveTask.perform();
|
|
|
|
}
|
|
|
|
|
2021-10-12 17:19:27 +03:00
|
|
|
@task
|
|
|
|
*saveTask() {
|
|
|
|
try {
|
|
|
|
if (this.settings.get('errors').length !== 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield Promise.all([
|
|
|
|
this.settings.save(),
|
|
|
|
this.customThemeSettings.save()
|
|
|
|
]);
|
|
|
|
|
|
|
|
// ensure task button switches to success state
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
if (error) {
|
|
|
|
this.notifications.showAPIError(error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-20 19:34:53 +03:00
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.previewSize = 'desktop';
|
|
|
|
this.themeManagement.setPreviewType('homepage');
|
|
|
|
}
|
2021-10-11 17:24:46 +03:00
|
|
|
}
|