diff --git a/app/assets/javascripts/controllers/admin/events.coffee.erb b/app/assets/javascripts/controllers/admin/events.coffee.erb index c2354d28d..949cafc37 100644 --- a/app/assets/javascripts/controllers/admin/events.coffee.erb +++ b/app/assets/javascripts/controllers/admin/events.coffee.erb @@ -288,6 +288,31 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state", + ## + # Delete the given price category from the API + # @param index {number} index of the caterory in the $scope.priceCategories array + # @param id {number} price category ID, must match the ID of the category at the index specified above + ## + $scope.removePriceCategory = (id, index) -> + if $scope.priceCategories[index].id != id + growl.error(_t('unexpected_error_occurred_please_refresh')) + else if $scope.priceCategories[index].events > 0 + growl.error(_t('unable_to_delete_this_price_category_because_it_is_already_used')) + else + dialogs.confirm + resolve: + object: -> + title: _t('confirmation_required') + msg: _t('do_you_really_want_to_delete_this_price_category') + , -> # delete confirmed + PriceCategory.remove {id: id}, -> # successfully deleted + growl.success _t('price_category_successfully_deleted') + $scope.priceCategories.splice(index, 1) + , -> + growl.error _t('price_category_deletion_failed') + + + ### PRIVATE SCOPE ### ## diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index a50b21a88..bb6e96e2c 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -104,6 +104,10 @@ en: unexpected_error_occurred_please_refresh: "An unexpected error occurred, please refresh the page." price_category_successfully_updated: "Price category successfully updated." unable_to_update_the_price_category: "Unable to update the price category." + unable_to_delete_this_price_category_because_it_is_already_used: "Unable to delete this price category because it is already used." + do_you_really_want_to_delete_this_price_category: "Do you really want to delete this price category?" + price_category_successfully_deleted: "Price category successfully deleted." + price_category_deletion_failed: "Price category deletion failed." events_new: # add a new event diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index fd480fa0e..7a30b2d84 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -104,6 +104,10 @@ fr: unexpected_error_occurred_please_refresh: "Une erreur inattendue est survenue, merci de rafraîchir la page." price_category_successfully_updated: "La catégorie tarifaire a bien été mise à jour." unable_to_update_the_price_category: "Impossible de mettre à jour la catégorie tarifaire." + unable_to_delete_this_price_category_because_it_is_already_used: "Impossible de supprimer cette catégorie tarifaire car elle déjà utilisée." + do_you_really_want_to_delete_this_price_category: "Êtes vous sur de vouloir supprimer cette catégorie tarifaire ?" + price_category_successfully_deleted: "Catégorie tarifaire supprimée avec succès." + price_category_deletion_failed: "Échec de la suppression de la catégorie tarifaire." events_new: # ajouter un nouvel évènement