mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 18:04:38 +08:00
422f395042
A while ago we made a change to display a warning after installing a theme component when the admin tries to leave the page without adding the new installed component to any themes (see 5e29ae3ef5
).
However there is an edge case that we forgot to address, and that's when an admin installs a component and then immediately opens the install modal again to install another one which can result in the warning being shown twice at the same time.
This PR prevents that by showing the warning when opening the install modal if the conditions are met (new component and not added to any themes) instead of showing it after installing the second component.
83 lines
2.1 KiB
JavaScript
83 lines
2.1 KiB
JavaScript
import { COMPONENTS, THEMES } from "admin/models/theme";
|
|
import I18n from "I18n";
|
|
import Route from "@ember/routing/route";
|
|
import { scrollTop } from "discourse/mixins/scroll-top";
|
|
|
|
export function showUnassignedComponentWarning(theme, callback) {
|
|
bootbox.confirm(
|
|
I18n.t("admin.customize.theme.unsaved_parent_themes"),
|
|
I18n.t("admin.customize.theme.discard"),
|
|
I18n.t("admin.customize.theme.stay"),
|
|
(result) => {
|
|
if (!result) {
|
|
theme.set("recentlyInstalled", false);
|
|
}
|
|
callback(result);
|
|
}
|
|
);
|
|
}
|
|
|
|
export default Route.extend({
|
|
serialize(model) {
|
|
return { theme_id: model.get("id") };
|
|
},
|
|
|
|
model(params) {
|
|
const all = this.modelFor("adminCustomizeThemes");
|
|
const model = all.findBy("id", parseInt(params.theme_id, 10));
|
|
return model ? model : this.replaceWith("adminCustomizeThemes.index");
|
|
},
|
|
|
|
setupController(controller, model) {
|
|
this._super(...arguments);
|
|
|
|
const parentController = this.controllerFor("adminCustomizeThemes");
|
|
|
|
parentController.setProperties({
|
|
editingTheme: false,
|
|
currentTab: model.get("component") ? COMPONENTS : THEMES,
|
|
});
|
|
|
|
controller.setProperties({
|
|
model: model,
|
|
parentController: parentController,
|
|
allThemes: parentController.get("model"),
|
|
colorSchemeId: model.get("color_scheme_id"),
|
|
colorSchemes: parentController.get("model.extras.color_schemes"),
|
|
editingName: false,
|
|
});
|
|
|
|
this.handleHighlight(model);
|
|
},
|
|
|
|
deactivate() {
|
|
this.handleHighlight();
|
|
},
|
|
|
|
handleHighlight(theme) {
|
|
this.get("controller.allThemes")
|
|
.filter((t) => t.get("selected"))
|
|
.forEach((t) => t.set("selected", false));
|
|
if (theme) {
|
|
theme.set("selected", true);
|
|
}
|
|
},
|
|
|
|
actions: {
|
|
didTransition() {
|
|
scrollTop();
|
|
},
|
|
willTransition(transition) {
|
|
const model = this.controller.model;
|
|
if (model.warnUnassignedComponent) {
|
|
transition.abort();
|
|
showUnassignedComponentWarning(model, (result) => {
|
|
if (!result) {
|
|
transition.retry();
|
|
}
|
|
});
|
|
}
|
|
},
|
|
},
|
|
});
|