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

View File

@@ -4,5 +4,5 @@
%i.icon-question-sign
.text{ ng: { bind: "::message" } }
.action-buttons.text-center
%button{ ng: { click: "close()", bind: "::cancelText" } }
%button.red{ ng: { click: "confirm()", bind: "::confirmText" } }
%button.cancel{ ng: { click: "close()", bind: "::cancelText" } }
%button.confirm.red{ ng: { click: "confirm()", bind: "::confirmText" } }

View File

@@ -4,13 +4,13 @@
%table.index#standing_orders
%col.customer{ width: "20%", 'ng-show' => 'columns.customer.visible' }
%col.schedule{ width: "15%", 'ng-show' => 'columns.schedule.visible' }
%col.items{ width: "15%", 'ng-show' => 'columns.items.visible' }
%col.orders{ width: "15%", 'ng-show' => 'columns.orders.visible' }
%col.items{ width: "10%", 'ng-show' => 'columns.items.visible' }
%col.orders{ width: "10%", 'ng-show' => 'columns.orders.visible' }
%col.begins_on{ width: "10%", 'ng-show' => 'columns.begins_on.visible' }
%col.ends_on{ width: "10%", 'ng-show' => 'columns.ends_on.visible' }
%col.payment_method{ width: "20%", 'ng-show' => 'columns.payment_method.visible' }
%col.shipping_method{ width: "20%", 'ng-show' => 'columns.shipping_method.visible' }
%col.actions{ width: "5%" }
%col.actions{ width: "10%" }
%thead
%tr
-# %th.bulk
@@ -47,6 +47,6 @@
%td.shipping_method{ ng: { show: 'columns.shipping_method.visible', bind: '::shippingMethodsByID[standingOrder.shipping_method_id].name' } }
%td.actions
%a.edit-standing-order.icon-edit.no-text{ ng: { href: '{{standingOrder.edit_path}}'} }
-# %a.delete-standing-order.icon-trash.no-text{ ng: { href: '{{standingOrder.delete_path}}'}, data: { method: 'delete', confirm: "Are you sure?" } }
%a.cancel-standing-order.icon-remove.no-text{ ng: { click: 'standingOrder.cancel()'} }
%tr.panel-row{ object: "standingOrder", panels: "{products: 'standing_order_products', orders: 'standing_order_orders'}" }

View File

@@ -129,10 +129,6 @@ en:
say_yes: "Yes"
then: then
ongoing: Ongoing
closes: Closes
closed: Closed
could_not_cancel_the_order: Could not cancel the order
could_not_resume_the_order: Could not resume the order
bill_address: Billing Address
ship_address: Shipping Address
sort_order_cycles_on_shopfront_by: "Sort Order Cycles On Shopfront By"
@@ -816,6 +812,8 @@ en:
orders:
number: Number
status: Status
confirm_cancel_msg: Are you sure you want to cancel this standing order? This action cannot be undone.
cancel_failure_msg: 'Sorry, cancellation failed!'
stripe_connect_settings:
edit:

View File

@@ -97,6 +97,14 @@ feature 'Standing Orders' do
expect(standing_order_order.reload.cancelled_at).to be nil
end
end
# Cancelling a standing order
within "tr#so_#{standing_order.id}" 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
end
end