Cancelling a standing order just changes the state, does not remove it from the page

This commit is contained in:
Rob Harrington
2016-12-08 12:02:58 +11:00
parent 522e646b36
commit 9c2e67e953
6 changed files with 8 additions and 21 deletions

View File

@@ -4,11 +4,10 @@ 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?
StandingOrders.index("q[shop_id_eq]": $scope.shop_id, "q[canceled_at_null]": true)
$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) ->

View File

@@ -36,9 +36,7 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http,
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')
, ->
@$cancel().then angular.noop, ->
InfoDialog.open 'error', t('admin.standing_orders.cancel_failure_msg')
pause: ->

View File

@@ -1,6 +1,5 @@
angular.module("admin.standingOrders").factory 'StandingOrders', ($q, StandingOrderResource, StandingOrder) ->
new class StandingOrders
all: []
byID: {}
pristineByID: {}
@@ -9,9 +8,7 @@ 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)
@@ -23,16 +20,7 @@ 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

View File

@@ -54,6 +54,6 @@
%a.edit-standing-order.icon-edit.no-text{ ng: { href: '{{standingOrder.edit_path}}'}, 'ofn-with-tip' => t('.edit_standing_order') }
%a.pause-standing-order.icon-pause.no-text{ ng: { click: 'standingOrder.pause()', hide: '!!standingOrder.paused_at' }, 'ofn-with-tip' => t('.pause_standing_order') , href: 'javascript:void(0)' }
%a.unpause-standing-order.icon-play.no-text{ ng: { click: 'standingOrder.unpause()', show: '!!standingOrder.paused_at' }, 'ofn-with-tip' => t('.unpause_standing_order') , href: 'javascript:void(0)' }
%a.cancel-standing-order.icon-remove.no-text{ ng: { click: 'standingOrder.cancel()'}, 'ofn-with-tip' => t('.cancel_standing_order') , href: 'javascript:void(0)' }
%a.cancel-standing-order.icon-remove.no-text{ ng: { click: 'standingOrder.cancel()', hide: '!!standingOrder.canceled_at'}, 'ofn-with-tip' => t('.cancel_standing_order') , href: 'javascript:void(0)' }
%tr.panel-row{ object: "standingOrder", panels: "{products: 'standing_order_products', orders: 'standing_order_orders'}" }

View File

@@ -123,8 +123,10 @@ feature 'Standing Orders' do
find("a.cancel-standing-order").click
end
click_button "Yes, I'm sure"
expect(page).to have_no_selector "tr#so_#{standing_order.id}"
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
within "tr#so_#{standing_order.id}" do
expect(page).to have_selector ".state.canceled", text: "CANCELLED"
expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now
end
end
end

View File

@@ -31,7 +31,7 @@ describe "StandingOrdersCtrl", ->
standingOrders = [standingOrder]
beforeEach ->
http.expectGET('/admin/standing_orders.json?q%5Bshop_id_eq%5D=3').respond 200, standingOrders
http.expectGET('/admin/standing_orders.json?q%5Bcanceled_at_null%5D=true&q%5Bshop_id_eq%5D=3').respond 200, standingOrders
scope.$apply -> scope.shop_id = 3
http.flush()