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:
Mark VanLandingham 2019-10-29 12:01:45 -05:00 committed by GitHub
parent 29e41dc511
commit 0a499966e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 35 deletions

View File

@ -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);
}
}
});

View File

@ -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")
}
});
}
});

View File

@ -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() {