2023-03-15 21:17:51 +08:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
import { inject as service } from "@ember/service";
|
2018-08-31 03:23:15 +08:00
|
|
|
import { COMPONENTS, THEMES } from "admin/models/theme";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-10-24 00:39:32 +08:00
|
|
|
import Route from "@ember/routing/route";
|
2018-08-24 09:30:00 +08:00
|
|
|
import { scrollTop } from "discourse/mixins/scroll-top";
|
2021-01-11 23:29:12 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
export default class AdminCustomizeThemesShowRoute extends Route {
|
|
|
|
@service dialog;
|
2023-08-22 05:53:54 +08:00
|
|
|
@service router;
|
2022-10-07 23:38:27 +08:00
|
|
|
|
2017-04-12 22:52:52 +08:00
|
|
|
serialize(model) {
|
|
|
|
return { theme_id: model.get("id") };
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
model(params) {
|
|
|
|
const all = this.modelFor("adminCustomizeThemes");
|
2019-11-12 17:47:42 +08:00
|
|
|
const model = all.findBy("id", parseInt(params.theme_id, 10));
|
2023-08-22 05:53:54 +08:00
|
|
|
if (model) {
|
|
|
|
return model;
|
|
|
|
} else {
|
|
|
|
this.router.replaceWith("adminCustomizeThemes.index");
|
|
|
|
}
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
setupController(controller, model) {
|
2023-03-15 21:17:51 +08:00
|
|
|
super.setupController(...arguments);
|
2018-08-24 09:30:00 +08:00
|
|
|
|
2017-04-12 22:52:52 +08:00
|
|
|
const parentController = this.controllerFor("adminCustomizeThemes");
|
2019-04-11 12:55:32 +08:00
|
|
|
|
2018-08-31 03:23:15 +08:00
|
|
|
parentController.setProperties({
|
|
|
|
editingTheme: false,
|
|
|
|
currentTab: model.get("component") ? COMPONENTS : THEMES,
|
|
|
|
});
|
|
|
|
|
|
|
|
controller.setProperties({
|
2021-11-10 07:31:41 +08:00
|
|
|
model,
|
|
|
|
parentController,
|
2018-08-31 03:23:15 +08:00
|
|
|
allThemes: parentController.get("model"),
|
2022-12-08 05:21:51 +08:00
|
|
|
colorSchemeId: model.get("color_scheme_id"),
|
2019-04-11 12:55:32 +08:00
|
|
|
colorSchemes: parentController.get("model.extras.color_schemes"),
|
|
|
|
editingName: false,
|
2018-08-31 03:23:15 +08:00
|
|
|
});
|
2018-08-24 09:30:00 +08:00
|
|
|
|
|
|
|
this.handleHighlight(model);
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2018-08-24 09:30:00 +08:00
|
|
|
|
|
|
|
deactivate() {
|
|
|
|
this.handleHighlight();
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2018-08-24 09:30:00 +08:00
|
|
|
|
|
|
|
handleHighlight(theme) {
|
2018-09-07 02:56:00 +08:00
|
|
|
this.get("controller.allThemes")
|
|
|
|
.filter((t) => t.get("selected"))
|
|
|
|
.forEach((t) => t.set("selected", false));
|
2018-08-24 09:30:00 +08:00
|
|
|
if (theme) {
|
2018-09-07 02:56:00 +08:00
|
|
|
theme.set("selected", true);
|
2018-08-24 09:30:00 +08:00
|
|
|
}
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2018-08-24 09:30:00 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
@action
|
|
|
|
didTransition() {
|
|
|
|
scrollTop();
|
|
|
|
}
|
2022-10-07 23:38:27 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
@action
|
|
|
|
willTransition(transition) {
|
|
|
|
const model = this.controller.model;
|
|
|
|
if (model.warnUnassignedComponent) {
|
|
|
|
transition.abort();
|
|
|
|
|
|
|
|
this.dialog.yesNoConfirm({
|
|
|
|
message: I18n.t("admin.customize.theme.unsaved_parent_themes"),
|
|
|
|
didConfirm: () => {
|
|
|
|
model.set("recentlyInstalled", false);
|
|
|
|
transition.retry();
|
|
|
|
},
|
|
|
|
didCancel: () => model.set("recentlyInstalled", false),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|