From c4824f99ba365c638281e4c631125744dfecdd9d Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 22 Feb 2017 10:28:14 +0100 Subject: [PATCH] fix summary after event moved --- .../controllers/machines.coffee.erb | 6 +----- .../javascripts/directives/cart.coffee.erb | 21 +++++++++++++++++-- .../templates/machines/reserve.html.erb | 11 ---------- app/assets/templates/shared/_cart.html.erb | 18 ++++++++-------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/controllers/machines.coffee.erb b/app/assets/javascripts/controllers/machines.coffee.erb index c8579ac29..e4d760a0e 100644 --- a/app/assets/javascripts/controllers/machines.coffee.erb +++ b/app/assets/javascripts/controllers/machines.coffee.erb @@ -311,6 +311,7 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat modifiable: null placable: null paid: [] + moved: null ## total amount of the bill to pay $scope.amountTotal = 0 @@ -427,16 +428,12 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat # When modifying an already booked reservation, callback when the modification was successfully done. ## $scope.modifyMachineSlot = -> - $scope.modifiedSlots = - newReservedSlot: $scope.events.placable - oldReservedSlot: $scope.events.modifiable $scope.events.placable.title = if $scope.currentUser.role isnt 'admin' then _t('i_ve_reserved') else _t('not_available') $scope.events.placable.backgroundColor = 'white' $scope.events.placable.borderColor = $scope.events.modifiable.borderColor $scope.events.placable.id = $scope.events.modifiable.id $scope.events.placable.is_reserved = true $scope.events.placable.can_modify = true - $scope.events.placable = null $scope.events.modifiable.backgroundColor = 'white' $scope.events.modifiable.title = '' @@ -444,7 +441,6 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat $scope.events.modifiable.id = null $scope.events.modifiable.is_reserved = false $scope.events.modifiable.can_modify = false - $scope.events.modifiable = null updateCalendar() diff --git a/app/assets/javascripts/directives/cart.coffee.erb b/app/assets/javascripts/directives/cart.coffee.erb index b58958658..5ffdf2c78 100644 --- a/app/assets/javascripts/directives/cart.coffee.erb +++ b/app/assets/javascripts/directives/cart.coffee.erb @@ -99,7 +99,13 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs', # Switch the user's view from the reservation agenda to the plan subscription ## $scope.showPlans = -> - $scope.modePlans = true + # first, we ensure that a user was selected (admin) or logged (member) + if Object.keys($scope.user).length > 0 + $scope.modePlans = true + else + # otherwise we alert, this error musn't occur when the current user hasn't the admin role + growl.error(_t('cart.please_select_a_member_first')) + ## # Validates the shopping chart and redirect the user to the payment step @@ -131,7 +137,15 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs', end_at: $scope.events.placable.end availability_id: $scope.events.placable.availability_id , -> # success + # -> run the callback $scope.onSlotModifySuccess() if typeof $scope.onSlotModifySuccess == 'function' + # -> set the events as successfully moved (to display a summary) + $scope.events.moved = + newSlot: $scope.events.placable + oldSlot: $scope.events.modifiable + # -> reset the 'moving' status + $scope.events.placable = null + $scope.events.modifiable = null , (err) -> # failure growl.error(_t('cart.unable_to_change_the_reservation')) console.error(err) @@ -140,8 +154,10 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs', ## # Cancel the current booking modification, reseting the whole process + # @param event {Object} see https://docs.angularjs.org/guide/expression#-event- ## - $scope.cancelModifySlot = -> + $scope.cancelModifySlot = (event) -> + event.preventDefault() if event $scope.onSlotModifyCancel() if typeof $scope.onSlotModifyCancel == 'function' $scope.events.placable = null $scope.events.modifiable = null @@ -222,6 +238,7 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs', # in every cases, because a new reservation has started # we reset the array of settled events, the selected plan and the coupon $scope.events.paid = [] + $scope.events.moved = null $scope.selectedPlan = null $scope.coupon.applied = null # finally, we update the prices diff --git a/app/assets/templates/machines/reserve.html.erb b/app/assets/templates/machines/reserve.html.erb index 262201554..540332855 100644 --- a/app/assets/templates/machines/reserve.html.erb +++ b/app/assets/templates/machines/reserve.html.erb @@ -29,17 +29,6 @@ -
-
-

{{ 'summary' }}

-
-
-

<%= image_tag("fleche-left.png", class: 'fleche-left visible-lg') %> - {{ 'select_one_or_more_slots_in_the_calendar' | translate }}

-
-
- - +

{{ 'cart.summary' }}

-

<%= image_tag("fleche-left.png", class: 'fleche-left visible-lg') %> +

<%= image_tag('fleche-left.png', class: 'fleche-left visible-lg') %> {{ 'cart.select_one_or_more_slots_in_the_calendar' | translate }}

@@ -38,7 +38,7 @@ - +

{{ 'cart.to_benefit_from_attractive_prices' }}

@@ -54,7 +54,7 @@
- + @@ -88,7 +88,7 @@ -
+

{{ 'cart.summary' }}

@@ -103,7 +103,7 @@
-

<%= image_tag("fleche-left.png", class: 'fleche-left visible-lg') %> +

<%= image_tag('fleche-left.png', class: 'fleche-left visible-lg') %> {{ 'cart.select_a_new_slot_in_the_calendar' | translate }}

@@ -140,12 +140,12 @@
-
+
{{ 'cart.your_booking_slot_was_successfully_moved_from_' }}
-
{{ 'cart.datetime_to_time' | translate:{START_DATETIME:(modifiedSlots.oldReservedSlot.start | amDateFormat:'LLLL'), END_TIME:(modifiedSlots.oldReservedSlot.end | amDateFormat:'LT') } }}
+
{{ 'cart.datetime_to_time' | translate:{START_DATETIME:(events.moved.oldSlot.start | amDateFormat:'LLLL'), END_TIME:(events.moved.oldSlot.end | amDateFormat:'LT') } }}
@@ -153,7 +153,7 @@
-
{{ 'cart.datetime_to_time' | translate:{START_DATETIME:(modifiedSlots.newReservedSlot.start | amDateFormat:'LLLL'), END_TIME:(modifiedSlots.newReservedSlot.end | amDateFormat:'LT') } }}
+
{{ 'cart.datetime_to_time' | translate:{START_DATETIME:(events.moved.newSlot.start | amDateFormat:'LLLL'), END_TIME:(events.moved.newSlot.end | amDateFormat:'LT') } }}