2018-06-15 23:03:24 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import Setting from "admin/mixins/setting-object";
|
2019-11-09 03:13:35 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2015-03-03 01:12:19 +08:00
|
|
|
|
2019-11-09 03:13:35 +08:00
|
|
|
const SiteSetting = EmberObject.extend(Setting, {});
|
2015-03-03 01:12:19 +08:00
|
|
|
|
|
|
|
SiteSetting.reopenClass({
|
|
|
|
findAll() {
|
2018-06-15 23:03:24 +08:00
|
|
|
return ajax("/admin/site_settings").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] = [];
|
|
|
|
}
|
2015-11-21 09:27:06 +08:00
|
|
|
categories[s.category].pushObject(SiteSetting.create(s));
|
2015-03-03 01:12:19 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return Object.keys(categories).map(function(n) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return {
|
|
|
|
nameKey: n,
|
|
|
|
name: I18n.t("admin.site_settings.categories." + n),
|
|
|
|
siteSettings: categories[n]
|
|
|
|
};
|
2015-03-03 01:12:19 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-10-15 21:11:27 +08:00
|
|
|
update(key, value, opts = {}) {
|
2015-03-03 01:12:19 +08:00
|
|
|
const data = {};
|
|
|
|
data[key] = value;
|
2019-10-15 21:11:27 +08:00
|
|
|
|
|
|
|
if (opts["updateExistingUsers"] === true) {
|
|
|
|
data["updateExistingUsers"] = true;
|
|
|
|
}
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
return ajax(`/admin/site_settings/${key}`, { type: "PUT", data });
|
2015-03-03 01:12:19 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default SiteSetting;
|