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 != ''

View File

@@ -0,0 +1,9 @@
# Used to display a message before redirecting to a link
angular.module("admin.standingOrders").directive "confirmOrderEdit", (ConfirmDialog, $window) ->
restrict: "A"
link: (scope, element, attrs) ->
element.bind "click", (event) ->
unless scope.proxyOrder.order_id?
event.preventDefault()
ConfirmDialog.open('error', t('admin.standing_orders.orders.confirm_edit'), {confirm: t('yes_i_am_sure')}).then ->
$window.open(attrs.href)

View File

@@ -0,0 +1,28 @@
angular.module("admin.standingOrders").directive 'newStandingOrderDialog', ($compile, $window, $templateCache, DialogDefaults, shops) ->
restrict: 'A'
scope: true
link: (scope, element, attr) ->
scope.submitted = false
scope.shops = shops
scope.shop_id = null
scope.newStandingOrder = ->
scope.new_standing_order_form.$setPristine()
scope.submitted = true
if scope.shop_id?
$window.location.href = "/admin/standing_orders/new?standing_order[shop_id]=#{scope.shop_id}"
return
# Compile modal template
template = $compile($templateCache.get('admin/new_standing_order_dialog.html'))(scope)
# Set Dialog options
template.dialog(DialogDefaults)
# Link opening of dialog to click event on element
element.bind 'click', (e) ->
if shops.length == 1
scope.shop_id = shops[0].id
scope.newStandingOrder()
else
template.dialog('open')

View File

@@ -0,0 +1,5 @@
angular.module("admin.standingOrders").factory 'CreditCardResource', ($resource) ->
resource = $resource '/admin/customers/:customer_id/cards.json', {},
'index':
method: 'GET'
isArray: true

View File

@@ -0,0 +1,6 @@
angular.module("admin.standingOrders").factory "StandingOrder", ($injector, StandingOrderResource) ->
class StandingOrder extends StandingOrderResource
constructor: ->
if $injector.has('standingOrder')
angular.extend(@, $injector.get('standingOrder'))

View File

@@ -0,0 +1,35 @@
angular.module("admin.standingOrders").factory 'StandingOrderForm', ($window, StatusMessage) ->
class StandingOrderForm
form: null
standingOrder: null
errors: {}
constructor: (form, standingOrder) ->
@form = form
@standingOrder = standingOrder
save: =>
return @formInvalid() unless @form.$valid
delete @errors[k] for k, v of @errors
@form.$setPristine()
StatusMessage.display 'progress', 'Saving...'
if @standingOrder.id?
@standingOrder.update().then @successCallback, @errorCallback
else
@standingOrder.create().then @successCallback, @errorCallback
successCallback: (response) =>
StatusMessage.display 'success', 'Saved. Redirecting...'
$window.location.href = "/admin/standing_orders"
errorCallback: (response) =>
if response.data?.errors?
angular.extend(@errors, response.data.errors)
keys = Object.keys(response.data.errors)
StatusMessage.display 'failure', response.data.errors[keys[0]][0]
else
# Happens when there are sync issues between SO and initialised orders
# We save the SO, but open a dialog, so want to stay on the page
StatusMessage.display 'success', 'Saved'
formInvalid: -> StatusMessage.display 'failure', t('admin.standing_orders.details.invalid_error')

View File

@@ -0,0 +1,70 @@
angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, $injector, $q, InfoDialog, ConfirmDialog) ->
buildItem: (item) ->
return false unless item.variant_id > 0
return false unless item.quantity > 0
data = angular.extend({}, item, { shop_id: @shop_id, schedule_id: @schedule_id })
$http.post("/admin/standing_line_items/build", data).then (response) =>
@standing_line_items.push response.data
, (response) =>
InfoDialog.open 'error', response.data.errors[0]
removeItem: (item) ->
item._destroy = true
create: ->
@$save().then (response) =>
$injector.get('StandingOrders').afterCreate(@id) if $injector.has('StandingOrders')
$q.resolve(response)
, (response) => $q.reject(response)
update: ->
@$update().then (response) =>
$injector.get('StandingOrders').afterUpdate(@id) if $injector.has('StandingOrders')
orders_with_issues = @not_closed_proxy_orders.filter((po) -> po.update_issues.length > 0)
if orders_with_issues.length > 0
InfoDialog.open('error', null, 'admin/order_update_issues_dialog.html', { proxyOrders: orders_with_issues})
return $q.reject(response)
$q.resolve(response)
, (response) => $q.reject(response)
cancel: ->
ConfirmDialog.open('error', t('admin.standing_orders.confirm_cancel_msg'), {cancel: t('back'), confirm: t('admin.standing_orders.yes_i_am_sure')})
.then =>
@$cancel().then angular.noop, (response) =>
if response.data?.errors?.open_orders?
options = {cancel: t('admin.standing_orders.no_keep_them'), confirm: t('admin.standing_orders.yes_cancel_them')}
ConfirmDialog.open('error', response.data.errors.open_orders, options)
.then (=> @$cancel(open_orders: 'cancel')), (=> @$cancel(open_orders: 'keep'))
else
InfoDialog.open 'error', t('admin.standing_orders.cancel_failure_msg')
pause: ->
ConfirmDialog.open('error', t('admin.standing_orders.confirm_pause_msg'), {confirm: t('admin.standing_orders.yes_i_am_sure')})
.then =>
@$pause().then angular.noop, (response) =>
if response.data?.errors?.open_orders?
options = {cancel: t('admin.standing_orders.no_keep_them'), confirm: t('admin.standing_orders.yes_cancel_them')}
ConfirmDialog.open('error', response.data.errors.open_orders, options)
.then (=> @$pause(open_orders: 'cancel')), (=> @$pause(open_orders: 'keep'))
else
InfoDialog.open 'error', t('admin.standing_orders.pause_failure_msg')
unpause: ->
ConfirmDialog.open('error', t('admin.standing_orders.confirm_unpause_msg'), {confirm: t('admin.standing_orders.yes_i_am_sure')})
.then =>
@$unpause().then angular.noop, ->
InfoDialog.open 'error', t('admin.standing_orders.unpause_failure_msg')
cancelOrder: (order) ->
if order.id?
$http.put("/admin/proxy_orders/#{order.id}/cancel").then (response) =>
angular.extend(order,response.data)
, (response) ->
InfoDialog.open 'error', response.data.errors[0]
resumeOrder: (order) ->
if order.id?
$http.put("/admin/proxy_orders/#{order.id}/resume").then (response) =>
angular.extend(order,response.data)
, (response) ->
InfoDialog.open 'error', response.data.errors[0]

View File

@@ -0,0 +1,31 @@
angular.module("admin.standingOrders").factory 'StandingOrderResource', ($resource, StandingOrderPrototype) ->
resource = $resource('/admin/standing_orders/:id/:action.json', {}, {
'index':
method: 'GET'
isArray: true
'update':
method: 'PUT'
params:
id: '@id'
'cancel':
method: 'PUT'
params:
id: '@id'
action: 'cancel'
open_orders: '@open_orders'
'pause':
method: 'PUT'
params:
id: '@id'
action: 'pause'
open_orders: '@open_orders'
'unpause':
method: 'PUT'
params:
id: '@id'
action: 'unpause'
})
angular.extend(resource.prototype, StandingOrderPrototype)
resource

View File

@@ -0,0 +1,27 @@
angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOrderResource, StandingOrder, RequestMonitor) ->
new class StandingOrders
byID: {}
pristineByID: {}
index: (params={}, callback=null) ->
request = StandingOrderResource.index params, (data) => @load(data)
RequestMonitor.load(request.$promise)
request
load: (standingOrders) ->
for standingOrder in standingOrders
@byID[standingOrder.id] = standingOrder
@pristineByID[standingOrder.id] = angular.copy(standingOrder)
afterCreate: (id) ->
return unless @byID[id]?
@pristineByID[id] = angular.copy(@byID[id])
afterUpdate: (id) ->
return unless @byID[id]?
@pristineByID[id] = angular.copy(@byID[id])
afterRemoveItem: (id, deletedItemID) ->
return unless @pristineByID[id]?
for item, i in @pristineByID[id].standing_line_items when item.id == deletedItemID
@pristineByID[id].standing_line_items.splice(i, 1)

View File

@@ -0,0 +1 @@
angular.module("admin.standingOrders", ['ngResource','admin.indexUtils','admin.dropdown'])