From 3eea03d70efd4e894a5020e8bae62a6af6e59803 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 26 Aug 2010 16:37:05 +0000 Subject: [PATCH] Refactor: extract link to previous and next month into helpers. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4042 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/calendars_helper.rb | 14 ++++++++++++++ app/views/calendars/show.html.erb | 9 +-------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 app/helpers/calendars_helper.rb diff --git a/app/helpers/calendars_helper.rb b/app/helpers/calendars_helper.rb new file mode 100644 index 000000000..d3544f267 --- /dev/null +++ b/app/helpers/calendars_helper.rb @@ -0,0 +1,14 @@ +module CalendarsHelper + def link_to_previous_month(year, month) + link_to_remote ('« ' + (month==1 ? "#{month_name(12)} #{year-1}" : "#{month_name(month-1)}")), + {:update => "content", :url => { :year => (month==1 ? year-1 : year), :month =>(month==1 ? 12 : month-1) }}, + {:href => url_for(:action => 'show', :year => (month==1 ? year-1 : year), :month =>(month==1 ? 12 : month-1))} + end + + def link_to_next_month(year, month) + link_to_remote ((month==12 ? "#{month_name(1)} #{year+1}" : "#{month_name(month+1)}") + ' »'), + {:update => "content", :url => { :year => (month==12 ? year+1 : year), :month =>(month==12 ? 1 : month+1) }}, + {:href => url_for(:action => 'show', :year => (month==12 ? year+1 : year), :month =>(month==12 ? 1 : month+1))} + + end +end diff --git a/app/views/calendars/show.html.erb b/app/views/calendars/show.html.erb index afbceb9cd..09bf7ddf2 100644 --- a/app/views/calendars/show.html.erb +++ b/app/views/calendars/show.html.erb @@ -10,14 +10,7 @@

-<%= link_to_remote ('« ' + (@month==1 ? "#{month_name(12)} #{@year-1}" : "#{month_name(@month-1)}")), - {:update => "content", :url => { :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1) }}, - {:href => url_for(:action => 'show', :year => (@month==1 ? @year-1 : @year), :month =>(@month==1 ? 12 : @month-1))} - %> | -<%= link_to_remote ((@month==12 ? "#{month_name(1)} #{@year+1}" : "#{month_name(@month+1)}") + ' »'), - {:update => "content", :url => { :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1) }}, - {:href => url_for(:action => 'show', :year => (@month==12 ? @year+1 : @year), :month =>(@month==12 ? 1 : @month+1))} - %> + <%= link_to_previous_month(@year, @month) %> | <%= link_to_next_month(@year, @month) %>

-- 2.39.5