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 57c549db39..c099ed125d 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 @@ -40,3 +40,10 @@ angular.module("admin.standingOrders").factory 'StandingOrderPrototype', ($http, angular.extend(order,response.data) , (response) -> InfoDialog.open 'error', response.data.errors[0] + + resumeOrder: (order) -> + if order.id? + $http.put("/admin/standing_order_orders/#{order.id}/resume").then (response) => + angular.extend(order,response.data) + , (response) -> + InfoDialog.open 'error', response.data.errors[0] diff --git a/app/controllers/admin/standing_order_orders_controller.rb b/app/controllers/admin/standing_order_orders_controller.rb index 39f54edfa2..8551559ad2 100644 --- a/app/controllers/admin/standing_order_orders_controller.rb +++ b/app/controllers/admin/standing_order_orders_controller.rb @@ -13,5 +13,17 @@ module Admin end end end + + def resume + if @standing_order_order.resume + respond_with(@standing_order_order) do |format| + format.json { render_as_json @standing_order_order } + end + else + respond_with(@standing_order_order) do |format| + format.json { render json: { errors: [t(:could_not_resume_the_order)] }, status: :unprocessable_entity } + end + end + end end end diff --git a/app/views/admin/standing_orders/_orders_panel.html.haml b/app/views/admin/standing_orders/_orders_panel.html.haml index d8dc3bc9db..520e8e7df7 100644 --- a/app/views/admin/standing_orders/_orders_panel.html.haml +++ b/app/views/admin/standing_orders/_orders_panel.html.haml @@ -24,4 +24,5 @@ %td.text-center{ ng: { bind: 'order.status' } } %td.text-center{ ng: { bind: 'order.total' } } %td.actions - %a.cancel-order.icon-remove.no-text{ href: 'javascript:void(0)', ng: { click: "cancelOrder(order)" }, 'ofn-with-tip' => t(:cancel_order) } + %a.cancel-order.icon-remove.no-text{ href: 'javascript:void(0)', ng: { hide: "order.status == 'cancelled'", click: "cancelOrder(order)" }, 'ofn-with-tip' => t(:cancel_order) } + %a.resume-order.icon-resume.no-text{ href: 'javascript:void(0)', ng: { show: "order.status == 'cancelled'", click: "resumeOrder(order)" }, 'ofn-with-tip' => t(:resume_order) } diff --git a/spec/features/admin/standing_orders_spec.rb b/spec/features/admin/standing_orders_spec.rb index 1daac42eaf..c9b7080660 100644 --- a/spec/features/admin/standing_orders_spec.rb +++ b/spec/features/admin/standing_orders_spec.rb @@ -79,7 +79,6 @@ feature 'Standing Orders' do within ".standing-order-orders" do expect(page).to have_selector "tr.standing_order_order", count: 1 - # Cancelling an order standing_order_order = standing_order.standing_order_orders.first within "tr#o_#{standing_order_order.id}" do expect(page).to_not have_content 'CANCELLED' @@ -88,6 +87,14 @@ feature 'Standing Orders' do end expect(page).to have_content 'CANCELLED' expect(standing_order_order.reload.cancelled_at).to be_within(5.seconds).of Time.now + + # Resuming an order + accept_alert 'Are you sure?' do + find("a.resume-order").trigger('click') + end + # Note: the order itself was not complete when 'cancelled', so state remained as cart + expect(page).to have_content 'CART' + expect(standing_order_order.reload.cancelled_at).to be nil end end end