mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Make simple create redirect to OC list but normal create to jump to incoming settings
This commit is contained in:
@@ -150,7 +150,10 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, S
|
||||
create: (destination) ->
|
||||
oc = new OrderCycleResource({order_cycle: this.dataForSubmit()})
|
||||
oc.$create (data) ->
|
||||
$window.location = destination
|
||||
if destination? && destination.length != 0
|
||||
$window.location = destination
|
||||
else if data.edit_path?
|
||||
$window.location = data.edit_path
|
||||
, (response) ->
|
||||
if response.data.errors?
|
||||
StatusMessage.display('failure', response.data.errors[0])
|
||||
|
||||
@@ -43,7 +43,7 @@ module Admin
|
||||
|
||||
if @order_cycle_form.save
|
||||
flash[:notice] = I18n.t(:order_cycles_create_notice)
|
||||
render json: { success: true }
|
||||
render json: { success: true, edit_path: main_app.admin_order_cycle_incoming_path(@order_cycle) }
|
||||
else
|
||||
render json: { errors: @order_cycle.errors.full_messages }, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f|
|
||||
|
||||
%save-bar{ dirty: "order_cycle_form.$dirty", persist: "true" }
|
||||
%input.red{ type: "button", value: t('.create'), ng: { click: "submit($event, '#{main_app.admin_order_cycles_path}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
- if order_cycles_simple_form
|
||||
- custom_redirect_path = main_app.admin_order_cycles_path
|
||||
%input.red{ type: "button", value: t('.create'), ng: { click: "submit($event, '#{custom_redirect_path}')", disabled: "!order_cycle_form.$dirty || order_cycle_form.$invalid" } }
|
||||
%input{ type: "button", ng: { value: "order_cycle_form.$dirty ? '#{t('.cancel')}' : '#{t('.back_to_list')}'", click: "cancel('#{main_app.admin_order_cycles_path}')" } }
|
||||
|
||||
- if order_cycles_simple_form
|
||||
|
||||
@@ -111,10 +111,20 @@ module Admin
|
||||
context "when creation is successful" do
|
||||
before { allow(form_mock).to receive(:save) { true } }
|
||||
|
||||
it "returns success: true" do
|
||||
# mock build_resource so that we can control the edit_path
|
||||
OrderCyclesController.class_eval do
|
||||
def build_resource
|
||||
order_cycle = OrderCycle.new
|
||||
order_cycle.id = 1
|
||||
order_cycle
|
||||
end
|
||||
end
|
||||
|
||||
it "returns success: true and a valid edit path" do
|
||||
spree_post :create, params
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['success']).to be true
|
||||
expect(json_response['edit_path']).to eq "/admin/order_cycles/1/incoming"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -348,17 +348,28 @@ describe 'OrderCycle service', ->
|
||||
beforeEach ->
|
||||
spyOn(OrderCycle, 'confirmNoDistributors').and.returnValue true
|
||||
|
||||
it 'redirects to the destination page on success', ->
|
||||
it 'redirects to the given destination on success', ->
|
||||
OrderCycle.order_cycle = 'this is the order cycle'
|
||||
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
|
||||
$httpBackend.expectPOST('/admin/order_cycles.json', {
|
||||
order_cycle: 'this is the submit data'
|
||||
}).respond {success: true}
|
||||
}).respond {success: true, edit_path: "/edit/path"}
|
||||
|
||||
OrderCycle.create('/destination/page')
|
||||
$httpBackend.flush()
|
||||
expect($window.location).toEqual('/destination/page')
|
||||
|
||||
it 'redirects to the edit_path on success if no destination is given', ->
|
||||
OrderCycle.order_cycle = 'this is the order cycle'
|
||||
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
|
||||
$httpBackend.expectPOST('/admin/order_cycles.json', {
|
||||
order_cycle: 'this is the submit data'
|
||||
}).respond {success: true, edit_path: "/edit/path"}
|
||||
|
||||
OrderCycle.create()
|
||||
$httpBackend.flush()
|
||||
expect($window.location).toEqual('/edit/path')
|
||||
|
||||
it 'does not redirect on error', ->
|
||||
OrderCycle.order_cycle = 'this is the order cycle'
|
||||
spyOn(OrderCycle, 'dataForSubmit').and.returnValue('this is the submit data')
|
||||
|
||||
Reference in New Issue
Block a user