From fc9a97fe3f48f8d01cac9e247dad63a33475a321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Thu, 23 Sep 2021 17:53:01 +0200 Subject: [PATCH 1/3] WIP remote change p_customer_sheet state --- .../admin/p_customer_sheets_controller.rb | 12 ++++++----- app/views/admin/buy_lists/index.html.haml | 21 +++++++++++++++++-- app/views/admin/buy_lists/index.js.erb | 2 ++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 app/views/admin/buy_lists/index.js.erb diff --git a/app/controllers/admin/p_customer_sheets_controller.rb b/app/controllers/admin/p_customer_sheets_controller.rb index fbc5058..8040166 100644 --- a/app/controllers/admin/p_customer_sheets_controller.rb +++ b/app/controllers/admin/p_customer_sheets_controller.rb @@ -196,10 +196,13 @@ class Admin::PCustomerSheetsController < ApplicationController if @p_customer_sheet.update_attributes(params.require(:p_customer_sheet).permit!) - @p_customer = @p_customer_sheet.price_line_block.p_customer - - - redirect_to admin_p_customer_sheet_path(@p_customer_sheet) + @p_customer = @p_customer_sheet.price_line_block.p_customer + if params[:no_redirect] == "true" + @price_line_id = params[:price_line_id] + render "admin/buy_lists/index" + else + redirect_to admin_p_customer_sheet_path(@p_customer_sheet) + end else render action: "edit" @@ -207,7 +210,6 @@ class Admin::PCustomerSheetsController < ApplicationController end - def destroy @p_customer_sheet = PCustomerSheet.find(params[:id]) @p_customer_sheet.destroy diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index de9fbbb..8999cff 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -216,7 +216,7 @@ %tbody.detail -ppr_lines.each do |price_line| - %tr + %tr{id: "price_line_row_#{price_line.id}"} - if checkbox %td =check_box_tag :"price_line_ids[]", price_line.id @@ -235,7 +235,23 @@ =link_to price_line.p_customer.show_name, [:admin, price_line.p_customer] %td - =state_helper price_line.price_line_block.price_lineable.state + -@p_customer_sheet = price_line.price_line_block.price_lineable + -if true + %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 + =f.input :state, collection: ["AV BPA", "PAS BPA","BPA", "Traitée"], as: :select, :include_blank => false, label: false, selected: f.object.state, input_html: {class: "custom-select"}, remote: true + =hidden_field_tag :no_redirect, "true" + =hidden_field_tag :price_line_id, price_line.id + =f.button ic(:check), type: :submit, class: "btn btn-primary ml-1" + -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| + =f.select :state, ["AV BPA", "PAS BPA","BPA", "Traitée"] + =f.submit + =#state_helper price_line.price_line_block.price_lineable.state %td =price_line.comment @@ -364,6 +380,7 @@ checkbox.prop("checked", false) } }) + $('.plus-all').click() diff --git a/app/views/admin/buy_lists/index.js.erb b/app/views/admin/buy_lists/index.js.erb new file mode 100644 index 0000000..9eef406 --- /dev/null +++ b/app/views/admin/buy_lists/index.js.erb @@ -0,0 +1,2 @@ +console.log('coucou') +$('#price_line_row_<%= @price_line_id %>').replaceWith("<%= escape_javascript(render(@p_customer_sheet))%>"); 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 2/3] 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))%>"); From a7b4ec4c1939a787d3cd32142bf6e0746db071f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Fri, 15 Oct 2021 10:03:31 +0200 Subject: [PATCH 3/3] Dropdown ok --- .../admin/p_customer_sheets_controller.rb | 9 ++---- app/models/p_customer_sheet.rb | 3 +- app/views/admin/buy_lists/index.html.haml | 32 ++++++++----------- app/views/admin/buy_lists/update.js.erb | 2 -- .../admin/p_customer_sheets/update.js.erb | 6 ++-- 5 files changed, 22 insertions(+), 30 deletions(-) delete mode 100644 app/views/admin/buy_lists/update.js.erb diff --git a/app/controllers/admin/p_customer_sheets_controller.rb b/app/controllers/admin/p_customer_sheets_controller.rb index 8040166..8905ef1 100644 --- a/app/controllers/admin/p_customer_sheets_controller.rb +++ b/app/controllers/admin/p_customer_sheets_controller.rb @@ -192,16 +192,13 @@ class Admin::PCustomerSheetsController < ApplicationController def update @p_customer_sheet = PCustomerSheet.find(params[:id]) - if @p_customer_sheet.update_attributes(params.require(:p_customer_sheet).permit!) @p_customer = @p_customer_sheet.price_line_block.p_customer - if params[:no_redirect] == "true" - @price_line_id = params[:price_line_id] - render "admin/buy_lists/index" - else - redirect_to admin_p_customer_sheet_path(@p_customer_sheet) + respond_to do |format| + format.html{redirect_to admin_p_customer_sheet_path(@p_customer_sheet)} + format.js{} end else render action: "edit" diff --git a/app/models/p_customer_sheet.rb b/app/models/p_customer_sheet.rb index 158e723..3d98974 100644 --- a/app/models/p_customer_sheet.rb +++ b/app/models/p_customer_sheet.rb @@ -44,6 +44,8 @@ class PCustomerSheet < ApplicationRecord :actions => {:name => "Actions", :reorder => false}, } + # STATES = ["brouillon", "offre", "commande", "livrée","facturée", "annulée", "refusée"] + STATES = ["AV BPA", "PAS BPA","BPA", "Traitée"] def personalised_archive @@ -328,7 +330,6 @@ class PCustomerSheet < ApplicationRecord end - STATES = ["brouillon", "offre", "commande", "livrée","facturée", "annulée", "refusée"] def unblock_price diff --git a/app/views/admin/buy_lists/index.html.haml b/app/views/admin/buy_lists/index.html.haml index 36b8236..f561056 100644 --- a/app/views/admin/buy_lists/index.html.haml +++ b/app/views/admin/buy_lists/index.html.haml @@ -236,25 +236,19 @@ %td -@p_customer_sheet = price_line.price_line_block.price_lineable - -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 - =f.input :state, collection: ["AV BPA", "PAS BPA","BPA", "Traitée"], as: :select, :include_blank => false, label: false, selected: f.object.state, input_html: {class: "custom-select"}, remote: true - =hidden_field_tag :no_redirect, "true" - =hidden_field_tag :price_line_id, price_line.id - =f.button ic(:check), type: :submit, class: "btn btn-primary ml-1" - -if false - =f.actions class: "btn btn-primary ml-1" do - =f.action :submit, label: "#{ic(:check).html_safe}" - -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 for: "p_customer_sheet_state_#{@p_customer_sheet.id}" - =#state_helper price_line.price_line_block.price_lineable.state + .dropdown + %button.btn.btn-default.dropdown-toggle{"aria-expanded" => "true", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"} + %span.span_cat{'class' => "p_customer_sheet_#{@p_customer_sheet.id}"} + =#@p_customer_sheet.state + =state_helper @p_customer_sheet.state + %span.caret + %ul.dropdown-menu{"aria-labelledby" => "dropdownMenu1"} + -PCustomerSheet::STATES.each do |state| + %li + =link_to admin_p_customer_sheet_path(:id => @p_customer_sheet.id, :p_customer_sheet => {:state => state}), :method => :put, :remote => true, :onclick => "$('.dropdown-toggle').dropdown('hide');$(\".p_customer_sheet_#{@p_customer_sheet.id}\").html($(this).find('span').html());", :class => "dropdown-item" do + =ic :check if false + %span=state_helper state + %td =price_line.comment diff --git a/app/views/admin/buy_lists/update.js.erb b/app/views/admin/buy_lists/update.js.erb deleted file mode 100644 index 85ca3d0..0000000 --- a/app/views/admin/buy_lists/update.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -console.log('coucou'); -$('#price_line_row_<%= @price_line_id %>').replaceWith("<%= escape_javascript(render(@p_customer_sheet))%>"); diff --git a/app/views/admin/p_customer_sheets/update.js.erb b/app/views/admin/p_customer_sheets/update.js.erb index 1d96e9f..572c4eb 100644 --- a/app/views/admin/p_customer_sheets/update.js.erb +++ b/app/views/admin/p_customer_sheets/update.js.erb @@ -1,2 +1,4 @@ -$('#p_customer_sheets_rows').html("<%= escape_javascript(render(@p_customer_sheets))%>"); -close_pane_hover(); \ No newline at end of file +<% if @p_customer_sheets %> + $('#p_customer_sheets_rows').html("<%= escape_javascript(render(@p_customer_sheets))%>"); +<% end %> +close_pane_hover();