Calendrier sur année entière

This commit is contained in:
echarp 2013-12-29 17:45:53 +01:00
parent 7031620e9d
commit 0572dea806
5 changed files with 52 additions and 16 deletions

View File

@ -5,3 +5,7 @@
$(document).ready ->
$('form.region_selector select').change ->
this.form.submit()
selector = $('main form.region_selector + h2')
year = selector.html().substr selector.html().search(/\d{4}</), 4
selector.html selector.html().replace(/\d{4}</, '<a class="year_selector" href="?year='+year+'">'+year+'</a><')

View File

@ -1,5 +1,5 @@
form.region_selector
width: 98.3%
width: 98.4%
position: absolute
margin-top: 2.6em
label
@ -7,18 +7,28 @@ form.region_selector
main form.region_selector + h2
margin-top: 1.1em
margin-bottom: 2.5em
a
font-weight: normal
&.previous-month
margin-right: 0.4em
margin-right: 0.35em
&.next-month
margin-left: 0.4em
margin-left: 0.35em
// For whole year calendar
main form.region_selector + h2 + h2
padding: 1px 0 0
font-size: 1.2em
margin-bottom: 19px
table.calendar + h2
margin: 1em
font-size: 1.2em
table.calendar
width: 90%
margin: 0 auto
padding: 0
margin-top: 3.7em
border-spacing: 2px
th
padding: 0 0 5px 0

View File

@ -1,9 +1,11 @@
class EventsController < InheritedResources::Base
def index
params[:year] ||= Date.today.year
params[:month] ||= Date.today.month
@events = Event.month(params[:year], params[:month])
if (params[:year] and !params[:month])
# Whole year calendar
@events = Event.year(params[:year] || Date.today.year)
else
@events = Event.month(params[:year] || Date.today.year, params[:month] || Date.today.month)
end
if (params[:region] && params[:region].present?)
@events = @events.region(params[:region])
end

View File

@ -3,7 +3,7 @@ class Event < ActiveRecord::Base
scope :year, -> year {
where "end_time >= ? and start_time < ?",
"#{year}-1-1", "#{year.to_is+1}-1-1"
"#{year}-1-1", "#{year.to_i+1}-1-1"
}
scope :month, -> year, month {
where "end_time >= ? and start_time < ?",

View File

@ -8,6 +8,26 @@
options_from_collection_for_select(Region.all, 'id', 'name', params[:region]),
prompt: t('region_selector')
- if (params[:year] and !params[:month])
-# Whole year calendar
%h2
- params[:year] ||= Date.today.year
= link_to '<<', "?year=#{params[:year].to_i-1}"
= params[:year]
= link_to '>>', "?year=#{params[:year].to_i+1}"
- (1..12).each do |i|
- params[:month] = i
= calendar @events, { prev_text: '', next_text: '', start_day: :monday,
params: { region: params[:region] } } do |event|
%ul.events
%li.event
= link_to event.url do
%strong= event.city
= event.title
- else
= calendar @events, { prev_text: '<<', next_text: '>>', start_day: :monday,
params: { region: params[:region] } } do |event|
%ul.events