discourse/app/assets/javascripts/admin/addon/models/site-setting.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-11-09 03:13:35 +08:00
import EmberObject from "@ember/object";
import { alias } from "@ember/object/computed";
2019-11-09 03:13:35 +08:00
import { ajax } from "discourse/lib/ajax";
import discourseComputed from "discourse-common/utils/decorators";
import { i18n } from "discourse-i18n";
import SettingObjectHelper from "admin/lib/setting-object-helper";
2015-03-03 01:12:19 +08:00
export default class SiteSetting extends EmberObject {
static findAll(params = {}) {
return ajax("/admin/site_settings", { data: params }).then(function (
settings
) {
2015-03-03 01:12:19 +08:00
// Group the results by category
const categories = {};
settings.site_settings.forEach(function (s) {
if (!categories[s.category]) {
categories[s.category] = [];
}
categories[s.category].pushObject(SiteSetting.create(s));
2015-03-03 01:12:19 +08:00
});
return Object.keys(categories).map(function (n) {
return {
nameKey: n,
name: i18n("admin.site_settings.categories." + n),
2015-03-03 01:12:19 +08:00
siteSettings: categories[n],
};
});
});
}
2015-03-03 01:12:19 +08:00
static update(key, value, opts = {}) {
2015-03-03 01:12:19 +08:00
const data = {};
data[key] = value;
if (opts["updateExistingUsers"] === true) {
data["update_existing_user"] = true;
}
return ajax(`/admin/site_settings/${key}`, { type: "PUT", data });
}
2015-03-03 01:12:19 +08:00
settingObjectHelper = new SettingObjectHelper(this);
@alias("settingObjectHelper.overridden") overridden;
@alias("settingObjectHelper.computedValueProperty") computedValueProperty;
@alias("settingObjectHelper.computedNameProperty") computedNameProperty;
@alias("settingObjectHelper.validValues") validValues;
@alias("settingObjectHelper.allowsNone") allowsNone;
@alias("settingObjectHelper.anyValue") anyValue;
@discourseComputed("setting")
staffLogFilter(setting) {
if (!setting) {
return;
}
return {
subject: setting,
action_name: "change_site_setting",
};
}
}