2018-08-30 15:23:15 -04:00
|
|
|
import { COMPONENTS, THEMES } from "admin/models/theme";
|
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";
|
2018-08-23 21:30:00 -04:00
|
|
|
import { scrollTop } from "discourse/mixins/scroll-top";
|
2021-11-13 07:10:13 -05:00
|
|
|
import bootbox from "bootbox";
|
2018-08-23 21:30:00 -04:00
|
|
|
|
2021-01-11 10:29:12 -05:00
|
|
|
export function showUnassignedComponentWarning(theme, callback) {
|
|
|
|
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) {
|
|
|
|
theme.set("recentlyInstalled", false);
|
|
|
|
}
|
|
|
|
callback(result);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-23 12:39:32 -04:00
|
|
|
export default Route.extend({
|
2017-04-12 10:52:52 -04:00
|
|
|
serialize(model) {
|
|
|
|
return { theme_id: model.get("id") };
|
|
|
|
},
|
|
|
|
|
|
|
|
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));
|
2021-01-11 10:29:12 -05:00
|
|
|
return model ? model : this.replaceWith("adminCustomizeThemes.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({
|
2021-11-09 18:31:41 -05:00
|
|
|
model,
|
|
|
|
parentController,
|
2018-08-30 15:23:15 -04:00
|
|
|
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;
|
2021-01-11 10:29:12 -05:00
|
|
|
if (model.warnUnassignedComponent) {
|
2019-12-09 16:43:26 -05:00
|
|
|
transition.abort();
|
2021-01-11 10:29:12 -05:00
|
|
|
showUnassignedComponentWarning(model, (result) => {
|
|
|
|
if (!result) {
|
|
|
|
transition.retry();
|
2019-12-09 16:43:26 -05:00
|
|
|
}
|
2021-01-11 10:29:12 -05:00
|
|
|
});
|
2019-12-09 16:43:26 -05:00
|
|
|
}
|
2018-08-23 21:30:00 -04:00
|
|
|
},
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
});
|