Handle note saving with a new action on existing API controller

This commit is contained in:
Jean-Baptiste Bellet
2022-06-29 11:24:21 +02:00
parent 3f1099d968
commit 90af6bd22d
3 changed files with 31 additions and 2 deletions

View File

@@ -43,7 +43,7 @@ $(document).ready(function() {
$('a.edit-tracking').click(toggleTrackingEdit);
$('a.cancel-tracking').click(toggleTrackingEdit);
$('a.edit-note').click(toggleNoteEdit);
$('a.edit-note.icon-edit').click(toggleNoteEdit);
$('a.cancel-note').click(toggleNoteEdit);
handle_tracking_save = function(){
@@ -62,5 +62,23 @@ $(document).ready(function() {
console.log(msg);
});
}
handle_note_save = function(){
var link = $(this);
var note = link.parents('tbody').find('#note').val();
var url = Spree.url( Spree.routes.orders_api + "/" + order_number);
$.ajax({
type: "PUT",
url: url,
data: { note: note }
}).done(function( msg ) {
window.location.reload();
}).error(function( msg ) {
console.log(msg);
});
}
$('[data-hook=admin_order_edit_form] a.save-tracking').click(handle_tracking_save);
$('[data-hook=admin_order_edit_form] a.save-note').click(handle_note_save);
});

View File

@@ -26,6 +26,13 @@ module Api
}
end
def update
authorize! :admin, order
order.update!(order_params)
render json: order, serializer: Api::OrderDetailedSerializer, current_order: order
end
def ship
authorize! :admin, order
@@ -72,6 +79,10 @@ module Api
includes(line_items: { variant: [:product, :stock_items, :default_price] }).
first!
end
def order_params
params.permit(:note)
end
end
end
end

View File

@@ -18,7 +18,7 @@ Openfoodnetwork::Application.routes.draw do
resources :variants, :only => [:index]
resources :orders, only: [:index, :show] do
resources :orders, only: [:index, :show, :update] do
member do
put :capture
put :ship