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";
|
2022-10-07 23:38:27 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
2020-08-27 00:57:13 +08:00
|
|
|
|
2019-10-24 00:39:32 +08:00
|
|
|
export default Route.extend({
|
2022-10-07 23:38:27 +08:00
|
|
|
dialog: service(),
|
|
|
|
|
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));
|
2017-04-13 23:09:31 +08:00
|
|
|
return model
|
|
|
|
? {
|
|
|
|
model,
|
|
|
|
target: params.target,
|
|
|
|
field_name: params.field_name,
|
|
|
|
}
|
|
|
|
: this.replaceWith("adminCustomizeThemes.index");
|
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"),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
2020-11-13 23:57:49 +08:00
|
|
|
this.transitionTo("adminCustomizeThemes.index");
|
|
|
|
return;
|
|
|
|
}
|
2018-03-05 08:04:23 +08:00
|
|
|
if (!fields.includes(wrapper.field_name)) {
|
|
|
|
this.transitionTo(
|
|
|
|
"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);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
willTransition(transition) {
|
|
|
|
if (
|
|
|
|
this.get("controller.model.changed") &&
|
2019-05-27 16:15:39 +08:00
|
|
|
this.shouldAlertUnsavedChanges &&
|
2018-09-07 02:56:00 +08:00
|
|
|
transition.intent.name !== this.routeName
|
|
|
|
) {
|
|
|
|
transition.abort();
|
2022-10-07 23:38:27 +08:00
|
|
|
|
|
|
|
this.dialog.confirm({
|
|
|
|
message: I18n.t("admin.customize.theme.unsaved_changes_alert"),
|
|
|
|
confirmButtonLabel: "admin.customize.theme.discard",
|
|
|
|
cancelButtonLabel: "admin.customize.theme.stay",
|
|
|
|
didConfirm: () => {
|
|
|
|
this.set("shouldAlertUnsavedChanges", false);
|
|
|
|
transition.retry();
|
|
|
|
},
|
|
|
|
});
|
2018-09-07 02:56:00 +08:00
|
|
|
}
|
|
|
|
},
|
2017-04-12 22:52:52 +08:00
|
|
|
},
|
|
|
|
});
|