##// END OF EJS Templates
Fixed #208: Issue list does not scroll up when you click next...
Jean-Philippe Lang -
r1100:0beafecd3bd4
parent child
Show More
@@ -1,444 +1,450
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 include Redmine::WikiFormatting::Macros::Definitions
19 include Redmine::WikiFormatting::Macros::Definitions
20
20
21 def current_role
21 def current_role
22 @current_role ||= User.current.role_for_project(@project)
22 @current_role ||= User.current.role_for_project(@project)
23 end
23 end
24
24
25 # Return true if user is authorized for controller/action, otherwise false
25 # Return true if user is authorized for controller/action, otherwise false
26 def authorize_for(controller, action)
26 def authorize_for(controller, action)
27 User.current.allowed_to?({:controller => controller, :action => action}, @project)
27 User.current.allowed_to?({:controller => controller, :action => action}, @project)
28 end
28 end
29
29
30 # Display a link if user is authorized
30 # Display a link if user is authorized
31 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
31 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
32 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
32 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
33 end
33 end
34
34
35 def link_to_signin
35 def link_to_signin
36 link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin'
36 link_to l(:label_login), { :controller => 'account', :action => 'login' }, :class => 'signin'
37 end
37 end
38
38
39 def link_to_signout
39 def link_to_signout
40 link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout'
40 link_to l(:label_logout), { :controller => 'account', :action => 'logout' }, :class => 'logout'
41 end
41 end
42
42
43 # Display a link to user's account page
43 # Display a link to user's account page
44 def link_to_user(user)
44 def link_to_user(user)
45 user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
45 user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
46 end
46 end
47
47
48 def link_to_issue(issue)
48 def link_to_issue(issue)
49 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
49 link_to "#{issue.tracker.name} ##{issue.id}", :controller => "issues", :action => "show", :id => issue
50 end
50 end
51
51
52 def toggle_link(name, id, options={})
52 def toggle_link(name, id, options={})
53 onclick = "Element.toggle('#{id}'); "
53 onclick = "Element.toggle('#{id}'); "
54 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
54 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
55 onclick << "return false;"
55 onclick << "return false;"
56 link_to(name, "#", :onclick => onclick)
56 link_to(name, "#", :onclick => onclick)
57 end
57 end
58
58
59 def show_and_goto_link(name, id, options={})
59 def show_and_goto_link(name, id, options={})
60 onclick = "Element.show('#{id}'); "
60 onclick = "Element.show('#{id}'); "
61 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
61 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
62 onclick << "location.href='##{id}-anchor'; "
62 onclick << "location.href='##{id}-anchor'; "
63 onclick << "return false;"
63 onclick << "return false;"
64 link_to(name, "#", options.merge(:onclick => onclick))
64 link_to(name, "#", options.merge(:onclick => onclick))
65 end
65 end
66
66
67 def image_to_function(name, function, html_options = {})
67 def image_to_function(name, function, html_options = {})
68 html_options.symbolize_keys!
68 html_options.symbolize_keys!
69 tag(:input, html_options.merge({
69 tag(:input, html_options.merge({
70 :type => "image", :src => image_path(name),
70 :type => "image", :src => image_path(name),
71 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
71 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
72 }))
72 }))
73 end
73 end
74
74
75 def prompt_to_remote(name, text, param, url, html_options = {})
75 def prompt_to_remote(name, text, param, url, html_options = {})
76 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
76 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
77 link_to name, {}, html_options
77 link_to name, {}, html_options
78 end
78 end
79
79
80 def format_date(date)
80 def format_date(date)
81 return nil unless date
81 return nil unless date
82 # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
82 # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
83 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
83 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
84 date.strftime(@date_format)
84 date.strftime(@date_format)
85 end
85 end
86
86
87 def format_time(time, include_date = true)
87 def format_time(time, include_date = true)
88 return nil unless time
88 return nil unless time
89 time = time.to_time if time.is_a?(String)
89 time = time.to_time if time.is_a?(String)
90 zone = User.current.time_zone
90 zone = User.current.time_zone
91 if time.utc?
91 if time.utc?
92 local = zone ? zone.adjust(time) : time.getlocal
92 local = zone ? zone.adjust(time) : time.getlocal
93 else
93 else
94 local = zone ? zone.adjust(time.getutc) : time
94 local = zone ? zone.adjust(time.getutc) : time
95 end
95 end
96 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
96 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
97 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
97 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
98 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
98 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
99 end
99 end
100
100
101 def authoring(created, author)
101 def authoring(created, author)
102 time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
102 time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
103 l(:label_added_time_by, author || 'Anonymous', time_tag)
103 l(:label_added_time_by, author || 'Anonymous', time_tag)
104 end
104 end
105
105
106 def day_name(day)
106 def day_name(day)
107 l(:general_day_names).split(',')[day-1]
107 l(:general_day_names).split(',')[day-1]
108 end
108 end
109
109
110 def month_name(month)
110 def month_name(month)
111 l(:actionview_datehelper_select_month_names).split(',')[month-1]
111 l(:actionview_datehelper_select_month_names).split(',')[month-1]
112 end
112 end
113
113
114 def pagination_links_full(paginator, count=nil, options={})
114 def pagination_links_full(paginator, count=nil, options={})
115 page_param = options.delete(:page_param) || :page
115 page_param = options.delete(:page_param) || :page
116 url_param = params.dup
116 url_param = params.dup
117 # don't reuse params if filters are present
117 # don't reuse params if filters are present
118 url_param.clear if url_param.has_key?(:set_filter)
118 url_param.clear if url_param.has_key?(:set_filter)
119
119
120 html = ''
120 html = ''
121 html << link_to_remote(('&#171; ' + l(:label_previous)),
121 html << link_to_remote(('&#171; ' + l(:label_previous)),
122 {:update => "content", :url => url_param.merge(page_param => paginator.current.previous)},
122 {:update => 'content',
123 :url => url_param.merge(page_param => paginator.current.previous),
124 :complete => 'window.scrollTo(0,0)'},
123 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
125 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
124
126
125 html << (pagination_links_each(paginator, options) do |n|
127 html << (pagination_links_each(paginator, options) do |n|
126 link_to_remote(n.to_s,
128 link_to_remote(n.to_s,
127 {:url => {:params => url_param.merge(page_param => n)}, :update => 'content'},
129 {:url => {:params => url_param.merge(page_param => n)},
130 :update => 'content',
131 :complete => 'window.scrollTo(0,0)'},
128 {:href => url_for(:params => url_param.merge(page_param => n))})
132 {:href => url_for(:params => url_param.merge(page_param => n))})
129 end || '')
133 end || '')
130
134
131 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
135 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
132 {:update => "content", :url => url_param.merge(page_param => paginator.current.next)},
136 {:update => 'content',
137 :url => url_param.merge(page_param => paginator.current.next),
138 :complete => 'window.scrollTo(0,0)'},
133 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
139 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
134
140
135 unless count.nil?
141 unless count.nil?
136 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
142 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
137 end
143 end
138
144
139 html
145 html
140 end
146 end
141
147
142 def per_page_links(selected=nil)
148 def per_page_links(selected=nil)
143 url_param = params.dup
149 url_param = params.dup
144 url_param.clear if url_param.has_key?(:set_filter)
150 url_param.clear if url_param.has_key?(:set_filter)
145
151
146 links = Setting.per_page_options_array.collect do |n|
152 links = Setting.per_page_options_array.collect do |n|
147 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
153 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
148 {:href => url_for(url_param.merge(:per_page => n))})
154 {:href => url_for(url_param.merge(:per_page => n))})
149 end
155 end
150 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
156 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
151 end
157 end
152
158
153 def html_title(*args)
159 def html_title(*args)
154 if args.empty?
160 if args.empty?
155 title = []
161 title = []
156 title << @project.name if @project
162 title << @project.name if @project
157 title += @html_title if @html_title
163 title += @html_title if @html_title
158 title << Setting.app_title
164 title << Setting.app_title
159 title.compact.join(' - ')
165 title.compact.join(' - ')
160 else
166 else
161 @html_title ||= []
167 @html_title ||= []
162 @html_title += args
168 @html_title += args
163 end
169 end
164 end
170 end
165
171
166 def accesskey(s)
172 def accesskey(s)
167 Redmine::AccessKeys.key_for s
173 Redmine::AccessKeys.key_for s
168 end
174 end
169
175
170 # Formats text according to system settings.
176 # Formats text according to system settings.
171 # 2 ways to call this method:
177 # 2 ways to call this method:
172 # * with a String: textilizable(text, options)
178 # * with a String: textilizable(text, options)
173 # * with an object and one of its attribute: textilizable(issue, :description, options)
179 # * with an object and one of its attribute: textilizable(issue, :description, options)
174 def textilizable(*args)
180 def textilizable(*args)
175 options = args.last.is_a?(Hash) ? args.pop : {}
181 options = args.last.is_a?(Hash) ? args.pop : {}
176 case args.size
182 case args.size
177 when 1
183 when 1
178 obj = nil
184 obj = nil
179 text = args.shift || ''
185 text = args.shift || ''
180 when 2
186 when 2
181 obj = args.shift
187 obj = args.shift
182 text = obj.send(args.shift)
188 text = obj.send(args.shift)
183 else
189 else
184 raise ArgumentError, 'invalid arguments to textilizable'
190 raise ArgumentError, 'invalid arguments to textilizable'
185 end
191 end
186
192
187 # when using an image link, try to use an attachment, if possible
193 # when using an image link, try to use an attachment, if possible
188 attachments = options[:attachments]
194 attachments = options[:attachments]
189 if attachments
195 if attachments
190 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
196 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
191 style = $1
197 style = $1
192 filename = $6
198 filename = $6
193 rf = Regexp.new(filename, Regexp::IGNORECASE)
199 rf = Regexp.new(filename, Regexp::IGNORECASE)
194 # search for the picture in attachments
200 # search for the picture in attachments
195 if found = attachments.detect { |att| att.filename =~ rf }
201 if found = attachments.detect { |att| att.filename =~ rf }
196 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
202 image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
197 "!#{style}#{image_url}!"
203 "!#{style}#{image_url}!"
198 else
204 else
199 "!#{style}#{filename}!"
205 "!#{style}#{filename}!"
200 end
206 end
201 end
207 end
202 end
208 end
203
209
204 text = (Setting.text_formatting == 'textile') ?
210 text = (Setting.text_formatting == 'textile') ?
205 Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
211 Redmine::WikiFormatting.to_html(text) { |macro, args| exec_macro(macro, obj, args) } :
206 simple_format(auto_link(h(text)))
212 simple_format(auto_link(h(text)))
207
213
208 # different methods for formatting wiki links
214 # different methods for formatting wiki links
209 case options[:wiki_links]
215 case options[:wiki_links]
210 when :local
216 when :local
211 # used for local links to html files
217 # used for local links to html files
212 format_wiki_link = Proc.new {|project, title| "#{title}.html" }
218 format_wiki_link = Proc.new {|project, title| "#{title}.html" }
213 when :anchor
219 when :anchor
214 # used for single-file wiki export
220 # used for single-file wiki export
215 format_wiki_link = Proc.new {|project, title| "##{title}" }
221 format_wiki_link = Proc.new {|project, title| "##{title}" }
216 else
222 else
217 format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
223 format_wiki_link = Proc.new {|project, title| url_for :controller => 'wiki', :action => 'index', :id => project, :page => title }
218 end
224 end
219
225
220 project = options[:project] || @project
226 project = options[:project] || @project
221
227
222 # Wiki links
228 # Wiki links
223 #
229 #
224 # Examples:
230 # Examples:
225 # [[mypage]]
231 # [[mypage]]
226 # [[mypage|mytext]]
232 # [[mypage|mytext]]
227 # wiki links can refer other project wikis, using project name or identifier:
233 # wiki links can refer other project wikis, using project name or identifier:
228 # [[project:]] -> wiki starting page
234 # [[project:]] -> wiki starting page
229 # [[project:|mytext]]
235 # [[project:|mytext]]
230 # [[project:mypage]]
236 # [[project:mypage]]
231 # [[project:mypage|mytext]]
237 # [[project:mypage|mytext]]
232 text = text.gsub(/(!)?(\[\[([^\]\|]+)(\|([^\]\|]+))?\]\])/) do |m|
238 text = text.gsub(/(!)?(\[\[([^\]\|]+)(\|([^\]\|]+))?\]\])/) do |m|
233 link_project = project
239 link_project = project
234 esc, all, page, title = $1, $2, $3, $5
240 esc, all, page, title = $1, $2, $3, $5
235 if esc.nil?
241 if esc.nil?
236 if page =~ /^([^\:]+)\:(.*)$/
242 if page =~ /^([^\:]+)\:(.*)$/
237 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
243 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
238 page = $2
244 page = $2
239 title ||= $1 if page.blank?
245 title ||= $1 if page.blank?
240 end
246 end
241
247
242 if link_project && link_project.wiki
248 if link_project && link_project.wiki
243 # check if page exists
249 # check if page exists
244 wiki_page = link_project.wiki.find_page(page)
250 wiki_page = link_project.wiki.find_page(page)
245 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
251 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page)),
246 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
252 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
247 else
253 else
248 # project or wiki doesn't exist
254 # project or wiki doesn't exist
249 title || page
255 title || page
250 end
256 end
251 else
257 else
252 all
258 all
253 end
259 end
254 end
260 end
255
261
256 # Redmine links
262 # Redmine links
257 #
263 #
258 # Examples:
264 # Examples:
259 # Issues:
265 # Issues:
260 # #52 -> Link to issue #52
266 # #52 -> Link to issue #52
261 # Changesets:
267 # Changesets:
262 # r52 -> Link to revision 52
268 # r52 -> Link to revision 52
263 # Documents:
269 # Documents:
264 # document#17 -> Link to document with id 17
270 # document#17 -> Link to document with id 17
265 # document:Greetings -> Link to the document with title "Greetings"
271 # document:Greetings -> Link to the document with title "Greetings"
266 # document:"Some document" -> Link to the document with title "Some document"
272 # document:"Some document" -> Link to the document with title "Some document"
267 # Versions:
273 # Versions:
268 # version#3 -> Link to version with id 3
274 # version#3 -> Link to version with id 3
269 # version:1.0.0 -> Link to version named "1.0.0"
275 # version:1.0.0 -> Link to version named "1.0.0"
270 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
276 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
271 # Attachments:
277 # Attachments:
272 # attachment:file.zip -> Link to the attachment of the current object named file.zip
278 # attachment:file.zip -> Link to the attachment of the current object named file.zip
273 text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
279 text = text.gsub(%r{([\s\(,-^])(!)?(attachment|document|version)?((#|r)(\d+)|(:)([^"][^\s<>]+|"[^"]+"))(?=[[:punct:]]|\s|<|$)}) do |m|
274 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
280 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
275 link = nil
281 link = nil
276 if esc.nil?
282 if esc.nil?
277 if prefix.nil? && sep == 'r'
283 if prefix.nil? && sep == 'r'
278 if project && (changeset = project.changesets.find_by_revision(oid))
284 if project && (changeset = project.changesets.find_by_revision(oid))
279 link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset',
285 link = link_to("r#{oid}", {:controller => 'repositories', :action => 'revision', :id => project.id, :rev => oid}, :class => 'changeset',
280 :title => truncate(changeset.comments, 100))
286 :title => truncate(changeset.comments, 100))
281 end
287 end
282 elsif sep == '#'
288 elsif sep == '#'
283 oid = oid.to_i
289 oid = oid.to_i
284 case prefix
290 case prefix
285 when nil
291 when nil
286 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
292 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
287 link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue',
293 link = link_to("##{oid}", {:controller => 'issues', :action => 'show', :id => oid}, :class => 'issue',
288 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
294 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
289 link = content_tag('del', link) if issue.closed?
295 link = content_tag('del', link) if issue.closed?
290 end
296 end
291 when 'document'
297 when 'document'
292 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
298 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
293 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
299 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
294 end
300 end
295 when 'version'
301 when 'version'
296 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
302 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
297 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
303 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
298 end
304 end
299 end
305 end
300 elsif sep == ':'
306 elsif sep == ':'
301 # removes the double quotes if any
307 # removes the double quotes if any
302 name = oid.gsub(%r{^"(.*)"$}, "\\1")
308 name = oid.gsub(%r{^"(.*)"$}, "\\1")
303 case prefix
309 case prefix
304 when 'document'
310 when 'document'
305 if project && document = project.documents.find_by_title(name)
311 if project && document = project.documents.find_by_title(name)
306 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
312 link = link_to h(document.title), {:controller => 'documents', :action => 'show', :id => document}, :class => 'document'
307 end
313 end
308 when 'version'
314 when 'version'
309 if project && version = project.versions.find_by_name(name)
315 if project && version = project.versions.find_by_name(name)
310 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
316 link = link_to h(version.name), {:controller => 'versions', :action => 'show', :id => version}, :class => 'version'
311 end
317 end
312 when 'attachment'
318 when 'attachment'
313 if attachments && attachment = attachments.detect {|a| a.filename == name }
319 if attachments && attachment = attachments.detect {|a| a.filename == name }
314 link = link_to h(attachment.filename), {:controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment'
320 link = link_to h(attachment.filename), {:controller => 'attachments', :action => 'download', :id => attachment}, :class => 'attachment'
315 end
321 end
316 end
322 end
317 end
323 end
318 end
324 end
319 leading + (link || "#{prefix}#{sep}#{oid}")
325 leading + (link || "#{prefix}#{sep}#{oid}")
320 end
326 end
321
327
322 text
328 text
323 end
329 end
324
330
325 # Same as Rails' simple_format helper without using paragraphs
331 # Same as Rails' simple_format helper without using paragraphs
326 def simple_format_without_paragraph(text)
332 def simple_format_without_paragraph(text)
327 text.to_s.
333 text.to_s.
328 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
334 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
329 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
335 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
330 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
336 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
331 end
337 end
332
338
333 def error_messages_for(object_name, options = {})
339 def error_messages_for(object_name, options = {})
334 options = options.symbolize_keys
340 options = options.symbolize_keys
335 object = instance_variable_get("@#{object_name}")
341 object = instance_variable_get("@#{object_name}")
336 if object && !object.errors.empty?
342 if object && !object.errors.empty?
337 # build full_messages here with controller current language
343 # build full_messages here with controller current language
338 full_messages = []
344 full_messages = []
339 object.errors.each do |attr, msg|
345 object.errors.each do |attr, msg|
340 next if msg.nil?
346 next if msg.nil?
341 msg = msg.first if msg.is_a? Array
347 msg = msg.first if msg.is_a? Array
342 if attr == "base"
348 if attr == "base"
343 full_messages << l(msg)
349 full_messages << l(msg)
344 else
350 else
345 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
351 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
346 end
352 end
347 end
353 end
348 # retrieve custom values error messages
354 # retrieve custom values error messages
349 if object.errors[:custom_values]
355 if object.errors[:custom_values]
350 object.custom_values.each do |v|
356 object.custom_values.each do |v|
351 v.errors.each do |attr, msg|
357 v.errors.each do |attr, msg|
352 next if msg.nil?
358 next if msg.nil?
353 msg = msg.first if msg.is_a? Array
359 msg = msg.first if msg.is_a? Array
354 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
360 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
355 end
361 end
356 end
362 end
357 end
363 end
358 content_tag("div",
364 content_tag("div",
359 content_tag(
365 content_tag(
360 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
366 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
361 ) +
367 ) +
362 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
368 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
363 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
369 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
364 )
370 )
365 else
371 else
366 ""
372 ""
367 end
373 end
368 end
374 end
369
375
370 def lang_options_for_select(blank=true)
376 def lang_options_for_select(blank=true)
371 (blank ? [["(auto)", ""]] : []) +
377 (blank ? [["(auto)", ""]] : []) +
372 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
378 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
373 end
379 end
374
380
375 def label_tag_for(name, option_tags = nil, options = {})
381 def label_tag_for(name, option_tags = nil, options = {})
376 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
382 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
377 content_tag("label", label_text)
383 content_tag("label", label_text)
378 end
384 end
379
385
380 def labelled_tabular_form_for(name, object, options, &proc)
386 def labelled_tabular_form_for(name, object, options, &proc)
381 options[:html] ||= {}
387 options[:html] ||= {}
382 options[:html].store :class, "tabular"
388 options[:html].store :class, "tabular"
383 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
389 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
384 end
390 end
385
391
386 def check_all_links(form_name)
392 def check_all_links(form_name)
387 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
393 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
388 " | " +
394 " | " +
389 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
395 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
390 end
396 end
391
397
392 def progress_bar(pcts, options={})
398 def progress_bar(pcts, options={})
393 pcts = [pcts, pcts] unless pcts.is_a?(Array)
399 pcts = [pcts, pcts] unless pcts.is_a?(Array)
394 pcts[1] = pcts[1] - pcts[0]
400 pcts[1] = pcts[1] - pcts[0]
395 pcts << (100 - pcts[1] - pcts[0])
401 pcts << (100 - pcts[1] - pcts[0])
396 width = options[:width] || '100px;'
402 width = options[:width] || '100px;'
397 legend = options[:legend] || ''
403 legend = options[:legend] || ''
398 content_tag('table',
404 content_tag('table',
399 content_tag('tr',
405 content_tag('tr',
400 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
406 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
401 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
407 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
402 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
408 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
403 ), :class => 'progress', :style => "width: #{width};") +
409 ), :class => 'progress', :style => "width: #{width};") +
404 content_tag('p', legend, :class => 'pourcent')
410 content_tag('p', legend, :class => 'pourcent')
405 end
411 end
406
412
407 def context_menu_link(name, url, options={})
413 def context_menu_link(name, url, options={})
408 options[:class] ||= ''
414 options[:class] ||= ''
409 if options.delete(:selected)
415 if options.delete(:selected)
410 options[:class] << ' icon-checked disabled'
416 options[:class] << ' icon-checked disabled'
411 options[:disabled] = true
417 options[:disabled] = true
412 end
418 end
413 if options.delete(:disabled)
419 if options.delete(:disabled)
414 options.delete(:method)
420 options.delete(:method)
415 options.delete(:confirm)
421 options.delete(:confirm)
416 options.delete(:onclick)
422 options.delete(:onclick)
417 options[:class] << ' disabled'
423 options[:class] << ' disabled'
418 url = '#'
424 url = '#'
419 end
425 end
420 link_to name, url, options
426 link_to name, url, options
421 end
427 end
422
428
423 def calendar_for(field_id)
429 def calendar_for(field_id)
424 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
430 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
425 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
431 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
426 end
432 end
427
433
428 def wikitoolbar_for(field_id)
434 def wikitoolbar_for(field_id)
429 return '' unless Setting.text_formatting == 'textile'
435 return '' unless Setting.text_formatting == 'textile'
430 javascript_include_tag('jstoolbar/jstoolbar') +
436 javascript_include_tag('jstoolbar/jstoolbar') +
431 javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") +
437 javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language}") +
432 javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();")
438 javascript_tag("var toolbar = new jsToolBar($('#{field_id}')); toolbar.draw();")
433 end
439 end
434
440
435 def content_for(name, content = nil, &block)
441 def content_for(name, content = nil, &block)
436 @has_content ||= {}
442 @has_content ||= {}
437 @has_content[name] = true
443 @has_content[name] = true
438 super(name, content, &block)
444 super(name, content, &block)
439 end
445 end
440
446
441 def has_content?(name)
447 def has_content?(name)
442 (@has_content && @has_content[name]) || false
448 (@has_content && @has_content[name]) || false
443 end
449 end
444 end
450 end
General Comments 0
You need to be logged in to leave comments. Login now