Renaming standing order files

This commit is contained in:
Rob Harrington
2018-02-02 16:10:10 +11:00
parent b258c032cc
commit a9b5fd69d8
57 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
angular.module("admin.standingOrders").controller "AddressController", ($scope, $filter, StatusMessage, availableCountries) ->
$scope.countries = availableCountries
$scope.statesFor = (country_id) ->
return [] unless country_id
$filter('filter')(availableCountries, {id: country_id})[0].states
$scope.billStates = $scope.statesFor($scope.standingOrder.bill_address.country_id)
$scope.shipStates = $scope.statesFor($scope.standingOrder.ship_address.country_id)
$scope.registerNextCallback 'address', ->
$scope.standing_order_form.$submitted = true
if $scope.standing_order_address_form.$valid
$scope.standing_order_form.$setPristine()
StatusMessage.clear()
$scope.setView('products')
else
StatusMessage.display 'failure', t('admin.standing_orders.details.invalid_error')
$scope.registerBackCallback 'address', ->
StatusMessage.clear()
$scope.setView('details')
$scope.$watch 'standingOrder.bill_address.country_id', (newValue, oldValue) ->
$scope.billStates = $scope.statesFor(newValue) if newValue?
$scope.$watch 'standingOrder.ship_address.country_id', (newValue, oldValue) ->
$scope.shipStates = $scope.statesFor(newValue) if newValue?

View File

@@ -0,0 +1,38 @@
angular.module("admin.standingOrders").controller "DetailsController", ($scope, $http, CreditCardResource, StatusMessage) ->
$scope.cardRequired = false
$scope.registerNextCallback 'details', ->
$scope.standing_order_form.$submitted = true
if $scope.standing_order_details_form.$valid
$scope.standing_order_form.$setPristine()
StatusMessage.clear()
$scope.setView('address')
else
StatusMessage.display 'failure', t('admin.standing_orders.details.invalid_error')
$scope.$watch "standingOrder.customer_id", (newValue, oldValue) ->
return if !newValue?
$scope.loadAddresses(newValue) unless $scope.standingOrder.id?
$scope.loadCreditCards(newValue)
$scope.$watch "standingOrder.payment_method_id", (newValue, oldValue) ->
return if !newValue?
paymentMethod = ($scope.paymentMethods.filter (pm) -> pm.id == newValue)[0]
return unless paymentMethod?
if paymentMethod.type == "Spree::Gateway::StripeConnect"
$scope.cardRequired = true
else
$scope.cardRequired = false
$scope.standingOrder.credit_card_id = null
$scope.loadAddresses = (customer_id) ->
$http.get("/admin/customers/#{customer_id}/addresses")
.success (response) =>
delete response.bill_address.id
delete response.ship_address.id
angular.extend($scope.standingOrder.bill_address, response.bill_address)
angular.extend($scope.standingOrder.ship_address, response.ship_address)
$scope.shipAddressFromBilling() unless response.ship_address.address1?
$scope.loadCreditCards = (customer_id) ->
$scope.creditCards = CreditCardResource.index(customer_id: customer_id)

View File

@@ -0,0 +1,10 @@
angular.module("admin.standingOrders").controller "OrderUpdateIssuesController", ($scope, OrderCycles) ->
$scope.proxyOrders = $scope.options.proxyOrders
$scope.orderCycleName = (id) ->
OrderCycles.byID[id].name
$scope.orderCycleCloses = (id) ->
closes_at = moment(OrderCycles.byID[id].orders_close_at)
text = if closes_at > moment() then t('closes') else t('closed')
"#{text} #{closes_at.fromNow()}"

View File

@@ -0,0 +1,20 @@
angular.module("admin.standingOrders").controller "OrdersPanelController", ($scope, OrderCycles) ->
$scope.standingOrder = $scope.object
$scope.cancelOrder = (order) ->
if confirm(t('are_you_sure'))
$scope.standingOrder.cancelOrder(order)
$scope.resumeOrder = (order) ->
if confirm(t('are_you_sure'))
$scope.standingOrder.resumeOrder(order)
$scope.orderCycleName = (id) ->
OrderCycles.byID[id].name
$scope.orderCycleCloses = (id) ->
closes_at = moment(OrderCycles.byID[id].orders_close_at)
text = if closes_at > moment() then t('closes') else t('closed')
"#{text} #{closes_at.fromNow()}"
$scope.stateText = (state) -> t("spree.order_state.#{state}")

View File

@@ -0,0 +1,13 @@
angular.module("admin.standingOrders").controller "ProductsController", ($scope, StatusMessage) ->
$scope.registerNextCallback 'products', ->
$scope.standing_order_form.$submitted = true
if $scope.standingOrder.standing_line_items.length > 0
$scope.standing_order_form.$setPristine()
StatusMessage.clear()
$scope.setView('review')
else
StatusMessage.display 'failure', 'Please add at least one product'
$scope.registerBackCallback 'products', ->
StatusMessage.clear()
$scope.setView('address')

View File

@@ -0,0 +1,23 @@
angular.module("admin.standingOrders").controller "ProductsPanelController", ($scope, StandingOrders, StatusMessage) ->
$scope.standingOrder = $scope.object
$scope.distributor_id = $scope.standingOrder.shop_id
$scope.saving = false
$scope.saved = ->
pristine = StandingOrders.pristineByID[$scope.standingOrder.id].standing_line_items
return false unless angular.equals($scope.standingOrder.standing_line_items, pristine)
true
$scope.save = ->
$scope.saving = true
StatusMessage.display 'progress', 'Saving...'
$scope.standingOrder.update().then (response) ->
$scope.saving = false
StatusMessage.display 'success', 'Saved'
, (response) ->
$scope.saving = false
if response.data?.errors?
keys = Object.keys(response.data.errors)
StatusMessage.display 'failure', response.data.errors[keys[0]][0]
else
StatusMessage.display 'success', 'Saved'

View File

@@ -0,0 +1,33 @@
angular.module("admin.standingOrders").controller "StandingLineItemsController", ($scope, InfoDialog) ->
$scope.newItem = { variant_id: 0, quantity: 1 }
$scope.addStandingLineItem = ->
match = $scope.match()
if match
if match._destroy
angular.extend(match, $scope.newItem)
delete match._destroy
else
InfoDialog.open 'error', t('admin.standing_orders.product_already_in_order')
else
$scope.standing_order_form.$setDirty()
$scope.standingOrder.buildItem($scope.newItem)
$scope.removeStandingLineItem = (item) ->
$scope.standing_order_form.$setDirty()
$scope.standingOrder.removeItem(item)
$scope.match = ->
matching = $scope.standingOrder.standing_line_items.filter (sli) ->
sli.variant_id == $scope.newItem.variant_id
return matching[0] if matching.length > 0
null
$scope.estimatedSubtotal = ->
$scope.standingOrder.standing_line_items.reduce (subtotal, item) ->
return subtotal if item._destroy
subtotal += item.price_estimate * item.quantity
, 0
$scope.estimatedTotal = ->
$scope.estimatedSubtotal()

View File

@@ -0,0 +1,27 @@
angular.module("admin.standingOrders").controller "StandingOrderController", ($scope, StandingOrder, StandingOrderForm, customers, schedules, paymentMethods, shippingMethods) ->
$scope.standingOrder = new StandingOrder()
$scope.errors = null
$scope.save = null
$scope.customers = customers
$scope.schedules = schedules
$scope.paymentMethods = paymentMethods
$scope.shippingMethods = shippingMethods
$scope.distributor_id = $scope.standingOrder.shop_id # variant selector requires distributor_id
$scope.view = if $scope.standingOrder.id? then 'review' else 'details'
$scope.nextCallbacks = {}
$scope.backCallbacks = {}
$scope.creditCards = []
$scope.setView = (view) -> $scope.view = view
$scope.stepTitleFor = (step) -> t("admin.standing_orders.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.standingOrder.ship_address, $scope.standingOrder.bill_address)
$scope.$watch 'standing_order_form', ->
form = new StandingOrderForm($scope.standing_order_form, $scope.standingOrder)
$scope.errors = form.errors
$scope.save = form.save

View File

@@ -0,0 +1,20 @@
angular.module("admin.standingOrders").controller "StandingOrdersController", ($scope, StandingOrders, Columns, RequestMonitor, shops, ShippingMethods, PaymentMethods) ->
$scope.columns = Columns.columns
$scope.shops = shops
$scope.shop_id = if shops.length == 1 then shops[0].id else null
$scope.shippingMethodsByID = ShippingMethods.byID
$scope.paymentMethodsByID = PaymentMethods.byID
$scope.RequestMonitor = RequestMonitor
$scope.query = ''
$scope.$watch "shop_id", ->
if $scope.shop_id?
$scope.standingOrders = StandingOrders.index("q[shop_id_eq]": $scope.shop_id, "q[canceled_at_null]": true)
$scope.itemCount = (standingOrder) ->
standingOrder.standing_line_items.reduce (sum, sli) ->
return sum + sli.quantity
, 0
$scope.filtersApplied = ->
$scope.query != ''