diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml index 2059688..07b10c7 100644 --- a/app/views/admin/price_documents/show.html.haml +++ b/app/views/admin/price_documents/show.html.haml @@ -320,7 +320,7 @@ -if @price_document.label == "Demande prix" - %h3 Réponses fournisseur + %h3.ml-2 Réponses fournisseur #bills -params[:search][:per_page] = params[:search][:per_page] || 5000 -per_page = params[:search][:per_page] @@ -341,7 +341,7 @@ =render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @price_documents, :key => "reponses-prix-show"} - %h3 Consultations fournisseur + %h3.ml-2 Consultations fournisseur #consult -params[:search][:per_page] = params[:search][:per_page] || 5000 -per_page = params[:search][:per_page] @@ -370,25 +370,55 @@ -@price_documents.each do |price_document_consult| - =link_to ic(:clipboard) + " test clipboard TODO", "#", class: "right btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' - %h4= price_document_consult.p_fournisseur.name + %h4.ml-2= price_document_consult.p_fournisseur.name = semantic_form_for [:admin, price_document_consult], :html => {:class => "qi_price_form"}, :remote => false do |form| - = form.button ic(:clipboard) + "Valider modifications (TODO +copier la consultation)", type: :submit, class: "btn btn-primary m-2" + = form.button "Valider modifications)", type: :submit, class: "btn btn-primary m-2" + =link_to ic(:clipboard) + " Copier le text", "#", class: "btn btn-primary", "data-document" => price_document_consult.id, onclick: 'copyPriceLines(event)' .price-lines{"data-document" => price_document_consult.id} =form.semantic_fields_for :price_line_block do |f| - =f.semantic_fields_for :price_lines do |form| - =render partial: "admin/price_lines/form_consult", locals: {form: form} + .mx-2 + =f.semantic_fields_for :price_lines do |form| + =render partial: "admin/price_lines/form_consult", locals: {form: form} + + + + + :javascript const copyPriceLines = (event) => { event.preventDefault() - console.log(event.target.dataset.document) - let result = $('div[data-document=38]') - copy(result) - } - const copy = (element) => { - element.select() - document.execCommand("copy") + let priceDocumentId = event.target.dataset.document + let names = $(`.p_product_ref_cc_name_${priceDocumentId}`) + let qtes = $(`.input_price_line_qte_${priceDocumentId}`) + let prices = $(`.price_line_price_u_ht_${priceDocumentId}`) + + let table = [] + names.each(function( i ) { + let row = [] + row.push(qtes[i].valueAsNumber) + row.push(" X ") + row.push(names[i].innerText) + row.push(" @ ") + row.push(prices[i].innerText) + table.push(row.join(' ')) + }) + copyStringToClipboard(table.join('\r\n')) } - + function copyStringToClipboard (str) { + // Create new element + var el = document.createElement('textarea'); + // Set value (string to be copied) + el.value = str; + // Set non-editable to avoid focus and move outside of view + el.setAttribute('readonly', ''); + el.style = {position: 'absolute', left: '-9999px'}; + document.body.appendChild(el); + // Select text inside element + el.select(); + // Copy text to clipboard + document.execCommand('copy'); + // Remove temporary element + document.body.removeChild(el); + } diff --git a/app/views/admin/price_lines/_form_consult.html.haml b/app/views/admin/price_lines/_form_consult.html.haml index 61f9872..64841df 100644 --- a/app/views/admin/price_lines/_form_consult.html.haml +++ b/app/views/admin/price_lines/_form_consult.html.haml @@ -1,20 +1,23 @@ - price_line = form.object .qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} .row - .col-1 - .take.mr-1 + .col-6.d-flex + .take.mr-4 =ic :arrows - .col-6 - Produit : - =price_line.p_product_ref.cc_name + .mr-1 + ref : + %div{class: "p_product_ref_cc_name_#{price_line.price_line_block.price_lineable_id}"} + =price_line.p_product_ref.cc_name - .col-2 + + .col-3.d-flex Base de prix U HT : - = price_line.price_u_ht - € + %div{class: "mx-1 price_line_price_u_ht_#{price_line.price_line_block.price_lineable_id}"} + = price_line.price_u_ht + € .col-3 .form-inline - = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte form-control mx-2", tabindex: 1} + = form.input :qte, :label => "qte :", :input_html => {:class => "input_price_line_qte_#{price_line.price_line_block.price_lineable_id} form-control mx-2", tabindex: 1} %span.destroy=link_to_remove_fields ic(:"trash-o"), form = form.hidden_field :p_product_ref_id, :class => "p_product_ref_id"