130 lines
2.7 KiB
Ruby
130 lines
2.7 KiB
Ruby
# -*- encoding : utf-8 -*-
|
|
|
|
class Admin::PlumeEventsController < ApplicationController
|
|
before_filter :auth_admin
|
|
|
|
|
|
layout "admin"
|
|
|
|
before_filter :find_plume_events
|
|
|
|
|
|
def reorder
|
|
i = 0
|
|
params[:order].each do |petition_id|
|
|
i += 1
|
|
petition = PlumeEvent.find(petition_id)
|
|
petition.position = i
|
|
petition.save
|
|
end
|
|
render :inline => "ok"
|
|
|
|
end
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
def cible
|
|
@plume_events = PlumeEvent.all
|
|
|
|
render :layout => false
|
|
end
|
|
|
|
|
|
def new
|
|
if params[:plume_event_id] and PlumeEvent.find(params[:plume_event_id])
|
|
@plume_event = PlumeEvent.find(params[:plume_event_id]).dup
|
|
@plume_event.plume_event_id = params[:plume_event_id]
|
|
else
|
|
@plume_event = PlumeEvent.new(:start_at_date =>[ Date.today.day, Date.today.month, Date.today.year].join("/"), :start_at_time => "20:00")
|
|
|
|
end
|
|
|
|
@plume_event.plume_id = params[:plume_id]
|
|
|
|
end
|
|
|
|
def edit
|
|
@plume_event = PlumeEvent.find(params[:id])
|
|
|
|
|
|
end
|
|
|
|
|
|
def create
|
|
@plume_event = PlumeEvent.new(params.require(:plume_event).permit!)
|
|
|
|
|
|
if @plume_event.save
|
|
|
|
|
|
flash[:notice] = "L'événement à été ajouté avec succès."
|
|
|
|
@plume_events = @plume_event.plume.plume_events.order('start_at, stop_at')
|
|
|
|
else
|
|
render :action => "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def update
|
|
@plume_event = PlumeEvent.find(params[:id])
|
|
|
|
if @plume_event.update_attributes(params.require(:plume_event).permit!)
|
|
flash[:notice] = "L'événement à été modifié avec succès."
|
|
else
|
|
render :action => "edit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
def destroy
|
|
@plume_event = PlumeEvent.find(params[:id])
|
|
@plume_event.destroy
|
|
|
|
end
|
|
|
|
|
|
protected
|
|
|
|
def find_plume_events
|
|
date_regex = /^(0[1-9]|[12][0-9]|3[01])[\/](0[1-9]|1[012])[\/](19|20)\d\d$/i
|
|
if params[:start] and params[:start] =~ date_regex
|
|
start = Date.parse(params[:start]).beginning_of_day
|
|
params[:start]= start.strftime('%d/%m/%Y')
|
|
else
|
|
params[:start] = "Début"
|
|
end
|
|
if params[:stop] and params[:stop] =~ date_regex
|
|
stop = Date.parse(params[:stop]).end_of_day
|
|
params[:stop]= stop.strftime('%d/%m/%Y')
|
|
else
|
|
params[:stop] = "Fin"
|
|
end
|
|
|
|
@plume_events = PlumeEvent.order('start_at, stop_at')
|
|
@plume_events = @plume_events.after(start) if start
|
|
@plume_events = @plume_events.before(stop) if stop
|
|
per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 20
|
|
page = (params[:page] and params[:page] != "") ? params[:page] : 1
|
|
#@plume_events = PlumeEvent.all.page(page).per(per_page)
|
|
|
|
@plume_events = PlumeEvent.order('start_at DESC, stop_at DESC')
|
|
@plume_events = @plume_events.after(start) if start
|
|
@plume_events = @plume_events.before(stop) if stop
|
|
|
|
|
|
|
|
|
|
@plume_events = @plume_events.page(page).per(per_page)
|
|
end
|
|
end
|