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

remove reference to machine in cart directive code

This commit is contained in:
Sylvain 2017-02-21 16:41:53 +01:00
parent 5a41424579
commit 11619dc6c5
4 changed files with 29 additions and 25 deletions

View File

@ -6,6 +6,11 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
slot: '='
slotSelectionTime: '='
events: '='
user: '='
modePlans: '='
plan: '='
planSelectionTime: '='
settings: '='
onSlotAddedToCart: '='
onSlotRemovedFromCart: '='
onSlotStartToModify: '='
@ -14,12 +19,9 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
onSlotModifyCancel: '='
onSlotModifyUnselect: '='
onSlotCancelSuccess: '='
user: '='
modePlans: '='
plan: '='
planSelectionTime: '='
afterPayment: '='
settings: '='
reservableId: '@'
reservableType: '@'
templateUrl: '<%= asset_path "shared/_cart.html" %>'
link: ($scope, element, attributes) ->
## will store the user's plan if he choosed to buy one
@ -63,11 +65,11 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
##
# Remove the provided slot from the shopping cart (state transition from 'about to be reserved' to free)
# and decrement the total amount of the cart if needed.
# @param machineSlot {Object} fullCalendar event object
# @param slot {Object} fullCalendar event object
# @param index {number} index of the slot in the reservation array
# @param [event] {Object} see https://docs.angularjs.org/guide/expression#-event-
##
$scope.removeMachineSlot = (machineSlot, index, event)->
$scope.removeSlot = (slot, index, event)->
event.preventDefault() if event
$scope.events.reserved.splice(index, 1)
# if is was the last slot, we remove any plan from the cart
@ -75,7 +77,7 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
$scope.selectedPlan = null
$scope.plan = null
$scope.modePlans = false
$scope.onSlotRemovedFromCart(machineSlot) if typeof $scope.onSlotRemovedFromCart == 'function'
$scope.onSlotRemovedFromCart(slot) if typeof $scope.onSlotRemovedFromCart == 'function'
updateCartPrice()
@ -84,7 +86,7 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
# Checks that every selected slots were added to the shopping cart. Ie. will return false if
# any checked slot was not validated by the user.
##
$scope.machineSlotsValid = ->
$scope.isSlotsValid = ->
isValid = true
angular.forEach $scope.events.reserved, (m)->
isValid = false if !m.isValid
@ -101,7 +103,7 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
##
# Validates the shopping chart and redirect the user to the payment step
##
$scope.payMachine = ->
$scope.payCart = ->
# first, we check that a user was selected
if Object.keys($scope.user).length > 0
reservation = mkReservation($scope.user, $scope.events.reserved, $scope.selectedPlan)
@ -121,7 +123,7 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
##
# When modifying an already booked reservation, confirm the modification.
##
$scope.modifyMachineSlot = ->
$scope.modifySlot = ->
Slot.update {id: $scope.events.modifiable.id},
slot:
start_at: $scope.events.placable.start
@ -138,7 +140,7 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
##
# Cancel the current booking modification, reseting the whole process
##
$scope.cancelModifyMachineSlot = ->
$scope.cancelModifySlot = ->
$scope.onSlotModifyCancel() if typeof $scope.onSlotModifyCancel == 'function'
$scope.events.placable = null
$scope.events.modifiable = null
@ -207,7 +209,7 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
$scope.onSlotAddedToCart() if typeof $scope.onSlotAddedToCart == 'function'
else
# slot is in the cart, remove it
$scope.removeMachineSlot($scope.slot, index)
$scope.removeSlot($scope.slot, index)
# finally, we update the prices
updateCartPrice()
else if !$scope.slot.is_reserved && $scope.events.modifiable
@ -222,7 +224,7 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
else if $scope.slot.is_reserved and $scope.events.modifiable and $scope.slot.is_reserved._id == $scope.events.modifiable._id
# slot is reserved and currently modified
# -> we cancel the modification
$scope.cancelModifyMachineSlot()
$scope.cancelModifySlot()
else if $scope.slot.is_reserved and (slotCanBeModified($scope.slot) or slotCanBeCanceled($scope.slot)) and !$scope.events.modifiable and $scope.events.reserved.length == 0
# slot is reserved and is ok to be modified or cancelled
# but we are not currently running a modification or having any slots in the cart
@ -349,8 +351,8 @@ Application.Directives.directive 'cart', [ '$rootScope', '$uibModal', 'dialogs',
mkReservation = (member, slots, plan = null) ->
reservation =
user_id: member.id
reservable_id: (slots[0].machine.id if slots.length > 0)
reservable_type: 'Machine'
reservable_id: $scope.reservableId
reservable_type: $scope.reservableType
slots_attributes: []
plan_id: (plan.id if plan)
angular.forEach slots, (slot, key) ->

View File

@ -55,7 +55,9 @@
on-slot-modify-cancel="cancelModifyMachineSlot"
on-slot-modify-unselect="changeModifyMachineSlot"
on-slot-cancel-success="markSlotAsRemoved"
after-payment="afterPayment"></cart>
after-payment="afterPayment"
reservable-id="{{machine.id}}"
reservable-type="Machine"></cart>
<uib-alert type="warning m">
<p class="text-sm">

View File

@ -33,13 +33,13 @@
<button class="btn btn-valid btn-warning btn-block text-u-c r-b" ng-click="validateSlot(machineSlot)" ng-if="!machineSlot.isValid" translate>{{ 'confirm_this_slot' }}</button>
</div>
<div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeMachineSlot(machineSlot, $index, $event)" ng-if="machineSlot.isValid" translate>{{ 'remove_this_slot' }}</a></div>
<div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="removeSlot(machineSlot, $index, $event)" ng-if="machineSlot.isValid" translate>{{ 'remove_this_slot' }}</a></div>
</div>
<coupon show="machineSlotsValid() && (!modePlans || selectedPlan)" coupon="coupon.applied" total="totalNoCoupon" user-id="{{user.id}}"></coupon>
<coupon show="isSlotsValid() && (!modePlans || selectedPlan)" coupon="coupon.applied" total="totalNoCoupon" user-id="{{user.id}}"></coupon>
<span ng-hide="fablabWithoutPlans">
<div ng-if="machineSlotsValid() && !user.subscribed_plan" ng-show="!modePlans">
<div ng-if="isSlotsValid() && !user.subscribed_plan" ng-show="!modePlans">
<p class="font-sbold text-base l-h-2x" translate>{{ 'to_benefit_from_attractive_prices' }}</p>
<div><button class="btn btn-warning-full rounded btn-block text-xs" ng-click="showPlans()" translate>{{ 'view_our_subscriptions' }}</button></div>
<p class="font-bold text-base text-u-c text-center m-b-xs" translate>{{ 'or' }}</p>
@ -59,7 +59,7 @@
</div>
<div class="panel-footer no-padder" ng-if="events.reserved.length > 0">
<button class="btn btn-valid btn-info btn-block p-l btn-lg text-u-c r-b text-base" ng-click="payMachine()" ng-if="machineSlotsValid() && (!modePlans || selectedPlan)">{{ 'confirm_and_pay' | translate }} {{amountTotal | currency}}</button>
<button class="btn btn-valid btn-info btn-block p-l btn-lg text-u-c r-b text-base" ng-click="payCart()" ng-if="isSlotsValid() && (!modePlans || selectedPlan)">{{ 'confirm_and_pay' | translate }} {{amountTotal | currency}}</button>
</div>
<div class="widget-content no-bg auto wrapper" ng-if="paidMachineSlots">
@ -99,7 +99,7 @@
<div class="panel-body">
<div class="font-sbold text-u-c">{{ 'datetime_to_time' | translate:{START_DATETIME:(events.modifiable.start | amDateFormat:'LLLL'), END_TIME:(events.modifiable.end | amDateFormat:'LT') } }}</div>
</div>
<div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="cancelModifyMachineSlot($event)" translate>{{ 'cancel_my_modification' }}</a></div>
<div class="clear"><a class="pull-right m-b-sm text-u-l ng-scope m-r-sm" href="#" ng-click="cancelModifySlot($event)" translate>{{ 'cancel_my_modification' }}</a></div>
</div>
<div class="widget-content no-bg">
@ -134,9 +134,9 @@
<div class="panel-footer no-padder" ng-if="events.modifiable && events.placable">
<button class="btn btn-invalid btn-default btn-block p-l btn-lg text-u-c r-n text-base" ng-click="cancelModifyMachineSlot()" translate>{{ 'cancel' }}</button>
<button class="btn btn-invalid btn-default btn-block p-l btn-lg text-u-c r-n text-base" ng-click="cancelModifySlot()" translate>{{ 'cancel' }}</button>
<div>
<button class="btn btn-valid btn-info btn-block p-l btn-lg text-u-c r-b text-base" ng-click="modifyMachineSlot()" translate>{{ 'confirm_my_modification' }}</button>
<button class="btn btn-valid btn-info btn-block p-l btn-lg text-u-c r-b text-base" ng-click="modifySlot()" translate>{{ 'confirm_my_modification' }}</button>
</div>
</div>

View File

@ -44,7 +44,7 @@ class API::PricesController < API::ApiController
@amount = {elements: nil, total: 0, before_coupon: 0}
else
_reservable = _price_params[:reservable_type].constantize.find(_price_params[:reservable_id])
@amount = Price.compute(current_user.is_admin?, _user, _reservable, _price_params[:slots_attributes], _price_params[:plan_id], _price_params[:nb_reserve_places], _price_params[:tickets_attributes], coupon_params[:coupon_code])
@amount = Price.compute(current_user.is_admin?, _user, _reservable, _price_params[:slots_attributes] || [], _price_params[:plan_id], _price_params[:nb_reserve_places], _price_params[:tickets_attributes], coupon_params[:coupon_code])
end