diff --git a/app/assets/javascripts/events.js.coffee b/app/assets/javascripts/events.js.coffee index 7b3312a7..c3e57ba8 100644 --- a/app/assets/javascripts/events.js.coffee +++ b/app/assets/javascripts/events.js.coffee @@ -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}'+year+'<') diff --git a/app/assets/stylesheets/events.css.sass b/app/assets/stylesheets/events.css.sass index 41819fbd..ff65cfae 100644 --- a/app/assets/stylesheets/events.css.sass +++ b/app/assets/stylesheets/events.css.sass @@ -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 diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index a2fe0778..5ff0bf4b 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 0f5d32d7..07184c7a 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 < ?", diff --git a/app/views/events/index.html.haml b/app/views/events/index.html.haml index 9c653245..60915d8b 100644 --- a/app/views/events/index.html.haml +++ b/app/views/events/index.html.haml @@ -8,13 +8,33 @@ options_from_collection_for_select(Region.all, 'id', 'name', params[:region]), prompt: t('region_selector') -= 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 +- 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 + %li.event + = link_to event.url do + %strong= event.city + = event.title .formats =t '.calendar_in'