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";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
|
|
|
|
2019-10-24 00:39:32 +08:00
|
|
|
export default Route.extend({
|
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);
|
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();
|
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("admin.customize.theme.unsaved_changes_alert"),
|
|
|
|
I18n.t("admin.customize.theme.discard"),
|
|
|
|
I18n.t("admin.customize.theme.stay"),
|
|
|
|
(result) => {
|
|
|
|
if (!result) {
|
|
|
|
this.set("shouldAlertUnsavedChanges", false);
|
|
|
|
transition.retry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2017-04-12 22:52:52 +08:00
|
|
|
},
|
|
|
|
});
|