Skip to content

Commit

Permalink
miq_tab_* - add ng-click, onclick & lazy options
Browse files Browse the repository at this point in the history
since #3859 (comment), `miq_tab_header` would put ng-click (hardcoded to call `changeAuthTab`) on every tab header, even though it makes no sense for most tabs

Fixed by moving the ng-click value explicitly to options, and passing it from where `ng-click` is actually needed

Also added :onclick to options, so that custom functionality can be added in non-angular tabs too.

miq_tab_content now also takes a :lazy option, which causes the tab content to render only if the tab is currently active
  • Loading branch information
himdel committed Jan 4, 2017
1 parent e36f61b commit 2b1da75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
16 changes: 10 additions & 6 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1552,19 +1552,23 @@ def title_for_cluster_record(record)
end

def miq_tab_header(id, active = nil, options = {}, &_block)
content_tag(:li,
:class => "#{options[:class]} #{active == id ? 'active' : ''}",
:id => "#{id}_tab",
'ng-click' => "changeAuthTab('#{id}');") do
tag_options = {:class => "#{options[:class]} #{active == id ? 'active' : ''}",
:id => "#{id}_tab"}

tag_options['ng-click'] = options['ng-click'] if options.key?('ng-click')
tag_options[:onclick] = options[:onclick] if options.key?(:onclick)

content_tag(:li, tag_options) do
content_tag(:a, :href => "##{id}", 'data-toggle' => 'tab') do
yield
end
end
end

def miq_tab_content(id, active = nil, options = {}, &_block)
content_tag(:div, :id => id, :class => "tab-pane #{options[:class]} #{active == id ? 'active' : ''}") do
yield
lazy = options[:lazy] && active != id
content_tag(:div, :id => id, :class => "tab-pane #{options[:class]} #{active == id ? 'active' : ''} #{lazy ? 'lazy' : ''}") do
yield unless lazy
end
end

Expand Down
14 changes: 7 additions & 7 deletions app/views/layouts/_multi_auth_credentials.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
= legendtext
#auth_tabs
%ul.nav.nav-tabs
= miq_tab_header('default') do
= miq_tab_header('default', nil, {'ng-click' => "changeAuthTab('default')"}) do
= _("Default")
- if %w(ems_cloud ems_infra).include?(params[:controller])
- if @edit[:new][:emstype] == "rhevm"
= miq_tab_header('metrics') do
= miq_tab_header('metrics', nil, {'ng-click' => "changeAuthTab('metrics')"}) do
= _("C & U Database")
- if %w(openstack openstack_infra).include?(@edit[:new][:emstype])
= miq_tab_header('amqp') do
= miq_tab_header('amqp', nil, {'ng-click' => "changeAuthTab('amqp')"}) do
= _("AMQP")
- if %w(openstack_infra).include?(@edit[:new][:emstype])
= miq_tab_header('ssh_keypair') do
= miq_tab_header('ssh_keypair', nil, {'ng-click' => "changeAuthTab('ssh_keypair')"}) do
= _("RSA key pair")
- elsif !%w(ems_middleware).include?(params[:controller])
= miq_tab_header('remote') do
= miq_tab_header('remote', nil, {'ng-click' => "changeAuthTab('remote')"}) do
= _("Remote Login")
= miq_tab_header('web') do
= miq_tab_header('web', nil, {'ng-click' => "changeAuthTab('web')"}) do
= _("Web Services")
= miq_tab_header('ipmi') do
= miq_tab_header('ipmi', nil, {'ng-click' => "changeAuthTab('ipmi')"}) do
= _("IPMI")

.tab-content
Expand Down

0 comments on commit 2b1da75

Please sign in to comment.