2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2019-10-23 12:39:32 -04:00
|
|
|
import Route from "@ember/routing/route";
|
2020-08-26 12:57:13 -04:00
|
|
|
import bootbox from "bootbox";
|
|
|
|
|
2019-10-23 12:39:32 -04:00
|
|
|
export default Route.extend({
|
2017-04-12 10:52:52 -04:00
|
|
|
model(params) {
|
|
|
|
const all = this.modelFor("adminCustomizeThemes");
|
2019-11-12 04:47:42 -05:00
|
|
|
const model = all.findBy("id", parseInt(params.theme_id, 10));
|
2017-04-13 11:09:31 -04:00
|
|
|
return model
|
|
|
|
? {
|
|
|
|
model,
|
|
|
|
target: params.target,
|
|
|
|
field_name: params.field_name,
|
|
|
|
}
|
|
|
|
: this.replaceWith("adminCustomizeThemes.index");
|
2017-04-12 10:52:52 -04: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 07:56:01 -05:00
|
|
|
const fields = wrapper.model
|
|
|
|
.get("fields")
|
|
|
|
[wrapper.target].map((f) => f.name);
|
2018-03-04 19:04:23 -05:00
|
|
|
if (!fields.includes(wrapper.field_name)) {
|
|
|
|
this.transitionTo(
|
|
|
|
"adminCustomizeThemes.edit",
|
|
|
|
wrapper.model.id,
|
|
|
|
wrapper.target,
|
|
|
|
fields[0]
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2017-04-12 10:52:52 -04: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-06 14:56:00 -04:00
|
|
|
this.set("shouldAlertUnsavedChanges", true);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
willTransition(transition) {
|
|
|
|
if (
|
|
|
|
this.get("controller.model.changed") &&
|
2019-05-27 04:15:39 -04:00
|
|
|
this.shouldAlertUnsavedChanges &&
|
2018-09-06 14:56:00 -04: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 10:52:52 -04:00
|
|
|
},
|
|
|
|
});
|