diff --git a/app/assets/javascripts/miq_application.js b/app/assets/javascripts/miq_application.js index 3291ba6044e0..53014a964a41 100644 --- a/app/assets/javascripts/miq_application.js +++ b/app/assets/javascripts/miq_application.js @@ -1231,8 +1231,11 @@ function miqAccordSelect(e) { return false; } - var url = '/' + $('body').data('controller') + '/accordion_select?id=' + $(e.target).attr('id'); - miqJqueryRequest(url, {beforeSend: true, complete: true}); + // No need to load anything if only a single accordion is present + if ($('#accordion > .panel').length > 1) { + var url = '/' + $('body').data('controller') + '/accordion_select?id=' + $(e.target).attr('id'); + miqJqueryRequest(url, {beforeSend: true, complete: true}); + } return true; } diff --git a/app/views/layouts/listnav/_explorer.html.haml b/app/views/layouts/listnav/_explorer.html.haml index 437fdafe3cb5..0793c8b89e07 100644 --- a/app/views/layouts/listnav/_explorer.html.haml +++ b/app/views/layouts/listnav/_explorer.html.haml @@ -1,17 +1,12 @@ -#accordion.panel-group - - if @accords.present? && @accords.length == 1 # there is no need for JavaScript if only one accordion is present - .panel.panel-default - .panel-heading - %h4.panel-title - %a{:href => '#'} - = @accords.first[:title] - .panel-collapse.collapse.in - .panel-body{:id => @accords.first[:container]} - = render :partial => 'shared/explorer_tree', :locals => {:name => @accords.first[:name]} - - elsif @accords.present? && @accords.length > 1 - - accord_names = @accords.map { |accord| accord[:name].to_sym } - - @accords.each_with_index do |a, i| - = miq_accordion_panel(a[:title], accord_names.include?(@sb[:active_accord]) ? a[:name].to_sym == @sb[:active_accord] : i == 0, a[:container]) do - = render :partial => 'shared/explorer_tree', :locals => {:name => a[:name]} +- if @accords + #accordion.panel-group + -# Set the first accordion as selected if there is no active_accord in the sandbox + - selected = @accords.find(-> { @accords.first }) { |accord| accord[:name].to_sym == @sb[:active_accord] } + - @accords.each do |accord| + = miq_accordion_panel(accord[:title], selected == accord, accord[:container]) do + -# Set the first tree to be rendered if there is a mismatch with the name/type + - tree = @trees.find(-> { @trees.first }) { |t| t.type == accord[:name].to_sym } + = render :partial => 'shared/tree', :locals => {:tree => tree, :name => tree.name.to_s} + :javascript $('#accordion').on('show.bs.collapse', miqAccordSelect); diff --git a/app/views/shared/_explorer_tree.html.haml b/app/views/shared/_explorer_tree.html.haml deleted file mode 100644 index a9cc9e64f0c0..000000000000 --- a/app/views/shared/_explorer_tree.html.haml +++ /dev/null @@ -1,8 +0,0 @@ --# Common partial for all available explorer trees --# Locals: --# name - name of the accordion which renders the given tree --# Used instance variables: --# @trees - all the available trees generated with TreeBuilder - -- tree = @trees.length == 1 ? @trees.first : @trees.detect { |t| t.type == name.to_sym } -= render :partial => 'shared/tree', :locals => {:tree => tree, :name => tree.name.to_s}