01_allow-tabs-to-have-a-custom-action_r16963.patch

Marius BALTEANU, 2017-09-10 14:18

Download (1.85 KB)

View differences:

app/helpers/application_helper.rb
348 348
    end
349 349
  end
350 350

  
351
  # Returns the tab action depending on the tab properties
352
  def get_tab_action(tab)
353
    if tab[:onclick]
354
      return tab[:onclick]
355
    elsif tab[:partial]
356
      return "showTab('#{tab[:name]}', this.href)"
357
    else
358
      return nil
359
    end
360
  end
361

  
351 362
  # Returns the default scope for the quick search form
352 363
  # Could be 'all', 'my_projects', 'subprojects' or nil (current project)
353 364
  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 %>