2019-10-24 00:39:32 +08:00
|
|
|
import Route from "@ember/routing/route";
|
|
|
|
export default Route.extend({
|
2017-04-12 22:52:52 +08:00
|
|
|
model(params) {
|
2018-06-15 23:03:24 +08:00
|
|
|
const all = this.modelFor("adminCustomizeThemes");
|
|
|
|
const model = all.findBy("id", parseInt(params.theme_id));
|
|
|
|
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)) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.transitionTo(
|
|
|
|
"adminCustomizeThemes.edit",
|
|
|
|
wrapper.model.id,
|
|
|
|
wrapper.target,
|
|
|
|
fields[0]
|
|
|
|
);
|
2018-03-05 08:04:23 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-06-15 23:03:24 +08:00
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
});
|