Sha256: 16d60220a7d1a70ae2af4b186b7e375c9b2c559402fd877c03a2d1b57b31b393

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

Sprangular.controller 'CheckoutAddressesCtrl', ($scope, Account, Cart, Checkout, Geography) ->
  Geography.getCountryList().then (countries) ->
    $scope.countries = countries

  $scope.order = Cart.current
  $scope.processing = false
  $scope.user = Account.user
  $scope.submitted = false

  unless Account.isGuest
    $scope.shippingAddresses = $scope.user.addresses.slice()
    $scope.billingAddresses = $scope.user.addresses.slice()

  $scope.$watch 'order.state', (state) ->
    $scope.done = _.contains(['confirm', 'payment', 'delivery'], state)
    $scope.active = _.contains(['cart', 'address'], state)

  createMergedAddressList = ->
    addresses = $scope.user.addresses
    order = $scope.order

    _.each $scope.shippingAddresses, (address, index) ->
      if address.same(order.shippingAddress)
        $scope.shippingAddresses[index] = order.shippingAddress

    _.each $scope.billingAddresses, (address, index) ->
      if address.same(order.billingAddress)
        $scope.billingAddresses[index] = order.billingAddress

  createMergedAddressList()

  $scope.edit = ->
    $scope.order.state = 'address'

  $scope.advance = ->
    order = $scope.order
    $scope.submitted = true

    return if order.shippingAddress.isInvalid() || (!order.billToShipAddress && order.billingAddress.isInvalid())

    $scope.processing = true

    Checkout.setAddresses()
      .then ->
          createMergedAddressList()
          $scope.processing = false
          $scope.submitted = false
        , ->
          $scope.processing = false

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sprangular-0.1.0 app/assets/javascripts/sprangular/controllers/checkout/addresses.coffee