- affichage coupons de réduction

- imports coupons de réduction
This commit is contained in:
Nicolas Bally 2020-07-30 13:10:05 +02:00
parent 1e6f2edf98
commit 364681bf5d
16 changed files with 173 additions and 4 deletions

View File

@ -43,7 +43,7 @@ class Admin::ImportCsvsController < ApplicationController
end
def new
@import_csv = ImportCsv.new(:parent_id => params[:parent_id], :m_odr_id => params[:m_odr_id])
@import_csv = ImportCsv.new(:parent_id => params[:parent_id], :m_odr_id => params[:m_odr_id], :table_name => params[:table_name] )
if @import_csv.parent
@import_csv.name = @import_csv.parent.name
@import_csv.table_name = @import_csv.parent.table_name

View File

@ -0,0 +1,65 @@
# -*- encoding : utf-8 -*-
class Admin::MOdrCouponsController < ApplicationController
layout "admin"
before_action :auth_admin
before_action :admin_space
def admin_space
@admin_space = "default"
end
def index
@m_odr_coupons = MOdrCoupon.order(:name).all
end
def show
@m_odr_coupon = MOdrCoupon.find(params[:id])
end
def new
@m_odr_coupon = MOdrCoupon.new(:m_odr_id => params[:m_odr_id])
end
def edit
@m_odr_coupon = MOdrCoupon.find(params[:id])
end
def create
@m_odr_coupon = MOdrCoupon.new(params.require(:m_odr_coupon).permit!)
if @m_odr_coupon.save
else
render action: "new"
end
end
def update
@m_odr_coupon = MOdrCoupon.find(params[:id])
if @m_odr_coupon.update_attributes(params.require(:m_odr_coupon).permit!)
else
render action: "edit"
end
end
def destroy
@m_odr_coupon = MOdrCoupon.find(params[:id])
@m_odr_coupon.destroy
end
end

View File

@ -1,3 +1,11 @@
class MOdrCoupon < ApplicationRecord
belongs_to :m_odr
validates :name, :presence => true
acts_as_sorting :fields => {
:name => {:name => "Nom", :reorder => true},
:actions => "Actions"
}
acts_as_csv_import :fields => [:name]
end

View File

@ -1,6 +1,7 @@
class MOdrPlace < ApplicationRecord
belongs_to :m_odr
validates :name, :presence => true
acts_as_sorting :fields => {
:name => {:name => "Nom", :reorder => true},

View File

@ -9,7 +9,7 @@
= f.input :name, :label => "Nom de l'import :"
= f.input :file, :label => "file :"
= f.input :table_name, :label => "Table :" , :as => :select, :collection => ["m_odr_places"]
= f.input :table_name, :label => "Table :" , :as => :select, :collection => [["Revendeurs", "m_odr_places"], ["Bons de réduction", "m_odr_coupons"]]
-if f.object.id
%table.import_csv_champs_form

View File

@ -0,0 +1,6 @@
=semantic_form_for [:admin, @m_odr_coupon], :remote => true do |form|
.content
=form.hidden_field :m_odr_id
= form.input :name, :label => "N° de coupon :"
.actions=form.submit "sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,14 @@
%tr#m_odr_coupon_row{:id => m_odr_coupon.id}
-tr = {}
-tr[:actions] = capture do
%td.actions
= link_to i(:"trash-o"), [:admin, m_odr_coupon], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
= link_to i(:pencil), edit_admin_m_odr_coupon_path(m_odr_coupon), :remote => true
=render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => m_odr_coupon}

View File

@ -0,0 +1,2 @@
$('#m_odr_coupons_rows').prepend("<%= escape_javascript(render(@m_odr_coupon))%>");
close_pane_hover();

View File

@ -0,0 +1 @@
$('#m_odr_coupon_row_<%= @m_odr_coupon.id %>').remove();

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,29 @@
.qi_header
.right= link_to 'Ajouter ', new_admin_m_odr_coupon_path(), :class => "btn btn-primary", :remote => true
%h1
%span
.qi_row
.qi_pannel.qi_plain.padding
%table.table
%tr
%th name
%th enseigne
%th city
%th cp
%th departement
%th departement_nbr
%th responsable
%th tel
%th email
%th m_odr_id
%th.actions
%tbody#m_odr_coupons_rows
=render @m_odr_coupons

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);

View File

@ -0,0 +1,10 @@
.qi_header
%h1
%span
.qi_row
.qi_pannel.qi_plain.padding
=debug @m_odr_coupon

View File

@ -0,0 +1,2 @@
$('#m_odr_coupon_row_<%= @m_odr_coupon.id %>').replaceWith("<%= escape_javascript(render(@m_odr_coupon))%>");
close_pane_hover();

View File

@ -44,7 +44,7 @@
=#%li{:class => ("active" if params[:tab] == "mail_hists")}=link_to "Historique des mails envoyés", "?tab=mail_hists"
- tabs = [["m_odr_file_types", "Fichiers demandés"],["m_odr_brands", "Marques concernées"],["m_odr_product_cats", "Catégories produit"],["m_odr_products", "Produits"],["m_odr_places", "Revendeurs"],["m_odr_trackers", "Trackers"],["mail_types", "Mails"],["mail_type_cats", "Catégories mails"],["import_csvs", "Imports CSV"]]
- tabs = [["m_odr_file_types", "Fichiers demandés"],["m_odr_brands", "Marques concernées"],["m_odr_product_cats", "Catégories produit"],["m_odr_products", "Produits"],["m_odr_places", "Revendeurs"],["m_odr_coupons", "Bons de réduction"],["m_odr_trackers", "Trackers"],["mail_types", "Mails"],["mail_type_cats", "Catégories mails"],["import_csvs", "Imports CSV"]]
- tabs.each do |tab|
%li{:class => ("active" if params[:tab] == tab[0])}=link_to tab[1], "?tab=#{tab[0]}"
@ -122,12 +122,30 @@
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @m_odr_products}
-if params[:tab] == "m_odr_coupons"
#offres
.qi_tab_header
.right{:style => "text-align:right;"}
= link_to 'Importer un fichier CSV', new_admin_import_csv_path(:m_odr_id => @m_odr.id, :table_name => "m_odr_coupons"), :class => "btn btn-primary", :remote => true
= link_to 'Ajouter', new_admin_m_odr_coupon_path(:m_odr_id => @m_odr.id), :class => "btn btn-primary", :remote => true
.clear
-params[:search][:per_page] = params[:search][:per_page] || 50
-per_page = params[:search][:per_page]
-page = (params[:page] and params[:page] != "") ? params[:page] : 1
-@m_odr_coupons =@m_odr.m_odr_coupons
-@m_odr_coupons = sort_by_sorting(@m_odr_coupons, "created_at DESC")
-@m_odr_coupons = @m_odr_coupons.page(page).per(per_page)
=render :partial => "qi/qi_ordered_table", :locals => {:qi_ordered_table_collection => @m_odr_coupons}
-if params[:tab] == "m_odr_places"
#offres
.qi_tab_header
.right{:style => "text-align:right;"}
= link_to 'Importer un fichier CSV', new_admin_import_csv_path(:m_odr_id => @m_odr.id), :class => "btn btn-primary", :remote => true
= link_to 'Importer un fichier CSV', new_admin_import_csv_path(:m_odr_id => @m_odr.id, :table_name => "m_odr_places"), :class => "btn btn-primary", :remote => true
= link_to 'Ajouter', new_admin_m_odr_place_path(:m_odr_id => @m_odr.id), :class => "btn btn-primary", :remote => true
.clear
-params[:search][:per_page] = params[:search][:per_page] || 50

View File

@ -4,6 +4,17 @@ Rails.application.routes.draw do
namespace :admin do
resources :m_odr_coupons do
member do
end
collection do
end
end
resources :import_csv_champs do
member do