summaryrefslogtreecommitdiffstats
path: root/app/helpers/calendars_helper.rb
blob: 20f1e82976e91a57eec60423d738552e4f80d37d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module CalendarsHelper
  def link_to_previous_month(year, month, options={})
    target_year, target_month = if month == 1
                                  [year - 1, 12]
                                else
                                  [year, month - 1]
                                end
    
    name = if target_month == 12
             "#{month_name(target_month)} #{target_year}"
           else
             "#{month_name(target_month)}"
           end

    link_to_month(('« ' + name), target_year, target_month, options)
  end

  def link_to_next_month(year, month, options={})
    target_year, target_month = if month == 12
                                  [year + 1, 1]
                                else
                                  [year, month + 1]
                                end

    name = if target_month == 1
             "#{month_name(target_month)} #{target_year}"
           else
             "#{month_name(target_month)}"
           end

    link_to_month((name + ' »'), target_year, target_month, options)
  end

  def link_to_month(link_name, year, month, options={})
    link_target = url_for(params.merge(:year => year, :month => month))

    link_to_remote(link_name,
                   {:update => "content", :url => link_target, :method => :put},
                   {:href => link_target})

  end
  
end