From 0199f0e520d555aa5aaa7a8d808f00e04c63caa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 24 Sep 2021 18:55:00 +0200 Subject: [PATCH] WIP doesn't work.... --- app/controllers/admin/buy_lists_controller.rb | 13 ++++++------- app/views/admin/buy_lists/index.html.haml | 11 +++++++---- .../admin/buy_lists/{index.js.erb => update.js.erb} | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) rename app/views/admin/buy_lists/{index.js.erb => update.js.erb} (82%) diff --git a/app/controllers/admin/buy_lists_controller.rb b/app/controllers/admin/buy_lists_controller.rb index 0fb842d..277832a 100644 --- a/app/controllers/admin/buy_lists_controller.rb +++ b/app/controllers/admin/buy_lists_controller.rb @@ -149,12 +149,13 @@ class Admin::BuyListsController < ApplicationController @p_customer_sheet = PCustomerSheet.find(params[:id]) @p_customer = @p_customer_sheet.p_customer - - if @p_customer_sheet.update_attributes(params.require(:p_customer_sheet).permit!) + @price_line_id = params[:price_line_id] + + if @p_customer_sheet.update(state: params[:state]) - @p_customer_sheets = PCustomerSheet.order(:id).all - - redirect_to admin_p_customer_sheet_path(@p_customer_sheet) + @p_customer_sheets = PCustomerSheet.where(:state => ["AV BPA", "PAS BPA", "BPA"]) + return @p_customer_sheet + # redirect_to admin_p_customer_sheet_path(@p_customer_sheet) else render action: "edit" @@ -235,6 +236,4 @@ class Admin::BuyListsController < ApplicationController end - - end diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index 8999cff..36b8236 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -236,7 +236,8 @@ %td -@p_customer_sheet = price_line.price_line_block.price_lineable - -if true + -form = false + -if form %form =semantic_form_for [:admin, @p_customer_sheet], remote: true, authenticity_token: true do |f| =f.inputs class: "form-inline d-flex flex-nowrap" do @@ -247,10 +248,12 @@ -if false =f.actions class: "btn btn-primary ml-1" do =f.action :submit, label: "#{ic(:check).html_safe}" - -if false - =form_with url: update_state_admin_p_customer_sheet_path(@p_customer_sheet), method: :get do |f| + -if !form + %form + =form_with url: admin_buy_list_path(@p_customer_sheet), method: :patch, remote: true, authenticity_token: true, id: "p_customer_sheet_state_#{@p_customer_sheet.id}" do |f| + =hidden_field_tag :price_line_id, price_line.id =f.select :state, ["AV BPA", "PAS BPA","BPA", "Traitée"] - =f.submit + =f.submit for: "p_customer_sheet_state_#{@p_customer_sheet.id}" =#state_helper price_line.price_line_block.price_lineable.state %td diff --git a/app/views/admin/buy_lists/index.js.erb b/app/views/admin/buy_lists/update.js.erb similarity index 82% rename from app/views/admin/buy_lists/index.js.erb rename to app/views/admin/buy_lists/update.js.erb index 9eef406..85ca3d0 100644 --- a/app/views/admin/buy_lists/index.js.erb +++ b/app/views/admin/buy_lists/update.js.erb @@ -1,2 +1,2 @@ -console.log('coucou') +console.log('coucou'); $('#price_line_row_<%= @price_line_id %>').replaceWith("<%= escape_javascript(render(@p_customer_sheet))%>");