##// END OF EJS Templates
Refactor: extract common code to link_to_month....
Eric Davis -
r3932:5b08b2f33d40
parent child
Show More
@@ -1,44 +1,45
1 module CalendarsHelper
1 module CalendarsHelper
2 def link_to_previous_month(year, month, options={})
2 def link_to_previous_month(year, month, options={})
3 target_year, target_month = if month == 1
3 target_year, target_month = if month == 1
4 [year - 1, 12]
4 [year - 1, 12]
5 else
5 else
6 [year, month - 1]
6 [year, month - 1]
7 end
7 end
8
8
9 name = if target_month == 12
9 name = if target_month == 12
10 "#{month_name(target_month)} #{target_year}"
10 "#{month_name(target_month)} #{target_year}"
11 else
11 else
12 "#{month_name(target_month)}"
12 "#{month_name(target_month)}"
13 end
13 end
14
14
15 project_id = options[:project].present? ? options[:project].to_param : nil
15 link_to_month(('« ' + name), target_year, target_month, options)
16 link_target = calendar_path(:year => target_year, :month => target_month, :project_id => project_id)
17
18 link_to_remote(('« ' + name),
19 {:update => "content", :url => link_target, :method => :put},
20 {:href => link_target})
21 end
16 end
22
17
23 def link_to_next_month(year, month, options={})
18 def link_to_next_month(year, month, options={})
24 target_year, target_month = if month == 12
19 target_year, target_month = if month == 12
25 [year + 1, 1]
20 [year + 1, 1]
26 else
21 else
27 [year, month + 1]
22 [year, month + 1]
28 end
23 end
29
24
30 name = if target_month == 1
25 name = if target_month == 1
31 "#{month_name(target_month)} #{target_year}"
26 "#{month_name(target_month)} #{target_year}"
32 else
27 else
33 "#{month_name(target_month)}"
28 "#{month_name(target_month)}"
34 end
29 end
35
30
31 link_to_month((name + ' »'), target_year, target_month, options)
32 end
33
34 def link_to_month(link_name, year, month, options={})
36 project_id = options[:project].present? ? options[:project].to_param : nil
35 project_id = options[:project].present? ? options[:project].to_param : nil
37 link_target = calendar_path(:year => target_year, :month => target_month, :project_id => project_id)
38
36
39 link_to_remote((name + ' »'),
37 link_target = calendar_path(:year => year, :month => month, :project_id => project_id)
38
39 link_to_remote(link_name,
40 {:update => "content", :url => link_target, :method => :put},
40 {:update => "content", :url => link_target, :method => :put},
41 {:href => link_target})
41 {:href => link_target})
42
42
43 end
43 end
44
44 end
45 end
General Comments 0
You need to be logged in to leave comments. Login now