##// END OF EJS Templates
Fixed pagination links on admin project listing...
Jean-Philippe Lang -
r436:2e78bc1bc416
parent child
Show More
@@ -1,241 +1,241
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 module ApplicationHelper
18 module ApplicationHelper
19
19
20 # Return current logged in user or nil
20 # Return current logged in user or nil
21 def loggedin?
21 def loggedin?
22 @logged_in_user
22 @logged_in_user
23 end
23 end
24
24
25 # Return true if user is logged in and is admin, otherwise false
25 # Return true if user is logged in and is admin, otherwise false
26 def admin_loggedin?
26 def admin_loggedin?
27 @logged_in_user and @logged_in_user.admin?
27 @logged_in_user and @logged_in_user.admin?
28 end
28 end
29
29
30 # Return true if user is authorized for controller/action, otherwise false
30 # Return true if user is authorized for controller/action, otherwise false
31 def authorize_for(controller, action)
31 def authorize_for(controller, action)
32 # check if action is allowed on public projects
32 # check if action is allowed on public projects
33 if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
33 if @project.is_public? and Permission.allowed_to_public "%s/%s" % [ controller, action ]
34 return true
34 return true
35 end
35 end
36 # check if user is authorized
36 # check if user is authorized
37 if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project) ) )
37 if @logged_in_user and (@logged_in_user.admin? or Permission.allowed_to_role( "%s/%s" % [ controller, action ], @logged_in_user.role_for_project(@project) ) )
38 return true
38 return true
39 end
39 end
40 return false
40 return false
41 end
41 end
42
42
43 # Display a link if user is authorized
43 # Display a link if user is authorized
44 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
44 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
45 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller], options[:action])
45 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller], options[:action])
46 end
46 end
47
47
48 # Display a link to user's account page
48 # Display a link to user's account page
49 def link_to_user(user)
49 def link_to_user(user)
50 link_to user.display_name, :controller => 'account', :action => 'show', :id => user
50 link_to user.display_name, :controller => 'account', :action => 'show', :id => user
51 end
51 end
52
52
53 def link_to_issue(issue)
53 def link_to_issue(issue)
54 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
54 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
55 end
55 end
56
56
57 def toggle_link(name, id, options={})
57 def toggle_link(name, id, options={})
58 onclick = "Element.toggle('#{id}'); "
58 onclick = "Element.toggle('#{id}'); "
59 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
59 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
60 onclick << "return false;"
60 onclick << "return false;"
61 link_to(name, "#", :onclick => onclick)
61 link_to(name, "#", :onclick => onclick)
62 end
62 end
63
63
64 def image_to_function(name, function, html_options = {})
64 def image_to_function(name, function, html_options = {})
65 html_options.symbolize_keys!
65 html_options.symbolize_keys!
66 tag(:input, html_options.merge({
66 tag(:input, html_options.merge({
67 :type => "image", :src => image_path(name),
67 :type => "image", :src => image_path(name),
68 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
68 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
69 }))
69 }))
70 end
70 end
71
71
72 def format_date(date)
72 def format_date(date)
73 l_date(date) if date
73 l_date(date) if date
74 end
74 end
75
75
76 def format_time(time)
76 def format_time(time)
77 l_datetime((time.is_a? String) ? time.to_time : time) if time
77 l_datetime((time.is_a? String) ? time.to_time : time) if time
78 end
78 end
79
79
80 def day_name(day)
80 def day_name(day)
81 l(:general_day_names).split(',')[day-1]
81 l(:general_day_names).split(',')[day-1]
82 end
82 end
83
83
84 def month_name(month)
84 def month_name(month)
85 l(:actionview_datehelper_select_month_names).split(',')[month-1]
85 l(:actionview_datehelper_select_month_names).split(',')[month-1]
86 end
86 end
87
87
88 def pagination_links_full(paginator, options={}, html_options={})
88 def pagination_links_full(paginator, options={}, html_options={})
89 html = ''
89 html = ''
90 html << link_to_remote(('&#171; ' + l(:label_previous)),
90 html << link_to_remote(('&#171; ' + l(:label_previous)),
91 {:update => "content", :url => options.merge(:page => paginator.current.previous)},
91 {:update => "content", :url => options.merge(:page => paginator.current.previous)},
92 {:href => url_for(:params => options.merge(:page => paginator.current.previous))}) + ' ' if paginator.current.previous
92 {:href => url_for(:params => options.merge(:page => paginator.current.previous))}) + ' ' if paginator.current.previous
93
93
94 html << (pagination_links_each(paginator, options) do |n|
94 html << (pagination_links_each(paginator, options) do |n|
95 link_to_remote(n.to_s,
95 link_to_remote(n.to_s,
96 {:url => {:action => 'list', :params => options.merge(:page => n)}, :update => 'content'},
96 {:url => {:params => options.merge(:page => n)}, :update => 'content'},
97 {:href => url_for(:params => options.merge(:page => n))})
97 {:href => url_for(:params => options.merge(:page => n))})
98 end || '')
98 end || '')
99
99
100 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
100 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
101 {:update => "content", :url => options.merge(:page => paginator.current.next)},
101 {:update => "content", :url => options.merge(:page => paginator.current.next)},
102 {:href => url_for(:params => options.merge(:page => paginator.current.next))}) if paginator.current.next
102 {:href => url_for(:params => options.merge(:page => paginator.current.next))}) if paginator.current.next
103 html
103 html
104 end
104 end
105
105
106 # textilize text according to system settings and RedCloth availability
106 # textilize text according to system settings and RedCloth availability
107 def textilizable(text, options = {})
107 def textilizable(text, options = {})
108 # different methods for formatting wiki links
108 # different methods for formatting wiki links
109 case options[:wiki_links]
109 case options[:wiki_links]
110 when :local
110 when :local
111 # used for local links to html files
111 # used for local links to html files
112 format_wiki_link = Proc.new {|title| "#{title}.html" }
112 format_wiki_link = Proc.new {|title| "#{title}.html" }
113 when :anchor
113 when :anchor
114 # used for single-file wiki export
114 # used for single-file wiki export
115 format_wiki_link = Proc.new {|title| "##{title}" }
115 format_wiki_link = Proc.new {|title| "##{title}" }
116 else
116 else
117 if @project
117 if @project
118 format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
118 format_wiki_link = Proc.new {|title| url_for :controller => 'wiki', :action => 'index', :id => @project, :page => title }
119 else
119 else
120 format_wiki_link = Proc.new {|title| title }
120 format_wiki_link = Proc.new {|title| title }
121 end
121 end
122 end
122 end
123
123
124 # turn wiki links into textile links:
124 # turn wiki links into textile links:
125 # example:
125 # example:
126 # [[link]] -> "link":link
126 # [[link]] -> "link":link
127 # [[link|title]] -> "title":link
127 # [[link|title]] -> "title":link
128 text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + format_wiki_link.call(Wiki.titleize($1)) }
128 text = text.gsub(/\[\[([^\]\|]+)(\|([^\]\|]+))?\]\]/) {|m| "\"#{$3 || $1}\":" + format_wiki_link.call(Wiki.titleize($1)) }
129
129
130 # turn issue ids to textile links
130 # turn issue ids to textile links
131 # example:
131 # example:
132 # #52 -> "#52":/issues/show/52
132 # #52 -> "#52":/issues/show/52
133 text = text.gsub(/#(\d+)(?=\b)/) {|m| "\"##{$1}\":" + url_for(:controller => 'issues', :action => 'show', :id => $1) }
133 text = text.gsub(/#(\d+)(?=\b)/) {|m| "\"##{$1}\":" + url_for(:controller => 'issues', :action => 'show', :id => $1) }
134
134
135 # turn revision ids to textile links (@project needed)
135 # turn revision ids to textile links (@project needed)
136 # example:
136 # example:
137 # r52 -> "r52":/repositories/revision/6?rev=52 (@project.id is 6)
137 # r52 -> "r52":/repositories/revision/6?rev=52 (@project.id is 6)
138 text = text.gsub(/r(\d+)(?=\b)/) {|m| "\"r#{$1}\":" + url_for(:controller => 'repositories', :action => 'revision', :id => @project.id, :rev => $1) } if @project
138 text = text.gsub(/r(\d+)(?=\b)/) {|m| "\"r#{$1}\":" + url_for(:controller => 'repositories', :action => 'revision', :id => @project.id, :rev => $1) } if @project
139
139
140 # finally textilize text
140 # finally textilize text
141 @do_textilize ||= (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize")
141 @do_textilize ||= (Setting.text_formatting == 'textile') && (ActionView::Helpers::TextHelper.method_defined? "textilize")
142 text = @do_textilize ? auto_link(RedCloth.new(text).to_html) : simple_format(auto_link(h(text)))
142 text = @do_textilize ? auto_link(RedCloth.new(text).to_html) : simple_format(auto_link(h(text)))
143 end
143 end
144
144
145 def error_messages_for(object_name, options = {})
145 def error_messages_for(object_name, options = {})
146 options = options.symbolize_keys
146 options = options.symbolize_keys
147 object = instance_variable_get("@#{object_name}")
147 object = instance_variable_get("@#{object_name}")
148 if object && !object.errors.empty?
148 if object && !object.errors.empty?
149 # build full_messages here with controller current language
149 # build full_messages here with controller current language
150 full_messages = []
150 full_messages = []
151 object.errors.each do |attr, msg|
151 object.errors.each do |attr, msg|
152 next if msg.nil?
152 next if msg.nil?
153 msg = msg.first if msg.is_a? Array
153 msg = msg.first if msg.is_a? Array
154 if attr == "base"
154 if attr == "base"
155 full_messages << l(msg)
155 full_messages << l(msg)
156 else
156 else
157 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
157 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
158 end
158 end
159 end
159 end
160 # retrieve custom values error messages
160 # retrieve custom values error messages
161 if object.errors[:custom_values]
161 if object.errors[:custom_values]
162 object.custom_values.each do |v|
162 object.custom_values.each do |v|
163 v.errors.each do |attr, msg|
163 v.errors.each do |attr, msg|
164 next if msg.nil?
164 next if msg.nil?
165 msg = msg.first if msg.is_a? Array
165 msg = msg.first if msg.is_a? Array
166 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
166 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
167 end
167 end
168 end
168 end
169 end
169 end
170 content_tag("div",
170 content_tag("div",
171 content_tag(
171 content_tag(
172 options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
172 options[:header_tag] || "h2", lwr(:gui_validation_error, full_messages.length) + " :"
173 ) +
173 ) +
174 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
174 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
175 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
175 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
176 )
176 )
177 else
177 else
178 ""
178 ""
179 end
179 end
180 end
180 end
181
181
182 def lang_options_for_select(blank=true)
182 def lang_options_for_select(blank=true)
183 (blank ? [["(auto)", ""]] : []) +
183 (blank ? [["(auto)", ""]] : []) +
184 (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
184 (GLoc.valid_languages.sort {|x,y| x.to_s <=> y.to_s }).collect {|lang| [ l_lang_name(lang.to_s, lang), lang.to_s]}
185 end
185 end
186
186
187 def label_tag_for(name, option_tags = nil, options = {})
187 def label_tag_for(name, option_tags = nil, options = {})
188 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
188 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
189 content_tag("label", label_text)
189 content_tag("label", label_text)
190 end
190 end
191
191
192 def labelled_tabular_form_for(name, object, options, &proc)
192 def labelled_tabular_form_for(name, object, options, &proc)
193 options[:html] ||= {}
193 options[:html] ||= {}
194 options[:html].store :class, "tabular"
194 options[:html].store :class, "tabular"
195 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
195 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
196 end
196 end
197
197
198 def check_all_links(form_name)
198 def check_all_links(form_name)
199 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
199 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
200 " | " +
200 " | " +
201 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
201 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
202 end
202 end
203
203
204 def calendar_for(field_id)
204 def calendar_for(field_id)
205 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
205 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
206 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
206 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
207 end
207 end
208 end
208 end
209
209
210 class TabularFormBuilder < ActionView::Helpers::FormBuilder
210 class TabularFormBuilder < ActionView::Helpers::FormBuilder
211 include GLoc
211 include GLoc
212
212
213 def initialize(object_name, object, template, options, proc)
213 def initialize(object_name, object, template, options, proc)
214 set_language_if_valid options.delete(:lang)
214 set_language_if_valid options.delete(:lang)
215 @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
215 @object_name, @object, @template, @options, @proc = object_name, object, template, options, proc
216 end
216 end
217
217
218 (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
218 (field_helpers - %w(radio_button hidden_field) + %w(date_select)).each do |selector|
219 src = <<-END_SRC
219 src = <<-END_SRC
220 def #{selector}(field, options = {})
220 def #{selector}(field, options = {})
221 return super if options.delete :no_label
221 return super if options.delete :no_label
222 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
222 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
223 label = @template.content_tag("label", label_text,
223 label = @template.content_tag("label", label_text,
224 :class => (@object && @object.errors[field] ? "error" : nil),
224 :class => (@object && @object.errors[field] ? "error" : nil),
225 :for => (@object_name.to_s + "_" + field.to_s))
225 :for => (@object_name.to_s + "_" + field.to_s))
226 label + super
226 label + super
227 end
227 end
228 END_SRC
228 END_SRC
229 class_eval src, __FILE__, __LINE__
229 class_eval src, __FILE__, __LINE__
230 end
230 end
231
231
232 def select(field, choices, options = {}, html_options = {})
232 def select(field, choices, options = {}, html_options = {})
233 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
233 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
234 label = @template.content_tag("label", label_text,
234 label = @template.content_tag("label", label_text,
235 :class => (@object && @object.errors[field] ? "error" : nil),
235 :class => (@object && @object.errors[field] ? "error" : nil),
236 :for => (@object_name.to_s + "_" + field.to_s))
236 :for => (@object_name.to_s + "_" + field.to_s))
237 label + super
237 label + super
238 end
238 end
239
239
240 end
240 end
241
241
General Comments 0
You need to be logged in to leave comments. Login now