discourse/app/assets/javascripts/admin/addon/models/theme-settings.js
Alan Guo Xiang Tan ef99b97ea7
DEV: Load theme objects typed setting metadata when routing to editor (#26354)
Why this change?

Previously, we were preloading the necessary metadata for
`adminCustomizeThemes.show.schema` route in the
`adminCustomizeThemes.show` route. This is wasteful because we're
loading data upfront when the objects setting editor may not be used.

This change also lays the ground work for a future commit where we need
to be shipping down additional metadata which may further add to the
payload.
2024-03-26 14:02:05 +08:00

29 lines
766 B
JavaScript

import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import Setting from "admin/mixins/setting-object";
export default class ThemeSettings extends EmberObject.extend(Setting) {
updateSetting(themeId, newValue) {
if (this.objects_schema) {
newValue = JSON.stringify(newValue);
}
return ajax(`/admin/themes/${themeId}/setting`, {
type: "PUT",
data: {
name: this.setting,
value: newValue,
},
});
}
loadMetadata(themeId) {
return ajax(
`/admin/themes/${themeId}/objects_setting_metadata/${this.setting}.json`
)
.then((result) => this.set("metadata", result))
.catch(popupAjaxError);
}
}