Files
openfoodnetwork/app/assets/javascripts/admin/subscriptions/controllers/subscription_controller.js.coffee

28 lines
1.3 KiB
CoffeeScript

angular.module("admin.subscriptions").controller "SubscriptionController", ($scope, Subscription, SubscriptionForm, customers, schedules, paymentMethods, shippingMethods) ->
$scope.subscription = new Subscription()
$scope.errors = null
$scope.save = null
$scope.customers = customers
$scope.schedules = schedules
$scope.paymentMethods = paymentMethods
$scope.shippingMethods = shippingMethods
$scope.distributor_id = $scope.subscription.shop_id # variant selector requires distributor_id
$scope.view = if $scope.subscription.id? then 'review' else 'details'
$scope.nextCallbacks = {}
$scope.backCallbacks = {}
$scope.creditCards = []
$scope.setView = (view) -> $scope.view = view
$scope.stepTitleFor = (step) -> t("admin.subscriptions.steps.#{step}")
$scope.registerNextCallback = (view, callback) => $scope.nextCallbacks[view] = callback
$scope.registerBackCallback = (view, callback) => $scope.backCallbacks[view] = callback
$scope.next = -> $scope.nextCallbacks[$scope.view]()
$scope.back = -> $scope.backCallbacks[$scope.view]()
$scope.shipAddressFromBilling = =>
angular.extend($scope.subscription.ship_address, $scope.subscription.bill_address)
$scope.$watch 'subscription_form', ->
form = new SubscriptionForm($scope.subscription_form, $scope.subscription)
$scope.errors = form.errors
$scope.save = form.save