mirror of
https://github.com/discourse/discourse.git
synced 2025-02-28 16:29:22 +00:00
DEV: Refactor setting component save callback (#8261)
* DEV: Refactor setting component save callback * refactor site-setting component around new callback * add callback to theme-translation component * remove the save callback altogether
This commit is contained in:
parent
29e41dc511
commit
0a499966e9
@ -6,7 +6,7 @@ import showModal from "discourse/lib/show-modal";
|
||||
import AboutRoute from "discourse/routes/about";
|
||||
|
||||
export default Component.extend(BufferedContent, SettingComponent, {
|
||||
_save(callback) {
|
||||
_save() {
|
||||
const defaultCategoriesSettings = [
|
||||
"default_categories_watching",
|
||||
"default_categories_tracking",
|
||||
@ -30,15 +30,13 @@ export default Component.extend(BufferedContent, SettingComponent, {
|
||||
});
|
||||
|
||||
controller.set("onClose", () => {
|
||||
callback(
|
||||
SiteSetting.update(key, value, {
|
||||
updateExistingUsers: controller.updateExistingUsers
|
||||
})
|
||||
);
|
||||
return SiteSetting.update(key, value, {
|
||||
updateExistingUsers: controller.updateExistingUsers
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
callback(SiteSetting.update(key, value));
|
||||
return SiteSetting.update(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -2,20 +2,17 @@ import Component from "@ember/component";
|
||||
import BufferedContent from "discourse/mixins/buffered-content";
|
||||
import SettingComponent from "admin/mixins/setting-component";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
|
||||
export default Component.extend(BufferedContent, SettingComponent, {
|
||||
layoutName: "admin/templates/components/site-setting",
|
||||
|
||||
_save(callback) {
|
||||
callback(
|
||||
ajax(`/admin/themes/${this.model.id}/setting`, {
|
||||
type: "PUT",
|
||||
data: {
|
||||
name: this.setting.setting,
|
||||
value: this.get("buffered.value")
|
||||
}
|
||||
}).catch(popupAjaxError)
|
||||
);
|
||||
_save() {
|
||||
return ajax(`/admin/themes/${this.model.id}/setting`, {
|
||||
type: "PUT",
|
||||
data: {
|
||||
name: this.setting.setting,
|
||||
value: this.get("buffered.value")
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -111,23 +111,21 @@ export default Ember.Mixin.create({
|
||||
|
||||
actions: {
|
||||
save() {
|
||||
this._save(result => {
|
||||
result
|
||||
.then(() => {
|
||||
this.set("validationMessage", null);
|
||||
this.commitBuffer();
|
||||
if (AUTO_REFRESH_ON_SAVE.includes(this.setting.setting)) {
|
||||
this.afterSave();
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
||||
this.set("validationMessage", e.jqXHR.responseJSON.errors[0]);
|
||||
} else {
|
||||
this.set("validationMessage", I18n.t("generic_error"));
|
||||
}
|
||||
});
|
||||
});
|
||||
this._save()
|
||||
.then(() => {
|
||||
this.set("validationMessage", null);
|
||||
this.commitBuffer();
|
||||
if (AUTO_REFRESH_ON_SAVE.includes(this.setting.setting)) {
|
||||
this.afterSave();
|
||||
}
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
||||
this.set("validationMessage", e.jqXHR.responseJSON.errors[0]);
|
||||
} else {
|
||||
this.set("validationMessage", I18n.t("generic_error"));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
cancel() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user