From b4e28b94f3921382746cfa06402e601eb4b36b62 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 9 Aug 2016 17:20:38 +0200 Subject: [PATCH] apply coupon in payment modal + fix update user w/o organization --- .../controllers/machines.coffee.erb | 23 ++++++++++++++----- .../templates/shared/_member_form.html.erb | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/controllers/machines.coffee.erb b/app/assets/javascripts/controllers/machines.coffee.erb index 99158a01b..ff4065d82 100644 --- a/app/assets/javascripts/controllers/machines.coffee.erb +++ b/app/assets/javascripts/controllers/machines.coffee.erb @@ -635,16 +635,27 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat + ## + # Format the parameters expected by /api/prices/compute and return the resulting object + # @param reservation {Object} as returned by mkReservation() + # @param coupon {Object} Coupon as returned from the API + # @return {{reservation:Object, coupon_id:number}} + ## + mkComputePriceParams = (reservation, coupon) -> + params = {reservation: reservation} + if coupon + params['coupon_id'] = coupon.id + params + + + ## # Update the total price of the current selection/reservation ## updateCartPrice = -> if Object.keys($scope.ctrl.member).length > 0 r = mkReservation($scope.ctrl.member, $scope.eventsReserved, $scope.selectedPlan) - params = {reservation: r} - if $scope.coupon.applied - params['coupon_id'] = $scope.coupon.applied.id - Price.compute params, (res) -> + Price.compute mkComputePriceParams(r, $scope.coupon.applied), (res) -> $scope.amountTotal = res.price setSlotsDetails(res.details) else @@ -759,7 +770,7 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat reservation: -> reservation price: -> - Price.compute({reservation: reservation}).$promise + Price.compute(mkComputePriceParams(reservation, $scope.coupon.applied)).$promise wallet: -> Wallet.getWalletByUser({user_id: reservation.user_id}).$promise cgv: -> @@ -816,7 +827,7 @@ Application.Controllers.controller "ReserveMachineController", ["$scope", "$stat reservation: -> reservation price: -> - Price.compute({reservation: reservation}).$promise + Price.compute(mkComputePriceParams(reservation, $scope.coupon.applied)).$promise wallet: -> Wallet.getWalletByUser({user_id: reservation.user_id}).$promise controller: ['$scope', '$uibModalInstance', '$state', 'reservation', 'price', 'Auth', 'Reservation', 'wallet', 'helpers', '$filter', '$locale', ($scope, $uibModalInstance, $state, reservation, price, Auth, Reservation, wallet, helpers, $filter, $locale) -> diff --git a/app/assets/templates/shared/_member_form.html.erb b/app/assets/templates/shared/_member_form.html.erb index 621247e07..b6c6d278e 100644 --- a/app/assets/templates/shared/_member_form.html.erb +++ b/app/assets/templates/shared/_member_form.html.erb @@ -162,7 +162,7 @@ {{ 'confirmation_mismatch_with_password' }} -
+
{{ 'organization_name_is_required' }}
-
+