This commit is contained in:
Nicolas Bally 2019-06-03 20:19:09 +02:00
parent 10bf7b95d0
commit 8399f37b09
16 changed files with 228 additions and 1 deletions

View File

@ -0,0 +1,108 @@
# -*- encoding : utf-8 -*-
class Admin::AbonnementsController < ApplicationController
before_filter :auth_admin
layout "admin"
before_filter :find_abonnements
def index
end
def new
@abonnement = Abonnement.new()
end
def edit
@abonnement = Abonnement.find(params[:id])
end
def show
@abonnement = Abonnement.find(params[:id])
end
def create
@abonnement = Abonnement.new(params.require(:abonnement).permit!)
if @abonnement.save
find_abonnements
flash[:notice] = "La catégorie à été ajouté avec succès."
else
render :action => "new"
end
end
def update
@abonnement = Abonnement.find(params[:id])
respond_to do |format|
if @abonnement.update_attributes(params.require(:abonnement).permit!)
flash[:notice] = "Le menu à été modifié avec succès."
if @reorder
format.js {
render :action => "update" }
else
format.js {
@abonnement = Abonnement.find(@abonnement.id)
render :action => "update_row" }
end
end
end
end
def destroy
@abonnement = Abonnement.find(params[:id])
@abonnement.destroy
find_abonnements
flash[:notice] = "La catégorie à bien été supprimée."
end
protected
def find_abonnements
@abonnements = Abonnement.order("created_at DESC").all
end
end

View File

@ -10,7 +10,11 @@ class ApplicationController < ActionController::Base
def get_reseaux
if session[:reseaux_id] and current_customer and !params[:no_reseaux]
if params[:reseaux_id] and current_customer and !params[:no_reseaux]
@reseaux = current_customer.reseauxes.find(params[:reseaux_id])
@reseaux_layout = true
session[:reseaux_id] = @reseaux.id
elsif session[:reseaux_id] and current_customer and !params[:no_reseaux]
@reseaux = current_customer.reseauxes.find(session[:reseaux_id])
@reseaux_layout = true
elsif !params[:no_reseaux]
@ -72,6 +76,8 @@ class ApplicationController < ActionController::Base
end
def require_negos_abo
get_reseaux
if !current_abo and (!session[:reseaux_id] or (@reseaux and @reseaux.abo_needed))
redirect_to new_public_abonnement_path
end

View File

@ -10,6 +10,15 @@ class Public::NeedsController < ApplicationController
before_filter :check_owner, only: [:destroy,:edit,:update]
def index
#dsffsd = sdfd
if params[:reseaux_id]
@reseaux = Reseaux.find(params[:reseaux_id])
session[:reseaux_id] = @reseaux.id
elsif session[:reseaux_id]
@reseaux = Reseaux.find(session[:reseaux_id])
end
params[:type] = params[:type] || 1
params[:type] = params[:type].to_i

View File

@ -3,6 +3,7 @@
class Public::ProductsController < ApplicationController
before_filter :auth_customer
before_filter :require_negos_abo
layout "public"
def show

View File

@ -1,5 +1,6 @@
class Abonnement < ActiveRecord::Base
belongs_to :reseaux
belongs_to :customer
has_many :payments, :as => :element
def after_paid

View File

@ -288,6 +288,10 @@ class Customer < ActiveRecord::Base
"#{firstname.capitalize} #{name.upcase}"
end
def name_for_label
"#{self.organisation} #{self.name.upcase} #{self.firstname.capitalize} - #{self.email}"
end
def pseudo
if self.pro
self.organisation

View File

@ -0,0 +1,30 @@
%tr#abonnement.abonnement{:id => abonnement.id}
%td=abonnement.id
%td
-if abonnement.reseaux
=abonnement.reseaux.name
%td
-if abonnement.customer
=abonnement.customer.organisation
=abonnement.customer.name
=abonnement.customer.firstname
%td=abonnement.slug
%td=l abonnement.start_at
%td=l abonnement.end_at
%td=number_to_currency abonnement.price
%td=ic :check if abonnement.paid
%td.actions
=# link_to i(:"trash-o"), [:admin, abonnement], :data =>{:remote => true, :confirm => 'Voulez-vous vraiment supprimer cette taille ? Elle sera supprimée de tous les produits qui la contenait'}, :method => :delete
= link_to i(:pencil), edit_admin_abonnement_path(abonnement), :data => {:remote => true}

View File

@ -0,0 +1,19 @@
= semantic_form_for [:admin,@abonnement], :remote => true do |form|
.content
= form.input :reseaux_id, :label => "Réseau :", :collection => Reseaux.where(:parent_id => nil).all, :as => :select, :include_blank => true
=form.input :customer_id, :label => "Client :", :collection => Customer.order(:organisation, :name).all, :as => :select, :include_blank => true, :member_label => :name_for_label
= form.input :start_at, :label => "Début", :as => :date
= form.input :end_at, :label => "Fin", :as => :date
= form.input :price, :label => "Prix :"
= form.input :paid, :label => "Payé ?"
.actions
= form.submit "Sauvegarder"

View File

@ -0,0 +1,4 @@
close_pane_hover();
$('#abonnements').html("<%= escape_javascript(render(@abonnements)) %>");

View File

@ -0,0 +1,5 @@
$('#abonnement_<%= @abonnement.id %>').remove();
<%= flash_js %>

View File

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

View File

@ -0,0 +1,27 @@
.qi_header
.right= link_to 'Ajouter un abonnement manuellement', new_admin_abonnement_path, :class => "btn btn-primary", :remote => true
%h1
Boutique
%span
Liste des documents
.qi_row
.qi_pannel.qi_plain.padding
%table.table
%tr
%th ID
%th Réseaux
%th Client
%th Slug
%th Début
%th Fin
%th Prix
%th Payé ?
%th
%tbody#abonnements=render @abonnements

View File

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

View File

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

View File

@ -72,6 +72,7 @@
%li= link_to "Type de documents", admin_product_order_document_types_path
%li=# link_to "Codes de reduction", admin_vourcher_codes_path
%li=link_to "Pages statiques", admin_menu_items_path(:menu_id => 1)
%li=link_to "Abos", admin_abonnements_path()
%ul.nav.navbar-nav.navbar-right
%li.dropdown

View File

@ -336,6 +336,14 @@ Rails.application.routes.draw do
end
namespace :admin do
resources :abonnements do
member do
get :force
end
end
resources :fournisseurs
resources :product_order_documents
resources :product_order_document_types