Project

General

Profile

Feature #3058 » 0001-allow-tabs-to-have-a-custom-action.patch

Marius BĂLTEANU, 2018-12-16 15:59

View differences:

app/helpers/application_helper.rb
389 389
    end
390 390
  end
391 391

  
392
  # Returns the tab action depending on the tab properties
393
  def get_tab_action(tab)
394
    if tab[:onclick]
395
      return tab[:onclick]
396
    elsif tab[:partial]
397
      return "showTab('#{tab[:name]}', this.href)"
398
    else
399
      return nil
400
    end
401
  end
402

  
392 403
  # Returns the default scope for the quick search form
393 404
  # Could be 'all', 'my_projects', 'subprojects' or nil (current project)
394 405
  def default_search_project_scope
app/views/common/_tabs.html.erb
1
<% default_action = false %>
2

  
1 3
<div class="tabs">
2 4
  <ul>
3 5
  <% tabs.each do |tab| -%>
6
    <% action = get_tab_action(tab) %>
4 7
    <li><%= link_to l(tab[:label]), (tab[:url] || { :tab => tab[:name] }),
5 8
                                    :id => "tab-#{tab[:name]}",
6 9
                                    :class => (tab[:name] != selected_tab ? nil : 'selected'),
7
                                    :onclick => tab[:partial] ? "showTab('#{tab[:name]}', this.href); this.blur(); return false;" : nil %></li>
10
                                    :onclick => (action.nil? ? nil : "#{ action }; return false;") %></li>
11
    <% default_action = action if tab[:name] == selected_tab %>
8 12
  <% end -%>
9 13
  </ul>
10 14
  <div class="tabs-buttons" style="display:none;">
......
19 23
                       :style => (tab[:name] != selected_tab ? 'display:none' : nil),
20 24
                       :class => 'tab-content') if tab[:partial] %>
21 25
<% end -%>
26

  
27
<%= javascript_tag default_action if default_action %>
(14-14/28)