From 2b1da75e4d389b1212f3db1b2885016a047846ee Mon Sep 17 00:00:00 2001 From: Martin Hradil Date: Wed, 4 Jan 2017 12:55:53 +0000 Subject: [PATCH] miq_tab_* - add ng-click, onclick & lazy options since https://github.com/ManageIQ/manageiq/pull/3859#discussion_r94436100, `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 --- app/helpers/application_helper.rb | 16 ++++++++++------ .../layouts/_multi_auth_credentials.html.haml | 14 +++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 00f35412ead..1ea9d157bb1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1552,10 +1552,13 @@ 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 @@ -1563,8 +1566,9 @@ def miq_tab_header(id, active = nil, options = {}, &_block) 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 diff --git a/app/views/layouts/_multi_auth_credentials.html.haml b/app/views/layouts/_multi_auth_credentials.html.haml index c1276b4444c..ddb1693eeb0 100644 --- a/app/views/layouts/_multi_auth_credentials.html.haml +++ b/app/views/layouts/_multi_auth_credentials.html.haml @@ -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