2023-03-15 21:17:51 +08:00
|
|
|
import { action } from "@ember/object";
|
2023-10-11 02:38:59 +08:00
|
|
|
import Route from "@ember/routing/route";
|
2024-03-07 01:05:11 +08:00
|
|
|
import { service } from "@ember/service";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from "discourse-i18n";
|
2020-08-27 00:57:13 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
export default class AdminCustomizeThemesEditRoute extends Route {
|
|
|
|
@service dialog;
|
2023-07-19 03:52:55 +08:00
|
|
|
@service router;
|
2022-10-07 23:38:27 +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,
|
|
|
|
target: params.target,
|
|
|
|
field_name: params.field_name,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.router.replaceWith("adminCustomizeThemes.index");
|
|
|
|
}
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
serialize(wrapper) {
|
|
|
|
return {
|
|
|
|
model: wrapper.model,
|
|
|
|
target: wrapper.target || "common",
|
|
|
|
field_name: wrapper.field_name || "scss",
|
|
|
|
theme_id: wrapper.model.get("id"),
|
|
|
|
};
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
setupController(controller, wrapper) {
|
2019-02-19 20:56:01 +08:00
|
|
|
const fields = wrapper.model
|
|
|
|
.get("fields")
|
|
|
|
[wrapper.target].map((f) => f.name);
|
2020-12-10 03:41:42 +08:00
|
|
|
if (wrapper.model.remote_theme && wrapper.model.remote_theme.is_git) {
|
2023-07-19 03:52:55 +08:00
|
|
|
this.router.transitionTo("adminCustomizeThemes.index");
|
2020-11-13 23:57:49 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-03-05 08:04:23 +08:00
|
|
|
if (!fields.includes(wrapper.field_name)) {
|
2023-07-19 03:52:55 +08:00
|
|
|
this.router.transitionTo(
|
2018-03-05 08:04:23 +08:00
|
|
|
"adminCustomizeThemes.edit",
|
|
|
|
wrapper.model.id,
|
|
|
|
wrapper.target,
|
|
|
|
fields[0]
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
controller.set("model", wrapper.model);
|
|
|
|
controller.setTargetName(wrapper.target || "common");
|
|
|
|
controller.set("fieldName", wrapper.field_name || "scss");
|
|
|
|
this.controllerFor("adminCustomizeThemes").set("editingTheme", true);
|
2018-09-07 02:56:00 +08:00
|
|
|
this.set("shouldAlertUnsavedChanges", true);
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2018-09-07 02:56:00 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
@action
|
|
|
|
willTransition(transition) {
|
|
|
|
if (
|
|
|
|
this.get("controller.model.changed") &&
|
|
|
|
this.shouldAlertUnsavedChanges &&
|
|
|
|
transition.intent.name !== this.routeName
|
|
|
|
) {
|
|
|
|
transition.abort();
|
2022-10-07 23:38:27 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
this.dialog.confirm({
|
2024-11-20 04:45:18 +08:00
|
|
|
message: i18n("admin.customize.theme.unsaved_changes_alert"),
|
2023-03-15 21:17:51 +08:00
|
|
|
confirmButtonLabel: "admin.customize.theme.discard",
|
|
|
|
cancelButtonLabel: "admin.customize.theme.stay",
|
|
|
|
didConfirm: () => {
|
|
|
|
this.set("shouldAlertUnsavedChanges", false);
|
|
|
|
transition.retry();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|