2019-10-24 00:39:32 +08:00
|
|
|
import Route from "@ember/routing/route";
|
2018-08-24 09:30:00 +08:00
|
|
|
import { scrollTop } from "discourse/mixins/scroll-top";
|
2018-08-31 03:23:15 +08:00
|
|
|
import { THEMES, COMPONENTS } from "admin/models/theme";
|
2018-08-24 09:30:00 +08:00
|
|
|
|
2019-10-24 00:39:32 +08:00
|
|
|
export default Route.extend({
|
2017-04-12 22:52:52 +08:00
|
|
|
serialize(model) {
|
|
|
|
return { theme_id: model.get("id") };
|
|
|
|
},
|
|
|
|
|
|
|
|
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-12 22:52:52 +08:00
|
|
|
return model ? model : this.replaceWith("adminCustomizeTheme.index");
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
2018-08-24 09:30:00 +08:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2017-04-12 22:52:52 +08:00
|
|
|
const parentController = this.controllerFor("adminCustomizeThemes");
|
2019-04-11 12:55:32 +08:00
|
|
|
|
2018-08-31 03:23:15 +08:00
|
|
|
parentController.setProperties({
|
|
|
|
editingTheme: false,
|
|
|
|
currentTab: model.get("component") ? COMPONENTS : THEMES
|
|
|
|
});
|
|
|
|
|
|
|
|
controller.setProperties({
|
|
|
|
model: model,
|
|
|
|
parentController: parentController,
|
|
|
|
allThemes: parentController.get("model"),
|
|
|
|
colorSchemeId: model.get("color_scheme_id"),
|
2019-04-11 12:55:32 +08:00
|
|
|
colorSchemes: parentController.get("model.extras.color_schemes"),
|
|
|
|
editingName: false
|
2018-08-31 03:23:15 +08:00
|
|
|
});
|
2018-08-24 09:30:00 +08:00
|
|
|
|
|
|
|
this.handleHighlight(model);
|
|
|
|
},
|
|
|
|
|
|
|
|
deactivate() {
|
|
|
|
this.handleHighlight();
|
|
|
|
},
|
|
|
|
|
|
|
|
handleHighlight(theme) {
|
2018-09-07 02:56:00 +08:00
|
|
|
this.get("controller.allThemes")
|
|
|
|
.filter(t => t.get("selected"))
|
|
|
|
.forEach(t => t.set("selected", false));
|
2018-08-24 09:30:00 +08:00
|
|
|
if (theme) {
|
2018-09-07 02:56:00 +08:00
|
|
|
theme.set("selected", true);
|
2018-08-24 09:30:00 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
didTransition() {
|
|
|
|
scrollTop();
|
2019-12-10 05:43:26 +08:00
|
|
|
},
|
|
|
|
willTransition(transition) {
|
|
|
|
const model = this.controller.model;
|
|
|
|
if (model.recentlyInstalled && !model.hasParents && model.component) {
|
|
|
|
transition.abort();
|
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("admin.customize.theme.unsaved_parent_themes"),
|
|
|
|
I18n.t("admin.customize.theme.discard"),
|
|
|
|
I18n.t("admin.customize.theme.stay"),
|
|
|
|
result => {
|
|
|
|
if (!result) {
|
|
|
|
this.controller.model.setProperties({ recentlyInstalled: false });
|
|
|
|
transition.retry();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2018-08-24 09:30:00 +08:00
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
}
|
|
|
|
});
|