@@ -103,6 +103,23 module ApplicationHelper | |||||
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 |
|
104 | end | |
105 |
|
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 | |||
|
121 | end | |||
|
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(); ") | |
@@ -368,12 +385,12 module ApplicationHelper | |||||
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 |
|
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 |
|
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(' » ') | |
@@ -605,8 +622,7 module ApplicationHelper | |||||
605 | end |
|
622 | end | |
606 | when 'project' |
|
623 | when 'project' | |
607 | if p = Project.visible.find_by_id(oid) |
|
624 | if p = Project.visible.find_by_id(oid) | |
608 |
link = link_to |
|
625 | link = link_to_project(p, {:only_path => only_path}, :class => 'project') | |
609 | :class => 'project' |
|
|||
610 | end |
|
626 | end | |
611 | end |
|
627 | end | |
612 | elsif sep == ':' |
|
628 | elsif sep == ':' | |
@@ -648,8 +664,7 module ApplicationHelper | |||||
648 | end |
|
664 | end | |
649 | when 'project' |
|
665 | when 'project' | |
650 | 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}]) | |
651 |
link = link_to |
|
667 | link = link_to_project(p, {:only_path => only_path}, :class => 'project') | |
652 | :class => 'project' |
|
|||
653 | end |
|
668 | end | |
654 | end |
|
669 | end | |
655 | end |
|
670 | end |
@@ -72,7 +72,7 module ProjectsHelper | |||||
72 | end |
|
72 | end | |
73 | classes = (ancestors.empty? ? 'root' : 'child') |
|
73 | classes = (ancestors.empty? ? 'root' : 'child') | |
74 | s << "<li class='#{classes}'><div class='#{classes}'>" + |
|
74 | s << "<li class='#{classes}'><div class='#{classes}'>" + | |
75 |
link_to |
|
75 | link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") | |
76 | s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? |
|
76 | s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? | |
77 | s << "</div>\n" |
|
77 | s << "</div>\n" | |
78 | ancestors << project |
|
78 | ancestors << project |
@@ -50,7 +50,7 module QueriesHelper | |||||
50 | when 'User' |
|
50 | when 'User' | |
51 | link_to_user value |
|
51 | link_to_user value | |
52 | when 'Project' |
|
52 | when 'Project' | |
53 | link_to(h(value), :controller => 'projects', :action => 'show', :id => value) |
|
53 | link_to_project value | |
54 | when 'Version' |
|
54 | when 'Version' | |
55 | link_to(h(value), :controller => 'versions', :action => 'show', :id => value) |
|
55 | link_to(h(value), :controller => 'versions', :action => 'show', :id => value) | |
56 | when 'TrueClass' |
|
56 | when 'TrueClass' |
@@ -27,7 +27,7 | |||||
27 | <tbody> |
|
27 | <tbody> | |
28 | <% project_tree(@projects) do |project, level| %> |
|
28 | <% project_tree(@projects) do |project, level| %> | |
29 | <tr class="<%= cycle("odd", "even") %> <%= css_project_classes(project) %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>"> |
|
29 | <tr class="<%= cycle("odd", "even") %> <%= css_project_classes(project) %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>"> | |
30 | <td class="name"><%= project.active? ? link_to(h(project.name), :controller => 'projects', :action => 'settings', :id => project) : h(project.name) %></td> |
|
30 | <td class="name"><%= link_to_project(project, :action => 'settings') %></td> | |
31 | <td><%= textilizable project.short_description, :project => project %></td> |
|
31 | <td><%= textilizable project.short_description, :project => project %></td> | |
32 | <td align="center"><%= checked_image project.is_public? %></td> |
|
32 | <td align="center"><%= checked_image project.is_public? %></td> | |
33 | <td align="center"><%= format_date(project.created_on) %></td> |
|
33 | <td align="center"><%= format_date(project.created_on) %></td> |
@@ -14,7 +14,7 | |||||
14 | <%= check_box_tag("ids[]", issue.id, false, :style => 'display:none;') %> |
|
14 | <%= check_box_tag("ids[]", issue.id, false, :style => 'display:none;') %> | |
15 | <%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %> |
|
15 | <%= link_to issue.id, :controller => 'issues', :action => 'show', :id => issue %> | |
16 | </td> |
|
16 | </td> | |
17 |
<td class="project"><%= link_to( |
|
17 | <td class="project"><%= link_to_project(issue.project) %></td> | |
18 | <td class="tracker"><%=h issue.tracker %></td> |
|
18 | <td class="tracker"><%=h issue.tracker %></td> | |
19 | <td class="subject"> |
|
19 | <td class="subject"> | |
20 | <%= link_to h(truncate(issue.subject, :length => 60)), :controller => 'issues', :action => 'show', :id => issue %> (<%=h issue.status %>) |
|
20 | <%= link_to h(truncate(issue.subject, :length => 60)), :controller => 'issues', :action => 'show', :id => issue %> (<%=h issue.status %>) |
@@ -1,4 +1,4 | |||||
1 |
<p><%= link_to( |
|
1 | <p><%= link_to_project(news.project) + ': ' unless @project %> | |
2 | <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %> |
|
2 | <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %> | |
3 | <%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %> |
|
3 | <%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %> | |
4 | <br /> |
|
4 | <br /> |
@@ -28,7 +28,7 | |||||
28 | <p class="nodata"><%= l(:label_no_data) %></p> |
|
28 | <p class="nodata"><%= l(:label_no_data) %></p> | |
29 | <% else %> |
|
29 | <% else %> | |
30 | <% @newss.each do |news| %> |
|
30 | <% @newss.each do |news| %> | |
31 |
<h3><%= link_to( |
|
31 | <h3><%= link_to_project(news.project) + ': ' unless news.project == @project %> | |
32 | <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %> |
|
32 | <%= link_to h(news.title), :controller => 'news', :action => 'show', :id => news %> | |
33 | <%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %></h3> |
|
33 | <%= "(#{l(:label_x_comments, :count => news.comments_count)})" if news.comments_count > 0 %></h3> | |
34 | <p class="author"><%= authoring news.created_on, news.author %></p> |
|
34 | <p class="author"><%= authoring news.created_on, news.author %></p> |
@@ -15,7 +15,7 | |||||
15 | <% next if membership.new_record? %> |
|
15 | <% next if membership.new_record? %> | |
16 | <tr id="member-<%= membership.id %>" class="<%= cycle 'odd', 'even' %> class"> |
|
16 | <tr id="member-<%= membership.id %>" class="<%= cycle 'odd', 'even' %> class"> | |
17 | <td class="project"> |
|
17 | <td class="project"> | |
18 | <%= link_to h(membership.project), {:controller => 'projects', :action => 'show', :id => membership.project} %> |
|
18 | <%= link_to_project membership.project %> | |
19 | </td> |
|
19 | </td> | |
20 | <td class="roles"> |
|
20 | <td class="roles"> | |
21 | <span id="member-<%= membership.id %>-roles"><%=h membership.roles.sort.collect(&:to_s).join(', ') %></span> |
|
21 | <span id="member-<%= membership.id %>-roles"><%=h membership.roles.sort.collect(&:to_s).join(', ') %></span> |
@@ -24,7 +24,7 | |||||
24 | <h3><%=l(:label_project_plural)%></h3> |
|
24 | <h3><%=l(:label_project_plural)%></h3> | |
25 | <ul> |
|
25 | <ul> | |
26 | <% for membership in @memberships %> |
|
26 | <% for membership in @memberships %> | |
27 | <li><%= link_to(h(membership.project.name), :controller => 'projects', :action => 'show', :id => membership.project) %> |
|
27 | <li><%= link_to_project(membership.project) %> | |
28 | (<%=h membership.roles.sort.collect(&:to_s).join(', ') %>, <%= format_date(membership.created_on) %>)</li> |
|
28 | (<%=h membership.roles.sort.collect(&:to_s).join(', ') %>, <%= format_date(membership.created_on) %>)</li> | |
29 | <% end %> |
|
29 | <% end %> | |
30 | </ul> |
|
30 | </ul> |
@@ -20,7 +20,7 | |||||
20 | <% for project in @projects %> |
|
20 | <% for project in @projects %> | |
21 | <% @project = project %> |
|
21 | <% @project = project %> | |
22 | <li> |
|
22 | <li> | |
23 |
<%= link_to |
|
23 | <%= link_to_project project %> (<%= format_time(project.created_on) %>) | |
24 | <%= textilizable project.short_description, :project => project %> |
|
24 | <%= textilizable project.short_description, :project => project %> | |
25 | </li> |
|
25 | </li> | |
26 | <% end %> |
|
26 | <% end %> |
@@ -597,4 +597,16 EXPECTED | |||||
597 | t = link_to_user(user) |
|
597 | t = link_to_user(user) | |
598 | assert_equal ::I18n.t(:label_user_anonymous), t |
|
598 | assert_equal ::I18n.t(:label_user_anonymous), t | |
599 | end |
|
599 | end | |
|
600 | ||||
|
601 | def test_link_to_project | |||
|
602 | project = Project.find(1) | |||
|
603 | assert_equal %(<a href="/projects/ecookbook">eCookbook</a>), | |||
|
604 | link_to_project(project) | |||
|
605 | assert_equal %(<a href="/projects/ecookbook/settings">eCookbook</a>), | |||
|
606 | link_to_project(project, :action => 'settings') | |||
|
607 | assert_equal %(<a href="http://test.host/projects/ecookbook?jump=blah">eCookbook</a>), | |||
|
608 | link_to_project(project, {:only_path => false, :jump => 'blah'}) | |||
|
609 | assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>), | |||
|
610 | link_to_project(project, {:action => 'settings'}, :class => "project") | |||
|
611 | end | |||
600 | end |
|
612 | end |
General Comments 0
You need to be logged in to leave comments.
Login now