1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

front-end modifications to cancel a booked event

This commit is contained in:
Sylvain 2016-11-09 17:07:48 +01:00
parent da71ba783c
commit 73e4439036
7 changed files with 66 additions and 13 deletions

View File

@ -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', 'settingsPromise', Application.Controllers.controller "ShowEventController", ["$scope", "$state", "$stateParams", "Event", '$uibModal', 'Member', 'Reservation', 'Price', 'CustomAsset', 'Slot', 'eventPromise', 'growl', '_t', 'Wallet', 'helpers', 'priceCategoriesPromise', 'settingsPromise', 'dialogs',
($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, Slot, eventPromise, growl, _t, Wallet, helpers, priceCategoriesPromise, settingsPromise, dialogs) ->
@ -169,9 +169,15 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
## Global config: is the user authorized to change his bookings slots? ## Global config: is the user authorized to change his bookings slots?
$scope.enableBookingMove = (settingsPromise.booking_move_enable == "true") $scope.enableBookingMove = (settingsPromise.booking_move_enable == "true")
## Global config: delay in hours before a booking while changing the booking slot is forbidden ## Global config: delay in hours from now while changing the booking slot is forbidden
$scope.moveBookingDelay = parseInt(settingsPromise.booking_move_delay) $scope.moveBookingDelay = parseInt(settingsPromise.booking_move_delay)
## Global config: is the user authorized to cancel his booking slots?
$scope.enableBookingCancel = (settingsPromise.booking_cancel_enable == "true")
## Global config: delay in hours from now when rectrictions occurs about cancelling reservations
$scope.cancelBookingDelay = parseInt(settingsPromise.booking_cancel_delay)
## ##
@ -236,7 +242,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
## ##reservationCanCan
# Callback to deal with the reservations of the user selected in the dropdown list instead of the current user's # Callback to deal with the reservations of the user selected in the dropdown list instead of the current user's
# reservations. (admins only) # reservations. (admins only)
## ##
@ -311,6 +317,29 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
##
#
# @param reservation {{id:number, reservable_id:number, nb_reserve_places:number}}
# @param e {Object} see https://docs.angularjs.org/guide/expression#-event-
##
$scope.cancelReservation = (reservation, e)->
e.preventDefault()
e.stopPropagation()
dialogs.confirm
resolve:
object: ->
title: _t('cancel_the_reservation')
msg: _t('do_you_really_want_to_cancel_this_reservation_this_apply_to_all_booked_tickets')
, -> # cancel confirmed
Slot.cancel {id: reservation.slots[0].id}, -> # successfully canceled
growl.success _t('reservation_was_successfully_cancelled')
index = $scope.reservations.indexOf(reservation)
$scope.event.nb_free_places = $scope.event.nb_free_places + reservation.total_booked_seats
$scope.reservations.splice(index, 1)
, (error)->
growl.warning(_t('cancellation_failed'))
## ##
# Callback to alter an already booked reservation date. A modal window will be opened to allow the user to choose # Callback to alter an already booked reservation date. A modal window will be opened to allow the user to choose
# a new date for his reservation (if any available) # a new date for his reservation (if any available)
@ -333,9 +362,9 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
$scope.reservation = angular.copy reservation $scope.reservation = angular.copy reservation
# set the reservable_id to the first available event # set the reservable_id to the first available event
for e in event.recurrence_events for evt in event.recurrence_events
if e.nb_free_places > reservation.total_booked_seats if evt.nb_free_places > reservation.total_booked_seats
$scope.reservation.reservable_id = e.id $scope.reservation.reservable_id = evt.id
break break
# Callback to validate the new reservation's date # Callback to validate the new reservation's date
@ -377,7 +406,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
## ##
# Checks if the provided reservation is able to be moved (date change) # Checks if the provided reservation is able to be moved (date change)
# @param reservation {{total_booked_seats:number}} # @param reservation {{slots:[], total_booked_seats:number}}
## ##
$scope.reservationCanModify = (reservation)-> $scope.reservationCanModify = (reservation)->
slotStart = moment(reservation.slots[0].start_at) slotStart = moment(reservation.slots[0].start_at)
@ -390,6 +419,17 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
##
# Checks if the provided reservation is able to be cancelled
# @param reservation {{slots:[]}}
##
$scope.reservationCanCancel = (reservation)->
slotStart = moment(reservation.slots[0].start_at)
now = moment()
return ($scope.enableBookingCancel and slotStart.diff(now, "hours") >= $scope.cancelBookingDelay)
## ##
# Compute the total amount for the current reservation according to the previously set parameters # Compute the total amount for the current reservation according to the previously set parameters
# and assign the result in $scope.reserve.amountTotal # and assign the result in $scope.reserve.amountTotal
@ -516,7 +556,7 @@ Application.Controllers.controller "ShowEventController", ["$scope", "$state", "
## ##
# Set the current reservation to the default values. This implies to reservation form to be hidden. # Set the current reservation to the default values. This implies the reservation form to be hidden.
## ##
resetEventReserve = -> resetEventReserve = ->
if $scope.event if $scope.event

View File

@ -522,7 +522,7 @@ angular.module('application.router', ['ui.router']).
PriceCategory.query().$promise PriceCategory.query().$promise
] ]
settingsPromise: ['Setting', (Setting)-> settingsPromise: ['Setting', (Setting)->
Setting.query(names: "['booking_move_enable', 'booking_move_delay']").$promise Setting.query(names: "['booking_move_enable', 'booking_move_delay', 'booking_cancel_enable', 'booking_cancel_delay']").$promise
] ]
translations: [ 'Translations', (Translations) -> translations: [ 'Translations', (Translations) ->
Translations.query(['app.public.events_show', 'app.shared.member_select', 'app.shared.stripe', Translations.query(['app.public.events_show', 'app.shared.member_select', 'app.shared.stripe',

View File

@ -159,6 +159,9 @@
<div class="clear" ng-if="event.recurrence_events.length > 0 && reservationCanModify(reservation)"> <div class="clear" ng-if="event.recurrence_events.length > 0 && reservationCanModify(reservation)">
<a class="pull-right m-t-xs text-u-l" href="#" ng-click="modifyReservation(reservation, $event)" translate>{{ 'change' }}</a> <a class="pull-right m-t-xs text-u-l" href="#" ng-click="modifyReservation(reservation, $event)" translate>{{ 'change' }}</a>
</div> </div>
<div class="clear" ng-if="reservationCanCancel(reservation)">
<a class="pull-right m-t-xs text-u-l" href="#" ng-click="cancelReservation(reservation, $event)" translate>{{ 'cancel' }}</a>
</div>
</div> </div>

View File

@ -327,7 +327,11 @@ class Reservation < ActiveRecord::Base
end end
def total_booked_seats def total_booked_seats
total = nb_reserve_places total = 0
unless slots.first.canceled_at
total = nb_reserve_places
end
if tickets.count > 0 if tickets.count > 0
total += tickets.map(&:booked).map(&:to_i).reduce(:+) total += tickets.map(&:booked).map(&:to_i).reduce(:+)
end end
@ -356,7 +360,7 @@ class Reservation < ActiveRecord::Base
def training_not_fully_reserved def training_not_fully_reserved
slot = self.slots.first slot = self.slots.first
errors.add(:training, "already fully reserved") if Availability.find(slot.availability_id).is_completed errors.add(:training, 'already fully reserved') if Availability.find(slot.availability_id).is_completed
end end
private private

View File

@ -119,7 +119,7 @@ en:
i_reserve: "I reserve" i_reserve: "I reserve"
i_shift: "I shift" i_shift: "I shift"
i_change: "I change" i_change: "I change"
do_you_really_want_to_cancel_this_reservation: "So you really want to cancel this reservation?" do_you_really_want_to_cancel_this_reservation: "Do you really want to cancel this reservation?"
reservation_was_cancelled_successfully: "Reservation was cancelled successfully." reservation_was_cancelled_successfully: "Reservation was cancelled successfully."
cancellation_failed: "Cancellation failed." cancellation_failed: "Cancellation failed."
a_problem_occured_during_the_payment_process_please_try_again_later: "A problem occurred during the payment process. Please try again later." a_problem_occured_during_the_payment_process_please_try_again_later: "A problem occurred during the payment process. Please try again later."

View File

@ -241,6 +241,9 @@ en:
book: "Book" book: "Book"
change_the_reservation: "Change the reservation" change_the_reservation: "Change the reservation"
you_can_shift_this_reservation_on_the_following_slots: "You can shift this reservation on the following slots:" you_can_shift_this_reservation_on_the_following_slots: "You can shift this reservation on the following slots:"
cancel_the_reservation: "Cancel the reservation"
do_you_really_want_to_cancel_this_reservation_this_apply_to_all_booked_tickets: "Do you really want to cancel this reservation? This apply to ALL booked tickets."
cancellation_failed: "Cancellation failed."
calendar: calendar:
calendar: "Calendar" calendar: "Calendar"

View File

@ -242,6 +242,9 @@ fr:
book: "Réserver" book: "Réserver"
change_the_reservation: "Modifier la réservation" change_the_reservation: "Modifier la réservation"
you_can_shift_this_reservation_on_the_following_slots: "Vous pouvez déplacer cette réservation sur les créneaux suivants :" you_can_shift_this_reservation_on_the_following_slots: "Vous pouvez déplacer cette réservation sur les créneaux suivants :"
cancel_the_reservation: "Annuler la réservation"
do_you_really_want_to_cancel_this_reservation_this_apply_to_all_booked_tickets: "Êtes vous sur de vouloir annuler cette réservation? Ceci s'applique à TOUTES les places réservées."
cancellation_failed: "L'annulation a échoué."
calendar: calendar:
calendar: "Calendrier" calendar: "Calendrier"