mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
1e8e0485e3
refs https://github.com/TryGhost/Team/issues/1070 - adds a `customThemeSettings` service that handles overall setting loading and saving to avoid components having to know any of the intricacies of the model setup - adds `custom-theme-setting-list` model so that we can save multiple setting records as embedded relations - custom adapter ensures requests go to the `/custom_theme_settings` base route as a `PUT` request - custom serializer drops the default `models: []` wrapper in the save request data so the format matches the `PUT /settings` endpoint, then converts the response to look like a `custom-theme-setting-list` response
24 lines
1.0 KiB
JavaScript
24 lines
1.0 KiB
JavaScript
import ApplicationSerializer from './application';
|
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
|
|
|
export default class CustomThemeSettingList extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
|
attrs = {
|
|
customThemeSettings: {embedded: 'always'}
|
|
}
|
|
|
|
serializeIntoHash(hash, type, record, options) {
|
|
// replace the whole request hash with the embedded custom_theme_settings array
|
|
const settings = this.serialize(record, options);
|
|
Object.assign(hash, settings);
|
|
}
|
|
|
|
normalizeSingleResponse(store, primaryModelClass, _payload, id, requestType) {
|
|
// response will come back as a custom theme settings array, not a "customThemeSettingList" array/object
|
|
// make it look like the list model so Ember Data does it's thing and doesn't complain
|
|
const payload = {
|
|
customThemeSettingLists: [Object.assign({id: 0}, _payload)]
|
|
};
|
|
return super.normalizeSingleResponse(store, primaryModelClass, payload, id, requestType);
|
|
}
|
|
}
|