mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
28 lines
957 B
CoffeeScript
28 lines
957 B
CoffeeScript
Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, CurrentHub) ->
|
|
$scope.Checkout = Checkout
|
|
$scope.submitted = false
|
|
|
|
# Bind to local storage
|
|
$scope.fieldsToBind = ["bill_address", "email", "payment_method_id", "shipping_method_id", "ship_address"]
|
|
prefix = "order_#{Checkout.order.id}#{CurrentUser.id or ""}#{CurrentHub.hub.id}"
|
|
|
|
for field in $scope.fieldsToBind
|
|
storage.bind $scope, "Checkout.order.#{field}",
|
|
storeName: "#{prefix}_#{field}"
|
|
storage.bind $scope, "Checkout.ship_address_same_as_billing",
|
|
storeName: "#{prefix}_sameasbilling"
|
|
defaultValue: true
|
|
|
|
$scope.order = Checkout.order # Ordering is important
|
|
$scope.secrets = Checkout.secrets
|
|
|
|
$scope.enabled = !!CurrentUser.id?
|
|
|
|
$scope.purchase = (event, form) ->
|
|
event.preventDefault()
|
|
$scope.submitted = true
|
|
if form.$valid
|
|
$scope.Checkout.submit()
|
|
else
|
|
$scope.$broadcast 'purchaseFormInvalid', form
|