From bb6295c487037e09d28c79a6f3a8bdd9f3b5f8db Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 30 Jun 2016 09:51:06 +0200 Subject: [PATCH] prevent from removing the last category --- app/assets/javascripts/controllers/admin/events.coffee | 7 +++++-- config/locales/app.admin.en.yml | 1 + config/locales/app.admin.fr.yml | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/controllers/admin/events.coffee b/app/assets/javascripts/controllers/admin/events.coffee index 7864b7149..93e080fb6 100644 --- a/app/assets/javascripts/controllers/admin/events.coffee +++ b/app/assets/javascripts/controllers/admin/events.coffee @@ -129,8 +129,8 @@ class EventsController ## # Controller used in the events listing page (admin view) ## -Application.Controllers.controller "AdminEventsController", ["$scope", "$state", 'dialogs','Event', 'Category', 'EventTheme', 'AgeRange', 'eventsPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', '_t' -, ($scope, $state, dialogs, Event, Category, EventTheme, AgeRange, eventsPromise, categoriesPromise, themesPromise, ageRangesPromise, _t) -> +Application.Controllers.controller "AdminEventsController", ["$scope", "$state", 'dialogs', 'growl', 'Event', 'Category', 'EventTheme', 'AgeRange', 'eventsPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', '_t' +, ($scope, $state, dialogs, growl, Event, Category, EventTheme, AgeRange, eventsPromise, categoriesPromise, themesPromise, ageRangesPromise, _t) -> @@ -191,6 +191,9 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state", # @param index {number} element index in the $scope[model] array ## $scope.removeElement = (model, index) -> + if model == 'category' and getModel(model)[1].length == 1 + growl.error(_t('at_least_one_category_is_required_unable_to_delete_the_last_one')) + return false dialogs.confirm resolve: object: -> diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 5b8bd0e22..b514ade85 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -85,6 +85,7 @@ en: age_ranges: "Age ranges" add_a_range: "Add a range" do_you_really_want_to_delete_this_ELEMENT_used_NUMBER_times: "Do you really want to delete this {ELEMENT, select, category{category} theme{theme} age_range{age range} other{element}}? {NUMBER, plural, =0{It is not currently associated with any events} one{Currently, it is associated with only one event} other{Currently, it is associated with {NUMBER} events}}." # messageFormat interpolation + at_least_one_category_is_required_unable_to_delete_the_last_one: "At least one category is required. Unable to delete the last one." events_new: # add a new event diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 8becfa7bf..974ac48f2 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -85,6 +85,7 @@ fr: age_ranges: "Tranches d'âge" add_a_range: "Ajouter une tranche" do_you_really_want_to_delete_this_ELEMENT_used_NUMBER_times: "Voulez-vous vraiment supprimer cette {ELEMENT, select, category{catégorie} theme{thématique} age_range{tranche d'âge} other{élément}} ? {NUMBER, plural, =0{Elle n'est actuellement associée à aucun évènement} one{Elle est actuellement associée à un seul évènement} other{Elle est actuellement associée à {NUMBER} évènements}}." # messageFormat interpolation + at_least_one_category_is_required_unable_to_delete_the_last_one: "Au moins une catégorie est requise. Impossible de supprimer la dernière." events_new: # ajouter un nouveau atelier/stage