]> source.dussan.org Git - redmine.git/commitdiff
Allow tabs to have a custom action (#3058).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 20 Jun 2019 07:06:47 +0000 (07:06 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 20 Jun 2019 07:06:47 +0000 (07:06 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@18271 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/application_helper.rb
app/views/common/_tabs.html.erb

index 4ecb558b5610d099a064be4d6ffc945d968adc27..1b259b44b57cc81cbc8c75746f5912a2c95fe955 100644 (file)
@@ -407,6 +407,17 @@ module ApplicationHelper
     end
   end
 
+  # Returns the tab action depending on the tab properties
+  def get_tab_action(tab)
+    if tab[:onclick]
+      return tab[:onclick]
+    elsif tab[:partial]
+      return "showTab('#{tab[:name]}', this.href)"
+    else
+      return nil
+    end
+  end
+
   # Returns the default scope for the quick search form
   # Could be 'all', 'my_projects', 'subprojects' or nil (current project)
   def default_search_project_scope
index 1b880c9c7e53ade964ce846ca7aa7409b0559fb4..df7513e42bde51a44ea3a226632489d7d1a20b86 100644 (file)
@@ -1,10 +1,14 @@
+<% default_action = false %>
+
 <div class="tabs">
   <ul>
   <% tabs.each do |tab| -%>
+    <% action = get_tab_action(tab) %>
     <li><%= link_to l(tab[:label]), (tab[:url] || { :tab => tab[:name] }),
                                     :id => "tab-#{tab[:name]}",
                                     :class => (tab[:name] != selected_tab ? nil : 'selected'),
-                                    :onclick => tab[:partial] ? "showTab('#{tab[:name]}', this.href); this.blur(); return false;" : nil %></li>
+                                    :onclick => (action.nil? ? nil : "#{ action }; return false;") %></li>
+    <% default_action = action if tab[:name] == selected_tab %>
   <% end -%>
   </ul>
   <div class="tabs-buttons" style="display:none;">
@@ -19,3 +23,5 @@
                        :style => (tab[:name] != selected_tab ? 'display:none' : nil),
                        :class => 'tab-content') if tab[:partial] %>
 <% end -%>
+
+<%= javascript_tag default_action if default_action %>