diff --git a/app/assets/javascripts/controllers/admin/events.js.erb b/app/assets/javascripts/controllers/admin/events.js.erb index 303c9c589..1dccf10df 100644 --- a/app/assets/javascripts/controllers/admin/events.js.erb +++ b/app/assets/javascripts/controllers/admin/events.js.erb @@ -498,8 +498,8 @@ Application.Controllers.controller('NewEventController', ['$scope', '$state', 'C /** * Controller used in the events edition page */ -Application.Controllers.controller('EditEventController', ['$scope', '$state', '$stateParams', 'CSRF', 'eventPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', 'priceCategoriesPromise', - function ($scope, $state, $stateParams, CSRF, eventPromise, categoriesPromise, themesPromise, ageRangesPromise, priceCategoriesPromise) { +Application.Controllers.controller('EditEventController', ['$scope', '$state', '$stateParams', 'CSRF', 'eventPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', 'priceCategoriesPromise', '$uibModal', + function ($scope, $state, $stateParams, CSRF, eventPromise, categoriesPromise, themesPromise, ageRangesPromise, priceCategoriesPromise, $uibModal) { /* PUBLIC SCOPE */ // API URL where the form will be posted @@ -523,6 +523,35 @@ Application.Controllers.controller('EditEventController', ['$scope', '$state', ' // List of age ranges $scope.ageRanges = ageRangesPromise; + // Default edit mode for periodic event + $scope.editMode = 'single'; + + // show edit mode modal if event is recurrence + $scope.isShowEditModeModal = $scope.event.recurrence_events.length > 0; + + $scope.editRecurrent = async function (e) { + if ($scope.isShowEditModeModal && $scope.event.recurrence_events.length > 0) { + e.preventDefault(); + + // open a choice edit mode dialog + const modalInstance = $uibModal.open({ + animation: true, + templateUrl: '<%= asset_path "events/editRecurrent.html" %>', + size: 'md', + controller: 'EditRecurrentEventController', + resolve: { + editMode: function () { return $scope.editMode; } + } + }); + // submit form event by edit mode + modalInstance.result.then(function(res) { + $scope.isShowEditModeModal = false; + $scope.editMode = res.editMode; + e.target.click(); + }); + } + }; + /* PRIVATE SCOPE */ /** @@ -543,3 +572,29 @@ Application.Controllers.controller('EditEventController', ['$scope', '$state', ' return initialize(); } ]); + +/** + * Controller used in the event edit mode modal window + */ +Application.Controllers.controller('EditRecurrentEventController', ['$scope', '$uibModalInstance', 'editMode', 'growl', '_t', + function ($scope, $uibModalInstance, editMode, growl, _t) { + // with recurrent slots: how many slots should we update? + $scope.editMode = editMode; + + /** + * Confirmation callback + */ + $scope.ok = function () { + $uibModalInstance.close({ + editMode: $scope.editMode, + }); + } + + /** + * Cancellation callback + */ + $scope.cancel = function () { + $uibModalInstance.dismiss('cancel'); + } + } +]); diff --git a/app/assets/templates/events/_form.html.erb b/app/assets/templates/events/_form.html.erb index 5eb02941d..049163ed7 100644 --- a/app/assets/templates/events/_form.html.erb +++ b/app/assets/templates/events/_form.html.erb @@ -77,11 +77,13 @@ + diff --git a/app/assets/templates/events/edit.html.erb b/app/assets/templates/events/edit.html.erb index 8790c8ea7..9e902c0fc 100644 --- a/app/assets/templates/events/edit.html.erb +++ b/app/assets/templates/events/edit.html.erb @@ -16,7 +16,7 @@ -
+ '"> diff --git a/app/assets/templates/events/editRecurrent.html b/app/assets/templates/events/editRecurrent.html new file mode 100644 index 000000000..cbf0b0117 --- /dev/null +++ b/app/assets/templates/events/editRecurrent.html @@ -0,0 +1,25 @@ + + + diff --git a/app/controllers/api/events_controller.rb b/app/controllers/api/events_controller.rb index 0e6a7fc08..e485f4ed3 100644 --- a/app/controllers/api/events_controller.rb +++ b/app/controllers/api/events_controller.rb @@ -56,10 +56,11 @@ class API::EventsController < API::ApiController def update authorize Event begin - if @event.update(event_params.permit!) + res = EventService.update(@event, event_params.permit!, params[:edit_mode]) + if res.all? { |r| r[:status] } render :show, status: :ok, location: @event else - render json: @event.errors, status: :unprocessable_entity + render json: { total: res.length, updated: res.select { |r| r[:status] }.length, details: res }, status: :unprocessable_entity end rescue ActiveRecord::RecordNotDestroyed => e if e.record.class.name == 'EventPriceCategory' diff --git a/app/services/event_service.rb b/app/services/event_service.rb index 196acaeb6..1f45a88e4 100644 --- a/app/services/event_service.rb +++ b/app/services/event_service.rb @@ -72,4 +72,39 @@ class EventService end results end + + # update one or more events (if periodic) + def self.update(event, event_params, mode = 'single') + results = [] + events = case mode + when 'single' + [event] + when 'next' + Event.includes(:availability) + .where( + 'availabilities.start_at >= ? AND events.recurrence_id = ?', + event.availability.start_at, + event.recurrence_id + ) + .references(:availabilities, :events) + when 'all' + Event.where( + 'recurrence_id = ?', + event.recurrence_id + ) + else + [] + end + + events.each do |e| + if e.id == event.id + results.push status: !!e.update(event_params), event: e # rubocop:disable Style/DoubleNegation + else + puts '------------' + puts e.id + puts event_params + end + end + results + end end diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index 7293ebb5b..ea2c67a3e 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -217,6 +217,11 @@ en: 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." + confirmation_required: "Confirmation required" + edit_recurring_event: "What do you want to update this periodic event ?" + edit_this_event: "Only this event" + edit_this_and_next: "This event and the following" + edit_all: "All events" events_new: # add a new event diff --git a/config/locales/app.admin.es.yml b/config/locales/app.admin.es.yml index d8d60a425..2a9df765c 100644 --- a/config/locales/app.admin.es.yml +++ b/config/locales/app.admin.es.yml @@ -217,6 +217,11 @@ es: do_you_really_want_to_delete_this_price_category: "¿Desea realmente eliminar esta categoría de precios?" price_category_successfully_deleted: "Categoría de precio eliminada correctamente." price_category_deletion_failed: "Error al eliminar la categoría de precio." + confirmation_required: "Confirmation required" + edit_recurring_event: "What do you want to update this periodic event ?" + edit_this_event: "Only this event" + edit_this_and_next: "This event and the following" + edit_all: "All events" events_new: # add a new event diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 10629b518..15aa9da26 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -217,6 +217,11 @@ fr: 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." + confirmation_required: "Confirmation requise" + edit_recurring_event: "Que voulez-vous modifier cet évènement périodique ?" + edit_this_event: "Uniquement cet évènement" + edit_this_and_next: "Cet évènement et tous les suivants" + edit_all: "Tous les évènements" events_new: # ajouter un nouvel évènement diff --git a/config/locales/app.admin.pt.yml b/config/locales/app.admin.pt.yml index 963fef504..80db6dac9 100755 --- a/config/locales/app.admin.pt.yml +++ b/config/locales/app.admin.pt.yml @@ -217,6 +217,11 @@ pt: do_you_really_want_to_delete_this_price_category: "Você realmente quer deletar este preço de categoria?" price_category_successfully_deleted: "Preço de categoria deletado com sucesso." price_category_deletion_failed: "Falha ao deletar preço de categoria." + confirmation_required: "Confirmation required" + edit_recurring_event: "What do you want to update this periodic event ?" + edit_this_event: "Only this event" + edit_this_and_next: "This event and the following" + edit_all: "All events" events_new: # add a new event