calendars_helper.rb 1.58 KB
Newer Older
1
module CalendarsHelper
2
  def link_to_previous_month(year, month, options={})
3 4 5 6 7 8 9 10 11 12 13
    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
14 15 16

    project_id = options[:project].present? ? options[:project].to_param : nil
    link_target = calendar_path(:year => target_year, :month => target_month, :project_id => project_id)
17 18 19 20

    link_to_remote(('« ' + name),
                   {:update => "content", :url => link_target, :method => :put},
                   {:href => link_target})
21 22
  end

23
  def link_to_next_month(year, month, options={})
24 25 26 27 28 29 30 31 32 33 34 35
    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

36 37
    project_id = options[:project].present? ? options[:project].to_param : nil
    link_target = calendar_path(:year => target_year, :month => target_month, :project_id => project_id)
38 39 40 41

    link_to_remote((name + ' »'), 
                   {:update => "content", :url => link_target, :method => :put},
                   {:href => link_target})
42 43 44

  end
end