diff --git a/app/controllers/admin/import_csvs_controller.rb b/app/controllers/admin/import_csvs_controller.rb index c92eba3..4b3a253 100644 --- a/app/controllers/admin/import_csvs_controller.rb +++ b/app/controllers/admin/import_csvs_controller.rb @@ -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 diff --git a/app/controllers/admin/m_odr_coupons_controller.rb b/app/controllers/admin/m_odr_coupons_controller.rb new file mode 100644 index 0000000..2eee419 --- /dev/null +++ b/app/controllers/admin/m_odr_coupons_controller.rb @@ -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 diff --git a/app/models/m_odr_coupon.rb b/app/models/m_odr_coupon.rb index 07a8c34..bf8fb5c 100644 --- a/app/models/m_odr_coupon.rb +++ b/app/models/m_odr_coupon.rb @@ -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 diff --git a/app/models/m_odr_place.rb b/app/models/m_odr_place.rb index a202643..c613dd3 100644 --- a/app/models/m_odr_place.rb +++ b/app/models/m_odr_place.rb @@ -1,6 +1,7 @@ class MOdrPlace < ApplicationRecord belongs_to :m_odr + validates :name, :presence => true acts_as_sorting :fields => { :name => {:name => "Nom", :reorder => true}, diff --git a/app/views/admin/import_csvs/_form.html.haml b/app/views/admin/import_csvs/_form.html.haml index 3f98f86..5274743 100644 --- a/app/views/admin/import_csvs/_form.html.haml +++ b/app/views/admin/import_csvs/_form.html.haml @@ -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 diff --git a/app/views/admin/m_odr_coupons/_form.html.haml b/app/views/admin/m_odr_coupons/_form.html.haml new file mode 100644 index 0000000..e533af3 --- /dev/null +++ b/app/views/admin/m_odr_coupons/_form.html.haml @@ -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" diff --git a/app/views/admin/m_odr_coupons/_m_odr_coupon.html.haml b/app/views/admin/m_odr_coupons/_m_odr_coupon.html.haml new file mode 100644 index 0000000..75b23a2 --- /dev/null +++ b/app/views/admin/m_odr_coupons/_m_odr_coupon.html.haml @@ -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} + + + \ No newline at end of file diff --git a/app/views/admin/m_odr_coupons/create.js.erb b/app/views/admin/m_odr_coupons/create.js.erb new file mode 100644 index 0000000..c80051f --- /dev/null +++ b/app/views/admin/m_odr_coupons/create.js.erb @@ -0,0 +1,2 @@ +$('#m_odr_coupons_rows').prepend("<%= escape_javascript(render(@m_odr_coupon))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/m_odr_coupons/destroy.js.erb b/app/views/admin/m_odr_coupons/destroy.js.erb new file mode 100644 index 0000000..d9d45f1 --- /dev/null +++ b/app/views/admin/m_odr_coupons/destroy.js.erb @@ -0,0 +1 @@ +$('#m_odr_coupon_row_<%= @m_odr_coupon.id %>').remove(); \ No newline at end of file diff --git a/app/views/admin/m_odr_coupons/edit.js.erb b/app/views/admin/m_odr_coupons/edit.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/m_odr_coupons/edit.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/m_odr_coupons/index.html.haml b/app/views/admin/m_odr_coupons/index.html.haml new file mode 100644 index 0000000..1de0e1c --- /dev/null +++ b/app/views/admin/m_odr_coupons/index.html.haml @@ -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 + + \ No newline at end of file diff --git a/app/views/admin/m_odr_coupons/new.js.erb b/app/views/admin/m_odr_coupons/new.js.erb new file mode 100644 index 0000000..6c8f015 --- /dev/null +++ b/app/views/admin/m_odr_coupons/new.js.erb @@ -0,0 +1 @@ +show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900); \ No newline at end of file diff --git a/app/views/admin/m_odr_coupons/show.html.haml b/app/views/admin/m_odr_coupons/show.html.haml new file mode 100644 index 0000000..a20d3df --- /dev/null +++ b/app/views/admin/m_odr_coupons/show.html.haml @@ -0,0 +1,10 @@ +.qi_header + %h1 + + %span + + + +.qi_row + .qi_pannel.qi_plain.padding + =debug @m_odr_coupon \ No newline at end of file diff --git a/app/views/admin/m_odr_coupons/update.js.erb b/app/views/admin/m_odr_coupons/update.js.erb new file mode 100644 index 0000000..078e041 --- /dev/null +++ b/app/views/admin/m_odr_coupons/update.js.erb @@ -0,0 +1,2 @@ +$('#m_odr_coupon_row_<%= @m_odr_coupon.id %>').replaceWith("<%= escape_javascript(render(@m_odr_coupon))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/m_odrs/show.html.haml b/app/views/admin/m_odrs/show.html.haml index 5635fd2..eda2e24 100644 --- a/app/views/admin/m_odrs/show.html.haml +++ b/app/views/admin/m_odrs/show.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index a5ece7e..7c7cba4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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