Mercurial > hg > soundsoftware-site
comparison app/helpers/application_helper.rb @ 14:1d32c0a0efbf
* Update to SVN trunk (revisions 3892-4040)
author | Chris Cannam |
---|---|
date | Wed, 25 Aug 2010 16:30:24 +0100 |
parents | 513646585e45 |
children | 9c6c72729d91 40f7cfd4df19 |
comparison
equal
deleted
inserted
replaced
4:9cc62779c13a | 14:1d32c0a0efbf |
---|---|
99 # * :text - Link text (default to the formatted revision) | 99 # * :text - Link text (default to the formatted revision) |
100 def link_to_revision(revision, project, options={}) | 100 def link_to_revision(revision, project, options={}) |
101 text = options.delete(:text) || format_revision(revision) | 101 text = options.delete(:text) || format_revision(revision) |
102 | 102 |
103 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision)) | 103 link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision}, :title => l(:label_revision_id, revision)) |
104 end | |
105 | |
106 # Generates a link to a project if active | |
107 # Examples: | |
108 # | |
109 # link_to_project(project) # => link to the specified project overview | |
110 # link_to_project(project, :action=>'settings') # => link to project settings | |
111 # link_to_project(project, {:only_path => false}, :class => "project") # => 3rd arg adds html options | |
112 # link_to_project(project, {}, :class => "project") # => html options with default url (project overview) | |
113 # | |
114 def link_to_project(project, options={}, html_options = nil) | |
115 if project.active? | |
116 url = {:controller => 'projects', :action => 'show', :id => project}.merge(options) | |
117 link_to(h(project), url, html_options) | |
118 else | |
119 h(project) | |
120 end | |
104 end | 121 end |
105 | 122 |
106 def toggle_link(name, id, options={}) | 123 def toggle_link(name, id, options={}) |
107 onclick = "Element.toggle('#{id}'); " | 124 onclick = "Element.toggle('#{id}'); " |
108 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") | 125 onclick << (options[:focus] ? "Form.Element.focus('#{options[:focus]}'); " : "this.blur(); ") |
366 else | 383 else |
367 b = [] | 384 b = [] |
368 ancestors = (@project.root? ? [] : @project.ancestors.visible) | 385 ancestors = (@project.root? ? [] : @project.ancestors.visible) |
369 if ancestors.any? | 386 if ancestors.any? |
370 root = ancestors.shift | 387 root = ancestors.shift |
371 b << link_to(h(root), {:controller => 'projects', :action => 'show', :id => root, :jump => current_menu_item}, :class => 'root') | 388 b << link_to_project(root, {:jump => current_menu_item}, :class => 'root') |
372 if ancestors.size > 2 | 389 if ancestors.size > 2 |
373 b << '…' | 390 b << '…' |
374 ancestors = ancestors[-2, 2] | 391 ancestors = ancestors[-2, 2] |
375 end | 392 end |
376 b += ancestors.collect {|p| link_to(h(p), {:controller => 'projects', :action => 'show', :id => p, :jump => current_menu_item}, :class => 'ancestor') } | 393 b += ancestors.collect {|p| link_to_project(p, {:jump => current_menu_item}, :class => 'ancestor') } |
377 end | 394 end |
378 b << h(@project) | 395 b << h(@project) |
379 b.join(' » ') | 396 b.join(' » ') |
380 end | 397 end |
381 end | 398 end |
389 title.select {|t| !t.blank? }.join(' - ') | 406 title.select {|t| !t.blank? }.join(' - ') |
390 else | 407 else |
391 @html_title ||= [] | 408 @html_title ||= [] |
392 @html_title += args | 409 @html_title += args |
393 end | 410 end |
411 end | |
412 | |
413 # Returns the theme, controller name, and action as css classes for the | |
414 # HTML body. | |
415 def body_css_classes | |
416 css = [] | |
417 if theme = Redmine::Themes.theme(Setting.ui_theme) | |
418 css << 'theme-' + theme.name | |
419 end | |
420 | |
421 css << 'controller-' + params[:controller] | |
422 css << 'action-' + params[:action] | |
423 css.join(' ') | |
394 end | 424 end |
395 | 425 |
396 def accesskey(s) | 426 def accesskey(s) |
397 Redmine::AccessKeys.key_for s | 427 Redmine::AccessKeys.key_for s |
398 end | 428 end |
590 :anchor => (message.parent ? "message-#{message.id}" : nil)}, | 620 :anchor => (message.parent ? "message-#{message.id}" : nil)}, |
591 :class => 'message' | 621 :class => 'message' |
592 end | 622 end |
593 when 'project' | 623 when 'project' |
594 if p = Project.visible.find_by_id(oid) | 624 if p = Project.visible.find_by_id(oid) |
595 link = link_to h(p.name), {:only_path => only_path, :controller => 'projects', :action => 'show', :id => p}, | 625 link = link_to_project(p, {:only_path => only_path}, :class => 'project') |
596 :class => 'project' | |
597 end | 626 end |
598 end | 627 end |
599 elsif sep == ':' | 628 elsif sep == ':' |
600 # removes the double quotes if any | 629 # removes the double quotes if any |
601 name = identifier.gsub(%r{^"(.*)"$}, "\\1") | 630 name = identifier.gsub(%r{^"(.*)"$}, "\\1") |
633 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, | 662 link = link_to h(attachment.filename), {:only_path => only_path, :controller => 'attachments', :action => 'download', :id => attachment}, |
634 :class => 'attachment' | 663 :class => 'attachment' |
635 end | 664 end |
636 when 'project' | 665 when 'project' |
637 if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}]) | 666 if p = Project.visible.find(:first, :conditions => ["identifier = :s OR LOWER(name) = :s", {:s => name.downcase}]) |
638 link = link_to h(p.name), {:only_path => only_path, :controller => 'projects', :action => 'show', :id => p}, | 667 link = link_to_project(p, {:only_path => only_path}, :class => 'project') |
639 :class => 'project' | |
640 end | 668 end |
641 end | 669 end |
642 end | 670 end |
643 end | 671 end |
644 leading + (link || "#{prefix}#{sep}#{identifier}") | 672 leading + (link || "#{prefix}#{sep}#{identifier}") |
706 def context_menu(url) | 734 def context_menu(url) |
707 unless @context_menu_included | 735 unless @context_menu_included |
708 content_for :header_tags do | 736 content_for :header_tags do |
709 javascript_include_tag('context_menu') + | 737 javascript_include_tag('context_menu') + |
710 stylesheet_link_tag('context_menu') | 738 stylesheet_link_tag('context_menu') |
739 end | |
740 if l(:direction) == 'rtl' | |
741 content_for :header_tags do | |
742 stylesheet_link_tag('context_menu_rtl') | |
743 end | |
711 end | 744 end |
712 @context_menu_included = true | 745 @context_menu_included = true |
713 end | 746 end |
714 javascript_tag "new ContextMenu('#{ url_for(url) }')" | 747 javascript_tag "new ContextMenu('#{ url_for(url) }')" |
715 end | 748 end |
781 end | 814 end |
782 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil | 815 return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil |
783 end | 816 end |
784 end | 817 end |
785 | 818 |
819 def favicon | |
820 "<link rel='shortcut icon' href='#{image_path('/favicon.ico')}' />" | |
821 end | |
822 | |
786 private | 823 private |
787 | 824 |
788 def wiki_helper | 825 def wiki_helper |
789 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) | 826 helper = Redmine::WikiFormatting.helper_for(Setting.text_formatting) |
790 extend helper | 827 extend helper |