##// END OF EJS Templates
Adds link to user's account on issue history....
Jean-Philippe Lang -
r2071:0b2299c7d1ef
parent child
Show More
@@ -1,617 +1,617
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require 'coderay'
19 19 require 'coderay/helpers/file_type'
20 20 require 'forwardable'
21 21
22 22 module ApplicationHelper
23 23 include Redmine::WikiFormatting::Macros::Definitions
24 24 include GravatarHelper::PublicMethods
25 25
26 26 extend Forwardable
27 27 def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter
28 28
29 29 def current_role
30 30 @current_role ||= User.current.role_for_project(@project)
31 31 end
32 32
33 33 # Return true if user is authorized for controller/action, otherwise false
34 34 def authorize_for(controller, action)
35 35 User.current.allowed_to?({:controller => controller, :action => action}, @project)
36 36 end
37 37
38 38 # Display a link if user is authorized
39 39 def link_to_if_authorized(name, options = {}, html_options = nil, *parameters_for_method_reference)
40 40 link_to(name, options, html_options, *parameters_for_method_reference) if authorize_for(options[:controller] || params[:controller], options[:action])
41 41 end
42 42
43 43 # Display a link to remote if user is authorized
44 44 def link_to_remote_if_authorized(name, options = {}, html_options = nil)
45 45 url = options[:url] || {}
46 46 link_to_remote(name, options, html_options) if authorize_for(url[:controller] || params[:controller], url[:action])
47 47 end
48 48
49 49 # Display a link to user's account page
50 50 def link_to_user(user)
51 user ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
51 (user && !user.anonymous?) ? link_to(user, :controller => 'account', :action => 'show', :id => user) : 'Anonymous'
52 52 end
53 53
54 54 def link_to_issue(issue, options={})
55 55 options[:class] ||= ''
56 56 options[:class] << ' issue'
57 57 options[:class] << ' closed' if issue.closed?
58 58 link_to "#{issue.tracker.name} ##{issue.id}", {:controller => "issues", :action => "show", :id => issue}, options
59 59 end
60 60
61 61 # Generates a link to an attachment.
62 62 # Options:
63 63 # * :text - Link text (default to attachment filename)
64 64 # * :download - Force download (default: false)
65 65 def link_to_attachment(attachment, options={})
66 66 text = options.delete(:text) || attachment.filename
67 67 action = options.delete(:download) ? 'download' : 'show'
68 68
69 69 link_to(h(text), {:controller => 'attachments', :action => action, :id => attachment, :filename => attachment.filename }, options)
70 70 end
71 71
72 72 def toggle_link(name, id, options={})
73 73 onclick = "Element.toggle('#{id}'); "
74 74 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ")
75 75 onclick << "return false;"
76 76 link_to(name, "#", :onclick => onclick)
77 77 end
78 78
79 79 def image_to_function(name, function, html_options = {})
80 80 html_options.symbolize_keys!
81 81 tag(:input, html_options.merge({
82 82 :type => "image", :src => image_path(name),
83 83 :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};"
84 84 }))
85 85 end
86 86
87 87 def prompt_to_remote(name, text, param, url, html_options = {})
88 88 html_options[:onclick] = "promptToRemote('#{text}', '#{param}', '#{url_for(url)}'); return false;"
89 89 link_to name, {}, html_options
90 90 end
91 91
92 92 def format_date(date)
93 93 return nil unless date
94 94 # "Setting.date_format.size < 2" is a temporary fix (content of date_format setting changed)
95 95 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
96 96 date.strftime(@date_format)
97 97 end
98 98
99 99 def format_time(time, include_date = true)
100 100 return nil unless time
101 101 time = time.to_time if time.is_a?(String)
102 102 zone = User.current.time_zone
103 103 local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
104 104 @date_format ||= (Setting.date_format.blank? || Setting.date_format.size < 2 ? l(:general_fmt_date) : Setting.date_format)
105 105 @time_format ||= (Setting.time_format.blank? ? l(:general_fmt_time) : Setting.time_format)
106 106 include_date ? local.strftime("#{@date_format} #{@time_format}") : local.strftime(@time_format)
107 107 end
108 108
109 109 def format_activity_title(text)
110 110 h(truncate_single_line(text, 100))
111 111 end
112 112
113 113 def format_activity_day(date)
114 114 date == Date.today ? l(:label_today).titleize : format_date(date)
115 115 end
116 116
117 117 def format_activity_description(text)
118 118 h(truncate(text.to_s, 250).gsub(%r{<(pre|code)>.*$}m, '...'))
119 119 end
120 120
121 121 def distance_of_date_in_words(from_date, to_date = 0)
122 122 from_date = from_date.to_date if from_date.respond_to?(:to_date)
123 123 to_date = to_date.to_date if to_date.respond_to?(:to_date)
124 124 distance_in_days = (to_date - from_date).abs
125 125 lwr(:actionview_datehelper_time_in_words_day, distance_in_days)
126 126 end
127 127
128 128 def due_date_distance_in_words(date)
129 129 if date
130 130 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
131 131 end
132 132 end
133 133
134 134 def render_page_hierarchy(pages, node=nil)
135 135 content = ''
136 136 if pages[node]
137 137 content << "<ul class=\"pages-hierarchy\">\n"
138 138 pages[node].each do |page|
139 139 content << "<li>"
140 140 content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :id => page.project, :page => page.title},
141 141 :title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
142 142 content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
143 143 content << "</li>\n"
144 144 end
145 145 content << "</ul>\n"
146 146 end
147 147 content
148 148 end
149 149
150 150 # Truncates and returns the string as a single line
151 151 def truncate_single_line(string, *args)
152 152 truncate(string, *args).gsub(%r{[\r\n]+}m, ' ')
153 153 end
154 154
155 155 def html_hours(text)
156 156 text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
157 157 end
158 158
159 159 def authoring(created, author)
160 160 time_tag = @project.nil? ? content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created)) :
161 161 link_to(distance_of_time_in_words(Time.now, created),
162 162 {:controller => 'projects', :action => 'activity', :id => @project, :from => created.to_date},
163 163 :title => format_time(created))
164 164 author_tag = (author.is_a?(User) && !author.anonymous?) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous')
165 165 l(:label_added_time_by, author_tag, time_tag)
166 166 end
167 167
168 168 def l_or_humanize(s, options={})
169 169 k = "#{options[:prefix]}#{s}".to_sym
170 170 l_has_string?(k) ? l(k) : s.to_s.humanize
171 171 end
172 172
173 173 def day_name(day)
174 174 l(:general_day_names).split(',')[day-1]
175 175 end
176 176
177 177 def month_name(month)
178 178 l(:actionview_datehelper_select_month_names).split(',')[month-1]
179 179 end
180 180
181 181 def syntax_highlight(name, content)
182 182 type = CodeRay::FileType[name]
183 183 type ? CodeRay.scan(content, type).html : h(content)
184 184 end
185 185
186 186 def to_path_param(path)
187 187 path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
188 188 end
189 189
190 190 def pagination_links_full(paginator, count=nil, options={})
191 191 page_param = options.delete(:page_param) || :page
192 192 url_param = params.dup
193 193 # don't reuse params if filters are present
194 194 url_param.clear if url_param.has_key?(:set_filter)
195 195
196 196 html = ''
197 197 html << link_to_remote(('&#171; ' + l(:label_previous)),
198 198 {:update => 'content',
199 199 :url => url_param.merge(page_param => paginator.current.previous),
200 200 :complete => 'window.scrollTo(0,0)'},
201 201 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
202 202
203 203 html << (pagination_links_each(paginator, options) do |n|
204 204 link_to_remote(n.to_s,
205 205 {:url => {:params => url_param.merge(page_param => n)},
206 206 :update => 'content',
207 207 :complete => 'window.scrollTo(0,0)'},
208 208 {:href => url_for(:params => url_param.merge(page_param => n))})
209 209 end || '')
210 210
211 211 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
212 212 {:update => 'content',
213 213 :url => url_param.merge(page_param => paginator.current.next),
214 214 :complete => 'window.scrollTo(0,0)'},
215 215 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
216 216
217 217 unless count.nil?
218 218 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
219 219 end
220 220
221 221 html
222 222 end
223 223
224 224 def per_page_links(selected=nil)
225 225 url_param = params.dup
226 226 url_param.clear if url_param.has_key?(:set_filter)
227 227
228 228 links = Setting.per_page_options_array.collect do |n|
229 229 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
230 230 {:href => url_for(url_param.merge(:per_page => n))})
231 231 end
232 232 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
233 233 end
234 234
235 235 def breadcrumb(*args)
236 236 elements = args.flatten
237 237 elements.any? ? content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb') : nil
238 238 end
239 239
240 240 def html_title(*args)
241 241 if args.empty?
242 242 title = []
243 243 title << @project.name if @project
244 244 title += @html_title if @html_title
245 245 title << Setting.app_title
246 246 title.compact.join(' - ')
247 247 else
248 248 @html_title ||= []
249 249 @html_title += args
250 250 end
251 251 end
252 252
253 253 def accesskey(s)
254 254 Redmine::AccessKeys.key_for s
255 255 end
256 256
257 257 # Formats text according to system settings.
258 258 # 2 ways to call this method:
259 259 # * with a String: textilizable(text, options)
260 260 # * with an object and one of its attribute: textilizable(issue, :description, options)
261 261 def textilizable(*args)
262 262 options = args.last.is_a?(Hash) ? args.pop : {}
263 263 case args.size
264 264 when 1
265 265 obj = options[:object]
266 266 text = args.shift
267 267 when 2
268 268 obj = args.shift
269 269 text = obj.send(args.shift).to_s
270 270 else
271 271 raise ArgumentError, 'invalid arguments to textilizable'
272 272 end
273 273 return '' if text.blank?
274 274
275 275 only_path = options.delete(:only_path) == false ? false : true
276 276
277 277 # when using an image link, try to use an attachment, if possible
278 278 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
279 279
280 280 if attachments
281 281 attachments = attachments.sort_by(&:created_on).reverse
282 282 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m|
283 283 style = $1
284 284 filename = $6
285 285 rf = Regexp.new(Regexp.escape(filename), Regexp::IGNORECASE)
286 286 # search for the picture in attachments
287 287 if found = attachments.detect { |att| att.filename =~ rf }
288 288 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
289 289 desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1")
290 290 alt = desc.blank? ? nil : "(#{desc})"
291 291 "!#{style}#{image_url}#{alt}!"
292 292 else
293 293 "!#{style}#{filename}!"
294 294 end
295 295 end
296 296 end
297 297
298 298 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) }
299 299
300 300 # different methods for formatting wiki links
301 301 case options[:wiki_links]
302 302 when :local
303 303 # used for local links to html files
304 304 format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" }
305 305 when :anchor
306 306 # used for single-file wiki export
307 307 format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
308 308 else
309 309 format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
310 310 end
311 311
312 312 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
313 313
314 314 # Wiki links
315 315 #
316 316 # Examples:
317 317 # [[mypage]]
318 318 # [[mypage|mytext]]
319 319 # wiki links can refer other project wikis, using project name or identifier:
320 320 # [[project:]] -> wiki starting page
321 321 # [[project:|mytext]]
322 322 # [[project:mypage]]
323 323 # [[project:mypage|mytext]]
324 324 text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
325 325 link_project = project
326 326 esc, all, page, title = $1, $2, $3, $5
327 327 if esc.nil?
328 328 if page =~ /^([^\:]+)\:(.*)$/
329 329 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
330 330 page = $2
331 331 title ||= $1 if page.blank?
332 332 end
333 333
334 334 if link_project && link_project.wiki
335 335 # extract anchor
336 336 anchor = nil
337 337 if page =~ /^(.+?)\#(.+)$/
338 338 page, anchor = $1, $2
339 339 end
340 340 # check if page exists
341 341 wiki_page = link_project.wiki.find_page(page)
342 342 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
343 343 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
344 344 else
345 345 # project or wiki doesn't exist
346 346 title || page
347 347 end
348 348 else
349 349 all
350 350 end
351 351 end
352 352
353 353 # Redmine links
354 354 #
355 355 # Examples:
356 356 # Issues:
357 357 # #52 -> Link to issue #52
358 358 # Changesets:
359 359 # r52 -> Link to revision 52
360 360 # commit:a85130f -> Link to scmid starting with a85130f
361 361 # Documents:
362 362 # document#17 -> Link to document with id 17
363 363 # document:Greetings -> Link to the document with title "Greetings"
364 364 # document:"Some document" -> Link to the document with title "Some document"
365 365 # Versions:
366 366 # version#3 -> Link to version with id 3
367 367 # version:1.0.0 -> Link to version named "1.0.0"
368 368 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
369 369 # Attachments:
370 370 # attachment:file.zip -> Link to the attachment of the current object named file.zip
371 371 # Source files:
372 372 # source:some/file -> Link to the file located at /some/file in the project's repository
373 373 # source:some/file@52 -> Link to the file's revision 52
374 374 # source:some/file#L120 -> Link to line 120 of the file
375 375 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
376 376 # export:some/file -> Force the download of the file
377 377 # Forum messages:
378 378 # message#1218 -> Link to message with id 1218
379 379 text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
380 380 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
381 381 link = nil
382 382 if esc.nil?
383 383 if prefix.nil? && sep == 'r'
384 384 if project && (changeset = project.changesets.find_by_revision(oid))
385 385 link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
386 386 :class => 'changeset',
387 387 :title => truncate_single_line(changeset.comments, 100))
388 388 end
389 389 elsif sep == '#'
390 390 oid = oid.to_i
391 391 case prefix
392 392 when nil
393 393 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
394 394 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
395 395 :class => (issue.closed? ? 'issue closed' : 'issue'),
396 396 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
397 397 link = content_tag('del', link) if issue.closed?
398 398 end
399 399 when 'document'
400 400 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
401 401 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
402 402 :class => 'document'
403 403 end
404 404 when 'version'
405 405 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
406 406 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
407 407 :class => 'version'
408 408 end
409 409 when 'message'
410 410 if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
411 411 link = link_to h(truncate(message.subject, 60)), {:only_path => only_path,
412 412 :controller => 'messages',
413 413 :action => 'show',
414 414 :board_id => message.board,
415 415 :id => message.root,
416 416 :anchor => (message.parent ? "message-#{message.id}" : nil)},
417 417 :class => 'message'
418 418 end
419 419 end
420 420 elsif sep == ':'
421 421 # removes the double quotes if any
422 422 name = oid.gsub(%r{^"(.*)"$}, "\\1")
423 423 case prefix
424 424 when 'document'
425 425 if project && document = project.documents.find_by_title(name)
426 426 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
427 427 :class => 'document'
428 428 end
429 429 when 'version'
430 430 if project && version = project.versions.find_by_name(name)
431 431 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
432 432 :class => 'version'
433 433 end
434 434 when 'commit'
435 435 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
436 436 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
437 437 :class => 'changeset',
438 438 :title => truncate_single_line(changeset.comments, 100)
439 439 end
440 440 when 'source', 'export'
441 441 if project && project.repository
442 442 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
443 443 path, rev, anchor = $1, $3, $5
444 444 link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
445 445 :path => to_path_param(path),
446 446 :rev => rev,
447 447 :anchor => anchor,
448 448 :format => (prefix == 'export' ? 'raw' : nil)},
449 449 :class => (prefix == 'export' ? 'source download' : 'source')
450 450 end
451 451 when 'attachment'
452 452 if attachments && attachment = attachments.detect {|a| a.filename == name }
453 453 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
454 454 :class => 'attachment'
455 455 end
456 456 end
457 457 end
458 458 end
459 459 leading + (link || "#{prefix}#{sep}#{oid}")
460 460 end
461 461
462 462 text
463 463 end
464 464
465 465 # Same as Rails' simple_format helper without using paragraphs
466 466 def simple_format_without_paragraph(text)
467 467 text.to_s.
468 468 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
469 469 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
470 470 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
471 471 end
472 472
473 473 def error_messages_for(object_name, options = {})
474 474 options = options.symbolize_keys
475 475 object = instance_variable_get("@#{object_name}")
476 476 if object && !object.errors.empty?
477 477 # build full_messages here with controller current language
478 478 full_messages = []
479 479 object.errors.each do |attr, msg|
480 480 next if msg.nil?
481 481 msg = msg.first if msg.is_a? Array
482 482 if attr == "base"
483 483 full_messages << l(msg)
484 484 else
485 485 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
486 486 end
487 487 end
488 488 # retrieve custom values error messages
489 489 if object.errors[:custom_values]
490 490 object.custom_values.each do |v|
491 491 v.errors.each do |attr, msg|
492 492 next if msg.nil?
493 493 msg = msg.first if msg.is_a? Array
494 494 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
495 495 end
496 496 end
497 497 end
498 498 content_tag("div",
499 499 content_tag(
500 500 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
501 501 ) +
502 502 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
503 503 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
504 504 )
505 505 else
506 506 ""
507 507 end
508 508 end
509 509
510 510 def lang_options_for_select(blank=true)
511 511 (blank ? [["(auto)", ""]] : []) +
512 512 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
513 513 end
514 514
515 515 def label_tag_for(name, option_tags = nil, options = {})
516 516 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
517 517 content_tag("label", label_text)
518 518 end
519 519
520 520 def labelled_tabular_form_for(name, object, options, &proc)
521 521 options[:html] ||= {}
522 522 options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
523 523 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
524 524 end
525 525
526 526 def back_url_hidden_field_tag
527 527 back_url = params[:back_url] || request.env['HTTP_REFERER']
528 528 hidden_field_tag('back_url', back_url) unless back_url.blank?
529 529 end
530 530
531 531 def check_all_links(form_name)
532 532 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
533 533 " | " +
534 534 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
535 535 end
536 536
537 537 def progress_bar(pcts, options={})
538 538 pcts = [pcts, pcts] unless pcts.is_a?(Array)
539 539 pcts[1] = pcts[1] - pcts[0]
540 540 pcts << (100 - pcts[1] - pcts[0])
541 541 width = options[:width] || '100px;'
542 542 legend = options[:legend] || ''
543 543 content_tag('table',
544 544 content_tag('tr',
545 545 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
546 546 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
547 547 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
548 548 ), :class => 'progress', :style => "width: #{width};") +
549 549 content_tag('p', legend, :class => 'pourcent')
550 550 end
551 551
552 552 def context_menu_link(name, url, options={})
553 553 options[:class] ||= ''
554 554 if options.delete(:selected)
555 555 options[:class] << ' icon-checked disabled'
556 556 options[:disabled] = true
557 557 end
558 558 if options.delete(:disabled)
559 559 options.delete(:method)
560 560 options.delete(:confirm)
561 561 options.delete(:onclick)
562 562 options[:class] << ' disabled'
563 563 url = '#'
564 564 end
565 565 link_to name, url, options
566 566 end
567 567
568 568 def calendar_for(field_id)
569 569 include_calendar_headers_tags
570 570 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
571 571 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
572 572 end
573 573
574 574 def include_calendar_headers_tags
575 575 unless @calendar_headers_tags_included
576 576 @calendar_headers_tags_included = true
577 577 content_for :header_tags do
578 578 javascript_include_tag('calendar/calendar') +
579 579 javascript_include_tag("calendar/lang/calendar-#{current_language}.js") +
580 580 javascript_include_tag('calendar/calendar-setup') +
581 581 stylesheet_link_tag('calendar')
582 582 end
583 583 end
584 584 end
585 585
586 586 def content_for(name, content = nil, &block)
587 587 @has_content ||= {}
588 588 @has_content[name] = true
589 589 super(name, content, &block)
590 590 end
591 591
592 592 def has_content?(name)
593 593 (@has_content && @has_content[name]) || false
594 594 end
595 595
596 596 # Returns the avatar image tag for the given +user+ if avatars are enabled
597 597 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
598 598 def avatar(user, options = { })
599 599 if Setting.gravatar_enabled?
600 600 email = nil
601 601 if user.respond_to?(:mail)
602 602 email = user.mail
603 603 elsif user.to_s =~ %r{<(.+?)>}
604 604 email = $1
605 605 end
606 606 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
607 607 end
608 608 end
609 609
610 610 private
611 611
612 612 def wiki_helper
613 613 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
614 614 extend helper
615 615 return self
616 616 end
617 617 end
@@ -1,15 +1,15
1 1 <% reply_links = authorize_for('issues', 'edit') -%>
2 2 <% for journal in journals %>
3 3 <div id="change-<%= journal.id %>" class="journal">
4 4 <h4><div style="float:right;"><%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %></div>
5 5 <%= content_tag('a', '', :name => "note-#{journal.indice}")%>
6 <%= format_time(journal.created_on) %> - <%= journal.user.name %></h4>
6 <%= format_time(journal.created_on) %> - <%= link_to_user(journal.user) %></h4>
7 7 <%= avatar(journal.user, :size => "32") %>
8 8 <ul>
9 9 <% for detail in journal.details %>
10 10 <li><%= show_detail(detail) %></li>
11 11 <% end %>
12 12 </ul>
13 13 <%= render_notes(journal, :reply_links => reply_links) unless journal.notes.blank? %>
14 14 </div>
15 15 <% end %>
General Comments 0
You need to be logged in to leave comments. Login now