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,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)