From 0fd86a6cc731341f6d8f1bea42de4fd41c347951 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 16 Mar 2017 15:14:02 +1100 Subject: [PATCH] Adding UI to require action from user when pausing/cancelling standing order with open orders --- .../standing_order_prototype.js.coffee | 18 ++++++++++++++---- .../services/standing_order_resource.js.coffee | 2 ++ config/locales/en.yml | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/admin/standing_orders/services/standing_order_prototype.js.coffee b/app/assets/javascripts/admin/standing_orders/services/standing_order_prototype.js.coffee index f369a2b807..84ba84945c 100644 --- a/app/assets/javascripts/admin/standing_orders/services/standing_order_prototype.js.coffee +++ b/app/assets/javascripts/admin/standing_orders/services/standing_order_prototype.js.coffee @@ -30,14 +30,24 @@ 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 angular.noop, -> - InfoDialog.open 'error', t('admin.standing_orders.cancel_failure_msg') + @$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('yes_i_am_sure')}) .then => - @$pause().then angular.noop, -> - InfoDialog.open 'error', t('admin.standing_orders.pause_failure_msg') + @$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('yes_i_am_sure')}) diff --git a/app/assets/javascripts/admin/standing_orders/services/standing_order_resource.js.coffee b/app/assets/javascripts/admin/standing_orders/services/standing_order_resource.js.coffee index 1bc1c3a42f..2b4303e298 100644 --- a/app/assets/javascripts/admin/standing_orders/services/standing_order_resource.js.coffee +++ b/app/assets/javascripts/admin/standing_orders/services/standing_order_resource.js.coffee @@ -12,11 +12,13 @@ angular.module("admin.standingOrders").factory 'StandingOrderResource', ($resour 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: diff --git a/config/locales/en.yml b/config/locales/en.yml index 6ad3be4d87..4be858f6f8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -859,6 +859,8 @@ en: confirm_unpause_msg: Are you sure you want to unpause this standing order? unpause_failure_msg: 'Sorry, unpausing failed!' confirm_cancel_open_orders_msg: "Some orders for this standing order are currently open. The customer has already been notified that the order will be placed. Would you like to cancel these order(s) or keep them?" + yes_cancel_them: Cancel them + no_keep_them: Keep them order_update_issues_msg: Some orders could not be automatically updated, this is most likely because they have been manually edited. Please review the issues listed below and make any adjustments to individual orders if required. no_results: no_standing_orders: No standing orders yet...