##// END OF EJS Templates
Link to activity view when displaying dates....
Jean-Philippe Lang -
r2000:57a4ee318af9
parent child
Show More
@@ -1,586 +1,589
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 51 user ? 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 distance_of_date_in_words(from_date, to_date = 0)
110 110 from_date = from_date.to_date if from_date.respond_to?(:to_date)
111 111 to_date = to_date.to_date if to_date.respond_to?(:to_date)
112 112 distance_in_days = (to_date - from_date).abs
113 113 lwr(:actionview_datehelper_time_in_words_day, distance_in_days)
114 114 end
115 115
116 116 def due_date_distance_in_words(date)
117 117 if date
118 118 l((date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in), distance_of_date_in_words(Date.today, date))
119 119 end
120 120 end
121 121
122 122 # Truncates and returns the string as a single line
123 123 def truncate_single_line(string, *args)
124 124 truncate(string, *args).gsub(%r{[\r\n]+}m, ' ')
125 125 end
126 126
127 127 def html_hours(text)
128 128 text.gsub(%r{(\d+)\.(\d+)}, '<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>')
129 129 end
130 130
131 131 def authoring(created, author)
132 time_tag = content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created))
132 time_tag = @project.nil? ? content_tag('acronym', distance_of_time_in_words(Time.now, created), :title => format_time(created)) :
133 link_to(distance_of_time_in_words(Time.now, created),
134 {:controller => 'projects', :action => 'activity', :id => @project, :from => created.to_date},
135 :title => format_time(created))
133 136 author_tag = (author.is_a?(User) && !author.anonymous?) ? link_to(h(author), :controller => 'account', :action => 'show', :id => author) : h(author || 'Anonymous')
134 137 l(:label_added_time_by, author_tag, time_tag)
135 138 end
136 139
137 140 def l_or_humanize(s, options={})
138 141 k = "#{options[:prefix]}#{s}".to_sym
139 142 l_has_string?(k) ? l(k) : s.to_s.humanize
140 143 end
141 144
142 145 def day_name(day)
143 146 l(:general_day_names).split(',')[day-1]
144 147 end
145 148
146 149 def month_name(month)
147 150 l(:actionview_datehelper_select_month_names).split(',')[month-1]
148 151 end
149 152
150 153 def syntax_highlight(name, content)
151 154 type = CodeRay::FileType[name]
152 155 type ? CodeRay.scan(content, type).html : h(content)
153 156 end
154 157
155 158 def to_path_param(path)
156 159 path.to_s.split(%r{[/\\]}).select {|p| !p.blank?}
157 160 end
158 161
159 162 def pagination_links_full(paginator, count=nil, options={})
160 163 page_param = options.delete(:page_param) || :page
161 164 url_param = params.dup
162 165 # don't reuse params if filters are present
163 166 url_param.clear if url_param.has_key?(:set_filter)
164 167
165 168 html = ''
166 169 html << link_to_remote(('&#171; ' + l(:label_previous)),
167 170 {:update => 'content',
168 171 :url => url_param.merge(page_param => paginator.current.previous),
169 172 :complete => 'window.scrollTo(0,0)'},
170 173 {:href => url_for(:params => url_param.merge(page_param => paginator.current.previous))}) + ' ' if paginator.current.previous
171 174
172 175 html << (pagination_links_each(paginator, options) do |n|
173 176 link_to_remote(n.to_s,
174 177 {:url => {:params => url_param.merge(page_param => n)},
175 178 :update => 'content',
176 179 :complete => 'window.scrollTo(0,0)'},
177 180 {:href => url_for(:params => url_param.merge(page_param => n))})
178 181 end || '')
179 182
180 183 html << ' ' + link_to_remote((l(:label_next) + ' &#187;'),
181 184 {:update => 'content',
182 185 :url => url_param.merge(page_param => paginator.current.next),
183 186 :complete => 'window.scrollTo(0,0)'},
184 187 {:href => url_for(:params => url_param.merge(page_param => paginator.current.next))}) if paginator.current.next
185 188
186 189 unless count.nil?
187 190 html << [" (#{paginator.current.first_item}-#{paginator.current.last_item}/#{count})", per_page_links(paginator.items_per_page)].compact.join(' | ')
188 191 end
189 192
190 193 html
191 194 end
192 195
193 196 def per_page_links(selected=nil)
194 197 url_param = params.dup
195 198 url_param.clear if url_param.has_key?(:set_filter)
196 199
197 200 links = Setting.per_page_options_array.collect do |n|
198 201 n == selected ? n : link_to_remote(n, {:update => "content", :url => params.dup.merge(:per_page => n)},
199 202 {:href => url_for(url_param.merge(:per_page => n))})
200 203 end
201 204 links.size > 1 ? l(:label_display_per_page, links.join(', ')) : nil
202 205 end
203 206
204 207 def breadcrumb(*args)
205 208 elements = args.flatten
206 209 elements.any? ? content_tag('p', args.join(' &#187; ') + ' &#187; ', :class => 'breadcrumb') : nil
207 210 end
208 211
209 212 def html_title(*args)
210 213 if args.empty?
211 214 title = []
212 215 title << @project.name if @project
213 216 title += @html_title if @html_title
214 217 title << Setting.app_title
215 218 title.compact.join(' - ')
216 219 else
217 220 @html_title ||= []
218 221 @html_title += args
219 222 end
220 223 end
221 224
222 225 def accesskey(s)
223 226 Redmine::AccessKeys.key_for s
224 227 end
225 228
226 229 # Formats text according to system settings.
227 230 # 2 ways to call this method:
228 231 # * with a String: textilizable(text, options)
229 232 # * with an object and one of its attribute: textilizable(issue, :description, options)
230 233 def textilizable(*args)
231 234 options = args.last.is_a?(Hash) ? args.pop : {}
232 235 case args.size
233 236 when 1
234 237 obj = options[:object]
235 238 text = args.shift
236 239 when 2
237 240 obj = args.shift
238 241 text = obj.send(args.shift).to_s
239 242 else
240 243 raise ArgumentError, 'invalid arguments to textilizable'
241 244 end
242 245 return '' if text.blank?
243 246
244 247 only_path = options.delete(:only_path) == false ? false : true
245 248
246 249 # when using an image link, try to use an attachment, if possible
247 250 attachments = options[:attachments] || (obj && obj.respond_to?(:attachments) ? obj.attachments : nil)
248 251
249 252 if attachments
250 253 attachments = attachments.sort_by(&:created_on).reverse
251 254 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m|
252 255 style = $1
253 256 filename = $6
254 257 rf = Regexp.new(Regexp.escape(filename), Regexp::IGNORECASE)
255 258 # search for the picture in attachments
256 259 if found = attachments.detect { |att| att.filename =~ rf }
257 260 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
258 261 desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1")
259 262 alt = desc.blank? ? nil : "(#{desc})"
260 263 "!#{style}#{image_url}#{alt}!"
261 264 else
262 265 "!#{style}#{filename}!"
263 266 end
264 267 end
265 268 end
266 269
267 270 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) }
268 271
269 272 # different methods for formatting wiki links
270 273 case options[:wiki_links]
271 274 when :local
272 275 # used for local links to html files
273 276 format_wiki_link = Proc.new {|project, title, anchor| "#{title}.html" }
274 277 when :anchor
275 278 # used for single-file wiki export
276 279 format_wiki_link = Proc.new {|project, title, anchor| "##{title}" }
277 280 else
278 281 format_wiki_link = Proc.new {|project, title, anchor| url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :id => project, :page => title, :anchor => anchor) }
279 282 end
280 283
281 284 project = options[:project] || @project || (obj && obj.respond_to?(:project) ? obj.project : nil)
282 285
283 286 # Wiki links
284 287 #
285 288 # Examples:
286 289 # [[mypage]]
287 290 # [[mypage|mytext]]
288 291 # wiki links can refer other project wikis, using project name or identifier:
289 292 # [[project:]] -> wiki starting page
290 293 # [[project:|mytext]]
291 294 # [[project:mypage]]
292 295 # [[project:mypage|mytext]]
293 296 text = text.gsub(/(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/) do |m|
294 297 link_project = project
295 298 esc, all, page, title = $1, $2, $3, $5
296 299 if esc.nil?
297 300 if page =~ /^([^\:]+)\:(.*)$/
298 301 link_project = Project.find_by_name($1) || Project.find_by_identifier($1)
299 302 page = $2
300 303 title ||= $1 if page.blank?
301 304 end
302 305
303 306 if link_project && link_project.wiki
304 307 # extract anchor
305 308 anchor = nil
306 309 if page =~ /^(.+?)\#(.+)$/
307 310 page, anchor = $1, $2
308 311 end
309 312 # check if page exists
310 313 wiki_page = link_project.wiki.find_page(page)
311 314 link_to((title || page), format_wiki_link.call(link_project, Wiki.titleize(page), anchor),
312 315 :class => ('wiki-page' + (wiki_page ? '' : ' new')))
313 316 else
314 317 # project or wiki doesn't exist
315 318 title || page
316 319 end
317 320 else
318 321 all
319 322 end
320 323 end
321 324
322 325 # Redmine links
323 326 #
324 327 # Examples:
325 328 # Issues:
326 329 # #52 -> Link to issue #52
327 330 # Changesets:
328 331 # r52 -> Link to revision 52
329 332 # commit:a85130f -> Link to scmid starting with a85130f
330 333 # Documents:
331 334 # document#17 -> Link to document with id 17
332 335 # document:Greetings -> Link to the document with title "Greetings"
333 336 # document:"Some document" -> Link to the document with title "Some document"
334 337 # Versions:
335 338 # version#3 -> Link to version with id 3
336 339 # version:1.0.0 -> Link to version named "1.0.0"
337 340 # version:"1.0 beta 2" -> Link to version named "1.0 beta 2"
338 341 # Attachments:
339 342 # attachment:file.zip -> Link to the attachment of the current object named file.zip
340 343 # Source files:
341 344 # source:some/file -> Link to the file located at /some/file in the project's repository
342 345 # source:some/file@52 -> Link to the file's revision 52
343 346 # source:some/file#L120 -> Link to line 120 of the file
344 347 # source:some/file@52#L120 -> Link to line 120 of the file's revision 52
345 348 # export:some/file -> Force the download of the file
346 349 # Forum messages:
347 350 # message#1218 -> Link to message with id 1218
348 351 text = text.gsub(%r{([\s\(,\-\>]|^)(!)?(attachment|document|version|commit|source|export|message)?((#|r)(\d+)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]]\W)|\s|<|$)}) do |m|
349 352 leading, esc, prefix, sep, oid = $1, $2, $3, $5 || $7, $6 || $8
350 353 link = nil
351 354 if esc.nil?
352 355 if prefix.nil? && sep == 'r'
353 356 if project && (changeset = project.changesets.find_by_revision(oid))
354 357 link = link_to("r#{oid}", {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => oid},
355 358 :class => 'changeset',
356 359 :title => truncate_single_line(changeset.comments, 100))
357 360 end
358 361 elsif sep == '#'
359 362 oid = oid.to_i
360 363 case prefix
361 364 when nil
362 365 if issue = Issue.find_by_id(oid, :include => [:project, :status], :conditions => Project.visible_by(User.current))
363 366 link = link_to("##{oid}", {:only_path => only_path, :controller => 'issues', :action => 'show', :id => oid},
364 367 :class => (issue.closed? ? 'issue closed' : 'issue'),
365 368 :title => "#{truncate(issue.subject, 100)} (#{issue.status.name})")
366 369 link = content_tag('del', link) if issue.closed?
367 370 end
368 371 when 'document'
369 372 if document = Document.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
370 373 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
371 374 :class => 'document'
372 375 end
373 376 when 'version'
374 377 if version = Version.find_by_id(oid, :include => [:project], :conditions => Project.visible_by(User.current))
375 378 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
376 379 :class => 'version'
377 380 end
378 381 when 'message'
379 382 if message = Message.find_by_id(oid, :include => [:parent, {:board => :project}], :conditions => Project.visible_by(User.current))
380 383 link = link_to h(truncate(message.subject, 60)), {:only_path => only_path,
381 384 :controller => 'messages',
382 385 :action => 'show',
383 386 :board_id => message.board,
384 387 :id => message.root,
385 388 :anchor => (message.parent ? "message-#{message.id}" : nil)},
386 389 :class => 'message'
387 390 end
388 391 end
389 392 elsif sep == ':'
390 393 # removes the double quotes if any
391 394 name = oid.gsub(%r{^"(.*)"$}, "\\1")
392 395 case prefix
393 396 when 'document'
394 397 if project && document = project.documents.find_by_title(name)
395 398 link = link_to h(document.title), {:only_path => only_path, :controller => 'documents', :action => 'show', :id => document},
396 399 :class => 'document'
397 400 end
398 401 when 'version'
399 402 if project && version = project.versions.find_by_name(name)
400 403 link = link_to h(version.name), {:only_path => only_path, :controller => 'versions', :action => 'show', :id => version},
401 404 :class => 'version'
402 405 end
403 406 when 'commit'
404 407 if project && (changeset = project.changesets.find(:first, :conditions => ["scmid LIKE ?", "#{name}%"]))
405 408 link = link_to h("#{name}"), {:only_path => only_path, :controller => 'repositories', :action => 'revision', :id => project, :rev => changeset.revision},
406 409 :class => 'changeset',
407 410 :title => truncate_single_line(changeset.comments, 100)
408 411 end
409 412 when 'source', 'export'
410 413 if project && project.repository
411 414 name =~ %r{^[/\\]*(.*?)(@([0-9a-f]+))?(#(L\d+))?$}
412 415 path, rev, anchor = $1, $3, $5
413 416 link = link_to h("#{prefix}:#{name}"), {:controller => 'repositories', :action => 'entry', :id => project,
414 417 :path => to_path_param(path),
415 418 :rev => rev,
416 419 :anchor => anchor,
417 420 :format => (prefix == 'export' ? 'raw' : nil)},
418 421 :class => (prefix == 'export' ? 'source download' : 'source')
419 422 end
420 423 when 'attachment'
421 424 if attachments && attachment = attachments.detect {|a| a.filename == name }
422 425 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment},
423 426 :class => 'attachment'
424 427 end
425 428 end
426 429 end
427 430 end
428 431 leading + (link || "#{prefix}#{sep}#{oid}")
429 432 end
430 433
431 434 text
432 435 end
433 436
434 437 # Same as Rails' simple_format helper without using paragraphs
435 438 def simple_format_without_paragraph(text)
436 439 text.to_s.
437 440 gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
438 441 gsub(/\n\n+/, "<br /><br />"). # 2+ newline -> 2 br
439 442 gsub(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
440 443 end
441 444
442 445 def error_messages_for(object_name, options = {})
443 446 options = options.symbolize_keys
444 447 object = instance_variable_get("@#{object_name}")
445 448 if object && !object.errors.empty?
446 449 # build full_messages here with controller current language
447 450 full_messages = []
448 451 object.errors.each do |attr, msg|
449 452 next if msg.nil?
450 453 msg = msg.first if msg.is_a? Array
451 454 if attr == "base"
452 455 full_messages << l(msg)
453 456 else
454 457 full_messages << "&#171; " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " &#187; " + l(msg) unless attr == "custom_values"
455 458 end
456 459 end
457 460 # retrieve custom values error messages
458 461 if object.errors[:custom_values]
459 462 object.custom_values.each do |v|
460 463 v.errors.each do |attr, msg|
461 464 next if msg.nil?
462 465 msg = msg.first if msg.is_a? Array
463 466 full_messages << "&#171; " + v.custom_field.name + " &#187; " + l(msg)
464 467 end
465 468 end
466 469 end
467 470 content_tag("div",
468 471 content_tag(
469 472 options[:header_tag] || "span", lwr(:gui_validation_error, full_messages.length) + ":"
470 473 ) +
471 474 content_tag("ul", full_messages.collect { |msg| content_tag("li", msg) }),
472 475 "id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
473 476 )
474 477 else
475 478 ""
476 479 end
477 480 end
478 481
479 482 def lang_options_for_select(blank=true)
480 483 (blank ? [["(auto)", ""]] : []) +
481 484 GLoc.valid_languages.collect{|lang| [ ll(lang.to_s, :general_lang_name), lang.to_s]}.sort{|x,y| x.last <=> y.last }
482 485 end
483 486
484 487 def label_tag_for(name, option_tags = nil, options = {})
485 488 label_text = l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym) + (options.delete(:required) ? @template.content_tag("span", " *", :class => "required"): "")
486 489 content_tag("label", label_text)
487 490 end
488 491
489 492 def labelled_tabular_form_for(name, object, options, &proc)
490 493 options[:html] ||= {}
491 494 options[:html][:class] = 'tabular' unless options[:html].has_key?(:class)
492 495 form_for(name, object, options.merge({ :builder => TabularFormBuilder, :lang => current_language}), &proc)
493 496 end
494 497
495 498 def back_url_hidden_field_tag
496 499 back_url = params[:back_url] || request.env['HTTP_REFERER']
497 500 hidden_field_tag('back_url', back_url) unless back_url.blank?
498 501 end
499 502
500 503 def check_all_links(form_name)
501 504 link_to_function(l(:button_check_all), "checkAll('#{form_name}', true)") +
502 505 " | " +
503 506 link_to_function(l(:button_uncheck_all), "checkAll('#{form_name}', false)")
504 507 end
505 508
506 509 def progress_bar(pcts, options={})
507 510 pcts = [pcts, pcts] unless pcts.is_a?(Array)
508 511 pcts[1] = pcts[1] - pcts[0]
509 512 pcts << (100 - pcts[1] - pcts[0])
510 513 width = options[:width] || '100px;'
511 514 legend = options[:legend] || ''
512 515 content_tag('table',
513 516 content_tag('tr',
514 517 (pcts[0] > 0 ? content_tag('td', '', :width => "#{pcts[0].floor}%;", :class => 'closed') : '') +
515 518 (pcts[1] > 0 ? content_tag('td', '', :width => "#{pcts[1].floor}%;", :class => 'done') : '') +
516 519 (pcts[2] > 0 ? content_tag('td', '', :width => "#{pcts[2].floor}%;", :class => 'todo') : '')
517 520 ), :class => 'progress', :style => "width: #{width};") +
518 521 content_tag('p', legend, :class => 'pourcent')
519 522 end
520 523
521 524 def context_menu_link(name, url, options={})
522 525 options[:class] ||= ''
523 526 if options.delete(:selected)
524 527 options[:class] << ' icon-checked disabled'
525 528 options[:disabled] = true
526 529 end
527 530 if options.delete(:disabled)
528 531 options.delete(:method)
529 532 options.delete(:confirm)
530 533 options.delete(:onclick)
531 534 options[:class] << ' disabled'
532 535 url = '#'
533 536 end
534 537 link_to name, url, options
535 538 end
536 539
537 540 def calendar_for(field_id)
538 541 include_calendar_headers_tags
539 542 image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) +
540 543 javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });")
541 544 end
542 545
543 546 def include_calendar_headers_tags
544 547 unless @calendar_headers_tags_included
545 548 @calendar_headers_tags_included = true
546 549 content_for :header_tags do
547 550 javascript_include_tag('calendar/calendar') +
548 551 javascript_include_tag("calendar/lang/calendar-#{current_language}.js") +
549 552 javascript_include_tag('calendar/calendar-setup') +
550 553 stylesheet_link_tag('calendar')
551 554 end
552 555 end
553 556 end
554 557
555 558 def content_for(name, content = nil, &block)
556 559 @has_content ||= {}
557 560 @has_content[name] = true
558 561 super(name, content, &block)
559 562 end
560 563
561 564 def has_content?(name)
562 565 (@has_content && @has_content[name]) || false
563 566 end
564 567
565 568 # Returns the avatar image tag for the given +user+ if avatars are enabled
566 569 # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
567 570 def avatar(user, options = { })
568 571 if Setting.gravatar_enabled?
569 572 email = nil
570 573 if user.respond_to?(:mail)
571 574 email = user.mail
572 575 elsif user.to_s =~ %r{<(.+?)>}
573 576 email = $1
574 577 end
575 578 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil
576 579 end
577 580 end
578 581
579 582 private
580 583
581 584 def wiki_helper
582 585 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting)
583 586 extend helper
584 587 return self
585 588 end
586 589 end
General Comments 0
You need to be logged in to leave comments. Login now