From 64bae54bce18cd1a3c4ffb409a3b35de0ec96f1a Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 15 Sep 2016 18:43:27 +0200 Subject: [PATCH] [Bug] move event reservation is not limited by admin settings (prior-delay & disable) --- CHANGELOG.md | 1 + .../javascripts/controllers/events.coffee.erb | 15 ++++++++++++--- app/assets/javascripts/router.coffee.erb | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c284f6de..7d5f74e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ - Fix a bug: avatar, address and organization details mapping from SSO were broken - Fix a bug: in SSO configuration some valid endpoints were recognized as erroneous - Fix a bug: clicking on the text in stripe's payment modal, does not validate the checkbox +- Fix a bug: move event reservation is not limited by admin settings (prior-delay & disable) - [TODO DEPLOY] `rake fablab:es_build_availabilities_index` - [TODO DEPLOY] `rake fablab:es_add_event_filters` - [TODO DEPLOY] `rake db:migrate` diff --git a/app/assets/javascripts/controllers/events.coffee.erb b/app/assets/javascripts/controllers/events.coffee.erb index 4279e7ed4..d8a177c46 100644 --- a/app/assets/javascripts/controllers/events.coffee.erb +++ b/app/assets/javascripts/controllers/events.coffee.erb @@ -132,8 +132,8 @@ Application.Controllers.controller "EventsController", ["$scope", "$state", 'Eve -Application.Controllers.controller "ShowEventController", ["$scope", "$state", "$stateParams", "Event", '$uibModal', 'Member', 'Reservation', 'Price', 'CustomAsset', 'eventPromise', 'growl', '_t', 'Wallet', 'helpers', 'priceCategoriesPromise', -($scope, $state, $stateParams, Event, $uibModal, Member, Reservation, Price, CustomAsset, eventPromise, growl, _t, Wallet, helpers, priceCategoriesPromise) -> +Application.Controllers.controller "ShowEventController", ["$scope", "$state", "$stateParams", "Event", '$uibModal', 'Member', 'Reservation', 'Price', 'CustomAsset', 'eventPromise', 'growl', '_t', 'Wallet', 'helpers', 'priceCategoriesPromise', 'settingsPromise', +($scope, $state, $stateParams, Event, $uibModal, Member, Reservation, Price, CustomAsset, eventPromise, growl, _t, Wallet, helpers, priceCategoriesPromise, settingsPromise) -> @@ -166,6 +166,12 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", " ## List of price categories for the events $scope.priceCategories = priceCategoriesPromise + ## Global config: is the user authorized to change his bookings slots? + $scope.enableBookingMove = (settingsPromise.booking_move_enable == "true") + + ## Global config: delay in hours before a booking while changing the booking slot is forbidden + $scope.moveBookingDelay = parseInt(settingsPromise.booking_move_delay) + ## @@ -374,10 +380,13 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", " # @param reservation {{total_booked_seats:number}} ## $scope.reservationCanModify = (reservation)-> + slotStart = moment(reservation.slots[0].start_at) + now = moment() + isAble = false angular.forEach $scope.event.recurrence_events, (e)-> isAble = true if e.nb_free_places >= reservation.total_booked_seats - isAble + return (isAble and $scope.enableBookingMove and slotStart.diff(now, "hours") >= $scope.moveBookingDelay) diff --git a/app/assets/javascripts/router.coffee.erb b/app/assets/javascripts/router.coffee.erb index 2ce8f411c..8d5984205 100644 --- a/app/assets/javascripts/router.coffee.erb +++ b/app/assets/javascripts/router.coffee.erb @@ -515,6 +515,9 @@ angular.module('application.router', ['ui.router']). priceCategoriesPromise: ['PriceCategory', (PriceCategory) -> PriceCategory.query().$promise ] + settingsPromise: ['Setting', (Setting)-> + Setting.query(names: "['booking_move_enable', 'booking_move_delay']").$promise + ] translations: [ 'Translations', (Translations) -> Translations.query(['app.public.events_show', 'app.shared.member_select', 'app.shared.stripe', 'app.shared.valid_reservation_modal', 'app.shared.wallet', 'app.shared.coupon_input']).$promise