2019-10-23 12:39:32 -04:00
|
|
|
import Route from "@ember/routing/route";
|
2018-08-23 21:30:00 -04:00
|
|
|
import { scrollTop } from "discourse/mixins/scroll-top";
|
2018-08-30 15:23:15 -04:00
|
|
|
import { THEMES, COMPONENTS } from "admin/models/theme";
|
2018-08-23 21:30:00 -04:00
|
|
|
|
2019-10-23 12:39:32 -04:00
|
|
|
export default Route.extend({
|
2017-04-12 10:52:52 -04:00
|
|
|
serialize(model) {
|
2018-06-15 11:03:24 -04:00
|
|
|
return { theme_id: model.get("id") };
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
model(params) {
|
2018-06-15 11:03:24 -04:00
|
|
|
const all = this.modelFor("adminCustomizeThemes");
|
2019-11-12 04:47:42 -05:00
|
|
|
const model = all.findBy("id", parseInt(params.theme_id, 10));
|
2018-06-15 11:03:24 -04:00
|
|
|
return model ? model : this.replaceWith("adminCustomizeTheme.index");
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
2018-08-23 21:30:00 -04:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
const parentController = this.controllerFor("adminCustomizeThemes");
|
2019-04-11 00:55:32 -04:00
|
|
|
|
2018-08-30 15:23:15 -04: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 00:55:32 -04:00
|
|
|
colorSchemes: parentController.get("model.extras.color_schemes"),
|
|
|
|
editingName: false
|
2018-08-30 15:23:15 -04:00
|
|
|
});
|
2018-08-23 21:30:00 -04:00
|
|
|
|
|
|
|
this.handleHighlight(model);
|
|
|
|
},
|
|
|
|
|
|
|
|
deactivate() {
|
|
|
|
this.handleHighlight();
|
|
|
|
},
|
|
|
|
|
|
|
|
handleHighlight(theme) {
|
2018-09-06 14:56:00 -04:00
|
|
|
this.get("controller.allThemes")
|
|
|
|
.filter(t => t.get("selected"))
|
|
|
|
.forEach(t => t.set("selected", false));
|
2018-08-23 21:30:00 -04:00
|
|
|
if (theme) {
|
2018-09-06 14:56:00 -04:00
|
|
|
theme.set("selected", true);
|
2018-08-23 21:30:00 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
didTransition() {
|
|
|
|
scrollTop();
|
2019-12-09 16:43:26 -05: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-23 21:30:00 -04:00
|
|
|
}
|
2017-04-12 10:52:52 -04:00
|
|
|
}
|
|
|
|
});
|