From 5e29ae3ef5f7ad33906d00314cbdfb3a2813c529 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 10 Dec 2019 08:43:26 +1100 Subject: [PATCH] FEATURE: Warning when component is added and not assigned (#8482) When a component is installed and not assigned to any theme and the user is changing page, we should display a warning. If the user decides to skip warning or come back later, a warning should not be shown anymore. Also, when the user clicks "delete" button right after installation, warning about forgotten themes should not be shown. --- .../admin-customize-themes-show.js.es6 | 1 + .../routes/admin-customize-themes-show.js.es6 | 17 +++++++++++++++++ .../admin/routes/admin-customize-themes.js.es6 | 1 + config/locales/client.en.yml | 1 + 4 files changed, 20 insertions(+) diff --git a/app/assets/javascripts/admin/controllers/admin-customize-themes-show.js.es6 b/app/assets/javascripts/admin/controllers/admin-customize-themes-show.js.es6 index b9712761e5b..cebdb192350 100644 --- a/app/assets/javascripts/admin/controllers/admin-customize-themes-show.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-customize-themes-show.js.es6 @@ -324,6 +324,7 @@ export default Controller.extend({ result => { if (result) { const model = this.model; + model.setProperties({ recentlyInstalled: false }); model.destroyRecord().then(() => { this.allThemes.removeObject(model); this.transitionToRoute("adminCustomizeThemes"); diff --git a/app/assets/javascripts/admin/routes/admin-customize-themes-show.js.es6 b/app/assets/javascripts/admin/routes/admin-customize-themes-show.js.es6 index 408917b57a7..5b9ce251697 100644 --- a/app/assets/javascripts/admin/routes/admin-customize-themes-show.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-customize-themes-show.js.es6 @@ -51,6 +51,23 @@ export default Route.extend({ actions: { didTransition() { scrollTop(); + }, + 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(); + } + } + ); + } } } }); diff --git a/app/assets/javascripts/admin/routes/admin-customize-themes.js.es6 b/app/assets/javascripts/admin/routes/admin-customize-themes.js.es6 index 7f7274ee0e2..7413057253c 100644 --- a/app/assets/javascripts/admin/routes/admin-customize-themes.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-customize-themes.js.es6 @@ -18,6 +18,7 @@ export default Route.extend({ addTheme(theme) { this.refresh(); + theme.setProperties({ recentlyInstalled: true }); this.transitionTo("adminCustomizeThemes.show", theme.get("id")); } } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 148d47de8ee..1db21152703 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3648,6 +3648,7 @@ en: upload: "Upload" select_component: "Select a component..." unsaved_changes_alert: "You haven't saved your changes yet, do you want to discard them and move on?" + unsaved_parent_themes: "You haven't assigned the component to themes, do you want to move on?" discard: "Discard" stay: "Stay" css_html: "Custom CSS/HTML"