Adding cancel button to standing orders index

This commit is contained in:
Rob Harrington
2016-12-07 14:54:03 +11:00
parent a2ddf78842
commit 774245f540
8 changed files with 43 additions and 13 deletions

View File

@@ -4,11 +4,11 @@ angular.module("admin.standingOrders").controller "StandingOrdersController", ($
$scope.shop_id = if shops.length == 1 then shops[0].id else null
$scope.shippingMethodsByID = ShippingMethods.byID
$scope.paymentMethodsByID = PaymentMethods.byID
$scope.standingOrders = StandingOrders.all
$scope.$watch "shop_id", ->
if $scope.shop_id?
# CurrentShop.shop = $filter('filter')($scope.shops, {id: $scope.shop_id})[0]
$scope.standingOrders = StandingOrders.index("q[shop_id_eq]": $scope.shop_id)
StandingOrders.index("q[shop_id_eq]": $scope.shop_id, "q[canceled_at_null]": true)
$scope.itemCount = (standingOrder) ->
standingOrder.standing_line_items.reduce (sum, sli) ->

View File

@@ -1,4 +1,4 @@
angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, $injector, InfoDialog, StatusMessage) ->
angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, $injector, InfoDialog, ConfirmDialog, StatusMessage) ->
errors: {}
buildItem: (item) ->
@@ -33,6 +33,13 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http,
StatusMessage.display 'failure', 'Oh no! I was unable to save your changes.'
angular.extend(@errors, response.data.errors)
cancel: ->
ConfirmDialog.open('error', t('admin.standing_orders.confirm_cancel_msg'), {cancel: t('back'), confirm: t('yes_i_am_sure')})
.then =>
@$cancel().then (response) =>
$injector.get('StandingOrders').afterCancel(@) if $injector.has('StandingOrders')
, ->
InfoDialog.open 'error', t('admin.standing_orders.cancel_failure_msg')
cancelOrder: (order) ->
if order.id?

View File

@@ -7,6 +7,11 @@ angular.module("admin.standingOrders").factory 'StandingOrderResource', ($resour
method: 'PUT'
params:
id: '@id'
'cancel':
method: 'PUT'
params:
id: '@id'
action: 'cancel'
})
angular.extend(resource.prototype, StandingOrderPrototype)

View File

@@ -1,5 +1,6 @@
angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOrderResource, StandingOrder) ->
new class StandingOrders
all: []
byID: {}
pristineByID: {}
@@ -8,7 +9,9 @@ angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOr
@load(data)
load: (standingOrders) ->
@clear()
for standingOrder in standingOrders
@all.push standingOrder
@byID[standingOrder.id] = standingOrder
@pristineByID[standingOrder.id] = angular.copy(standingOrder)
@@ -20,7 +23,16 @@ angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOr
return unless @byID[id]?
@pristineByID[id] = angular.copy(@byID[id])
afterCancel: (item) ->
i = @all.indexOf(item)
@all.splice(i,1) if i >= 0
delete @byID[item.id]
delete @pristineByID[item.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)
clear: ->
@all.length = 0