discourse/app/assets/javascripts/admin/addon/routes/admin-config-with-settings-route.js
Ted Johansson 7e77b24202
DEV: Preserve unsaved site settings (#32100)
This builds onto #32013 in two major ways:

- Unsaved changes are now persisted when you browse categories inside "All site settings".
- If you're about to navigate away (and lose edits) you will be prompted if you want to save or discard changes. (This applies to individual category site setting pages as well.
2025-04-03 16:10:30 +08:00

30 lines
885 B
JavaScript
Vendored

import { action } from "@ember/object";
import { service } from "@ember/service";
import DiscourseRoute from "discourse/routes/discourse";
export default class AdminConfigWithSettingsRoute extends DiscourseRoute {
@service siteSettingChangeTracker;
resetController(controller, isExiting) {
// Have to do this because this is the parent route. We don't want to have
// to make a controller for every single settings route when we can reset
// the filter here.
const settingsController = this.controllerFor(
`${this.fullRouteName}.settings`
);
if (isExiting) {
settingsController.set("filter", "");
}
}
@action
async willTransition(transition) {
if (this.siteSettingChangeTracker.hasUnsavedChanges) {
transition.abort();
await this.siteSettingChangeTracker.confirmTransition();
transition.retry();
}
}
}