diff --git a/app/controllers/admin/import_csvs_controller.rb b/app/controllers/admin/import_csvs_controller.rb index 9f70258..9d3ebb1 100644 --- a/app/controllers/admin/import_csvs_controller.rb +++ b/app/controllers/admin/import_csvs_controller.rb @@ -92,4 +92,21 @@ class Admin::ImportCsvsController < ApplicationController @import_csv.destroy end + + def temp_p_product + dev_mode = false + if dev_mode + @p_product_ref = PProductRef.last #DEV mode only + @price_line = PriceLine.find(params[:price_line_id]) + + @p_product_ref.ct_price_ht = @price_line.ct_u_price_ht #DEV ode onmy + @p_product_ref.p_product_ref_specs.build + else + if params[:price_line_id] + @price_line = PriceLine.find(params[:price_line_id]) + @p_product_ref = PProductRef.find_or_create_by(p_product: PProduct.find_by(name: "--> Selectioner un produit <--"), ct_sub_name: @price_line.title, ct_price_ht: @price_line.ct_u_price_ht) + @p_product_ref.p_product_ref_specs.build + end + end + end end diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index 736d823..2ff7f98 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -1,6 +1,8 @@ # -*- encoding : utf-8 -*- class Admin::PProductRefsController < ApplicationController + include ActionView::RecordIdentifier # adds `dom_id` + layout "admin" before_action :auth_admin @@ -102,12 +104,14 @@ class Admin::PProductRefsController < ApplicationController def update + @p_product_ref = PProductRef.find(params[:id]) - - if @p_product_ref.update_attributes(params.require(:p_product_ref).permit!) - - + if params[:update_price_line_id] + @price_line = PriceLine.find(params[:update_price_line_id]) + @price_line.update(p_product_ref: @p_product_ref) + end + # redirect_to admin_p_products_path(@p_product_ref.p_product, anchor: dom_id(@p_product_ref)) else render action: "edit" diff --git a/app/controllers/admin/p_products_controller.rb b/app/controllers/admin/p_products_controller.rb index 2ded2ca..aef9a1a 100644 --- a/app/controllers/admin/p_products_controller.rb +++ b/app/controllers/admin/p_products_controller.rb @@ -72,9 +72,9 @@ class Admin::PProductsController < ApplicationController @p_product = PProduct.new #(:p_customer_cat_ids => [3]) - @p_product.name = params[:p_fournisseur_ref_label] if params[:p_fournisseur_ref_label] # @p_product.p_product_refs << PProductRef.new - @p_product_refs = @p_product.p_product_refs.build + fournisseur_label = params[:fournisseur_label] if params[:fournisseur_label] + @p_product_refs = @p_product.p_product_refs.build(ct_sub_name: fournisseur_label) @p_product_ref_specs = @p_product_refs.p_product_ref_specs.build @p_spec_type = @p_product_ref_specs.build_p_spec_type @p_spec_value = @p_product_ref_specs.build_p_spec_value diff --git a/app/models/p_product.rb b/app/models/p_product.rb index 893a83c..ef6cdc6 100644 --- a/app/models/p_product.rb +++ b/app/models/p_product.rb @@ -33,9 +33,8 @@ class PProduct < ApplicationRecord belongs_to :p_product_cat belongs_to :s_brand - validates :name, :presence => true - validates :code, :presence => true, :uniqueness => true - + validates :name, :presence => true, exclusion: { in: ["--> Selectioner un produit <--"], message: "Selectioner un produit avant de valider" } + validates :code, :presence => true, :uniqueness => true, exclusion: { in: ["--> Indiquer un code produit <--"], message: "Indiquer un code produit avant de valider" } has_many :tvable_tva_rates, :as => :tvable has_many :tva_rates, :through => :tvable_tva_rates diff --git a/app/models/p_product_ref.rb b/app/models/p_product_ref.rb index 4b9d5a3..d11adc1 100644 --- a/app/models/p_product_ref.rb +++ b/app/models/p_product_ref.rb @@ -15,7 +15,7 @@ class PProductRef < ApplicationRecord accepts_nested_attributes_for :p_article_serial_nums, allow_destroy: true has_many :p_product_ref_specs - accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true + accepts_nested_attributes_for :p_product_ref_specs, allow_destroy: true, reject_if: :all_blank #validates :ct_price_ht, :presence => true validate :ean, :is_integer @@ -88,7 +88,8 @@ class PProductRef < ApplicationRecord self.p_product.p_product_cat_id end - QI_DYNAMICS = %w(name code p_product_cat_id sub_cat_names cat_name) + # QI_DYNAMICS = %w(name code p_product_cat_id sub_cat_names cat_name) + QI_DYNAMICS = %w(name code p_product_cat_id cat_name) #sub_cat_names removed eval(QI_DYNAMICS_CORE) diff --git a/app/models/p_product_ref_spec.rb b/app/models/p_product_ref_spec.rb index a036951..e15b3f1 100644 --- a/app/models/p_product_ref_spec.rb +++ b/app/models/p_product_ref_spec.rb @@ -5,6 +5,8 @@ class PProductRefSpec < ApplicationRecord accepts_nested_attributes_for :p_spec_type, :p_spec_value + validates :p_spec_type_id, :p_spec_value_id, presence: true + acts_as_sorting :fields => { :id => {:name => "ID"}, :p_product_ref => {:name => "Référence produit", :reorder => true}, diff --git a/app/views/admin/import_csvs/_form_temp_p_product.html.haml b/app/views/admin/import_csvs/_form_temp_p_product.html.haml new file mode 100644 index 0000000..afa6595 --- /dev/null +++ b/app/views/admin/import_csvs/_form_temp_p_product.html.haml @@ -0,0 +1,89 @@ +=semantic_form_for [:admin, @p_product_ref], remote: true do |form| + =hidden_field_tag :update_price_line_id, @price_line.id + .content + .qi_row.field + .padding + + %h1 Ajouter une références + %table.form-table + %tr + %td{colspan: 3} + %label Selectionner le produit parent + .input-group + %input.p_product_autocomplete_input.form-control{:type => "text", :style => "", tabindex: 1, autofocus: true, :class => "p_product_name"} + =form.hidden_field :p_product_id, :class => "p_product_id" + + =link_to ic(:plus)+ " Ajouter produit", new_admin_p_product_path(fournisseur_label: @p_product_ref.ct_sub_name) + + %tr + %td{:colspan => 3} + %input.form-control{type: "text", placeholder: @p_product_ref.ct_sub_name, "aria-label" => "Disabled input example", disabled: true} + =#form.input :ct_sub_name, label: "Label fournisseur", input_html: {disabled: true} + + %tr + %td{:colspan => 3} + = form.input :ct_sub_name, :label => "Désignation ARCOM :" + %tr + %td + = form.input :ref, :label => "Réf int. :" + + %td + = form.input :ct_price_ht, :label => "Prix vente HT :" + + %td + =form.input :p_product_color_id, :label => "Couleur :", :collection => PProductColor.all, :as => :select, :include_blank => true, input_html: {class: "custom-select"} + %tr + %td + =form.input :ct_sorecop, :label => "Sorecop personalisée :" + %td + =form.input :sorecop_comment, :label => "Type de Sorecop :" + %td + =form.input :ct_deee, :label => "DEEE personalisée :" + %tr + %td + =form.input :ean + + %td{:colspan => 2} + = form.input :description, :label => "Désignation longue :" , :input_html => {rows: 1} + + %tr + %td{:colspan => 3} + .qi_pannel.qi_plain.padding + .p_product_ref_specs_form + = form.semantic_fields_for :p_product_ref_specs do |f| + =render :partial => "admin/p_product_ref_specs/form", :locals => {:form => f} + %p= link_to_add_fields "Ajouter une spec", form, :p_product_ref_specs + + .actions=form.submit "sauvegarder", :class => "btn btn-primary" + + + +:javascript + $('.p_product_autocomplete_input').focus() + $( function() { + $('.p_product_autocomplete_input').autocomplete({ + source: function( request, response ) { + $.ajax( { + url: "/admin/p_products/autocomplete.json", + dataType: "json", + data: { + search: request.term, + }, + success: function(data){ + arr = jQuery.map( data, function( item ) { + return { + label: item.name, + value: item.name, + id: item.id + } + }); + response(arr) + } + }); + }, + minLength: 2, + select: function( event, ui ) { + $(this).next(".p_product_id").val(ui.item.id) + } + }); + }); diff --git a/app/views/admin/import_csvs/temp_p_product.js.erb b/app/views/admin/import_csvs/temp_p_product.js.erb new file mode 100644 index 0000000..0562b62 --- /dev/null +++ b/app/views/admin/import_csvs/temp_p_product.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form_temp_p_product"))%>",700,900); diff --git a/app/views/admin/p_product_ref_specs/_form.html.haml b/app/views/admin/p_product_ref_specs/_form.html.haml index ffde9d3..d369fed 100644 --- a/app/views/admin/p_product_ref_specs/_form.html.haml +++ b/app/views/admin/p_product_ref_specs/_form.html.haml @@ -15,15 +15,15 @@ %table %tr %td - %h4 spec : - + %h4 Specs : + %tr %td -#form.object.p_spec_type = PSpecType.new if !form.object.p_spec_type -#form.object.p_spec_value = PSpecValue.new if !form.object.p_spec_value - = form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType.all, :include_blank => false + = form.input :p_spec_type_id, :label => "Type", as: :select, collection: PSpecType.all, :include_blank => true,input_html: {class: "custom-select"} %td - = form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => false, :member_label => :member_label + = form.input :p_spec_value_id, :label => "Valeur", as: :select, collection: PSpecValue.all, :include_blank => true, :member_label => :member_label, input_html: {class: "custom-select"} =#form.inputs do diff --git a/app/views/admin/p_product_refs/update.js.erb b/app/views/admin/p_product_refs/update.js.erb index 49eb092..8b84b1e 100644 --- a/app/views/admin/p_product_refs/update.js.erb +++ b/app/views/admin/p_product_refs/update.js.erb @@ -1,2 +1,8 @@ $('#p_product_ref_row_<%= @p_product_ref.id %>').replaceWith("<%= escape_javascript(render(@p_product_ref))%>"); -close_pane_hover(); \ No newline at end of file + +if ($('#<%= dom_id(@price_line) %>').parents('.qi_pannel.qi_plain').find('tbody').find('tr').length === 1) { + $('#<%= dom_id(@price_line) %>').parents('.qi_pannel.qi_plain').remove() +} +$('#<%= dom_id(@price_line) %>').remove(); + +close_pane_hover(); diff --git a/app/views/admin/price_lines/_form_match_refs.html.haml b/app/views/admin/price_lines/_form_match_refs.html.haml index a8c2482..fb4fc62 100644 --- a/app/views/admin/price_lines/_form_match_refs.html.haml +++ b/app/views/admin/price_lines/_form_match_refs.html.haml @@ -1,4 +1,4 @@ -%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;"} +%tr.qi_pannel.qi_plain.padding.price_line_form.col-12.field{:style =>"border-left:4px solid gray;margin-bottom:10px;padding-left:5px;", id: dom_id(form.object)} %td{:style => "width: 30px;", :class => ("error has-error" if form.object.errors[:p_product_ref_id].size > 0 )} @@ -21,7 +21,7 @@ %td.text-center{style: "width: 80px;"} - %span=link_to ic(:"plus"), new_admin_p_product_path(p_fournisseur_ref_label: form.object.title) + %span=link_to ic(:"plus"), temp_p_product_admin_import_csvs_path(price_line_id: form.object.id), remote: true diff --git a/config/routes.rb b/config/routes.rb index 6b62c9c..59be0a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -458,6 +458,7 @@ Rails.application.routes.draw do resources :import_csvs do collection do get :match_refs + get :temp_p_product end member do get :charge