Files
openfoodnetwork/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee
2014-04-11 12:37:32 +10:00

36 lines
1.2 KiB
CoffeeScript

Darkswarm.controller "CheckoutCtrl", ($scope, $rootScope, order, $location, $anchorScroll) ->
$scope.require_ship_address = false
$scope.order = order
$scope.userOpen = true
$scope.initialize = ->
# Our shipping_methods comes through as a hash like so: {id: requires_shipping_address}
# Here we default to the first shipping method if none is selected
$scope.order.shipping_method_id ||= Object.keys(order.shipping_methods)[0]
$scope.order.ship_address_same_as_billing = true if $scope.order.ship_address_same_as_billing == null
$scope.shippingMethodChanged()
$scope.shippingPrice = ->
$scope.shippingMethod().price
$scope.cartTotal = ->
$scope.shippingPrice() + $scope.order.display_total
$scope.shippingMethod = ->
$scope.order.shipping_methods[$scope.order.shipping_method_id]
$scope.shippingMethodChanged = ->
$scope.require_ship_address = $scope.shippingMethod().require_ship_address if $scope.shippingMethod()
$scope.purchase = (event)->
event.preventDefault()
checkout.submit()
$scope.scrollTo = (name)->
$location.hash(name);
$anchorScroll();
$scope.userOpen = false
$scope.initialize()