app/controllers/host_controller.rb
# handle buttons pressed on the button bar
handle buttons pressed on the button bar
handle buttons pressed on the button bar
def button
    @edit = session[:edit]                                  
    params[:display] = @display if ["vms", "storages"].include?(@display)  
    if params[:pressed].starts_with?("vm_", 
                                     "miq_template_",
                                     "guest_",
                                     "storage_")
      pfx = pfx_for_vm_button_pressed(params[:pressed])
      process_vm_buttons(pfx)
      scanstorage if params[:pressed] == "storage_scan"
      refreshstorage if params[:pressed] == "storage_refresh"
      tag(Storage) if params[:pressed] == "storage_tag"
      return if ["host_drift", "#{pfx}_compare", "#{pfx}_tag", "#{pfx}_policy_sim",
                 "#{pfx}_retire", "#{pfx}_protect", "#{pfx}_ownership",
                 "#{pfx}_reconfigure", "#{pfx}_retire", "#{pfx}_right_size",
                 "storage_tag"].include?(params[:pressed]) && @flash_array.nil?
      unless ["#{pfx}_edit", "#{pfx}_miq_request_new", "#{pfx}_clone", "#{pfx}_migrate", "#{pfx}_publish"].include?(params[:pressed])
        @refresh_div = "main_div"
        @refresh_partial = "layouts/gtl"
        show
      end
    else                                                                        
      params[:page] = @current_page unless @current_page.nil?                     
      @refresh_div = "main_div" 
      drift_analysis if params[:pressed] == "common_drift"
      redirect_to :action => "new" if params[:pressed] == "new"
      deletehosts if params[:pressed] == "host_delete"
      comparemiq if params[:pressed] == "host_compare"
      refreshhosts if params[:pressed] == "host_refresh"
      scanhosts if params[:pressed] == "host_scan"
      check_compliance_hosts if params[:pressed] == "host_check_compliance"
      analyze_check_compliance_hosts if params[:pressed] == "host_analyze_check_compliance"
      tag(Host) if params[:pressed] == "host_tag"
      assign_policies(Host) if params[:pressed] == "host_protect"
      edit_record if params[:pressed] == "host_edit"
      custom_buttons if params[:pressed] == "custom_button"
      prov_redirect if params[:pressed] == "host_miq_request_new"
      if ["host_shutdown", "host_reboot", "host_standby", "host_enter_maint_mode", "host_exit_maint_mode",
          "host_start", "host_stop", "host_reset"].include?(params[:pressed])
        powerbutton_hosts(params[:pressed].split("_")[1..-1].join("_")) 
      end
      perf_chart_chooser if params[:pressed] == "perf_reload"
      perf_refresh_data if params[:pressed] == "perf_refresh"
      return if ["custom_button"].include?(params[:pressed])    
      return if ["host_tag", "host_compare", "common_drift",
                 "host_protect", "perf_reload"].include?(params[:pressed]) &&
                @flash_array.nil? 
      if @flash_array.nil? && !@refresh_partial && !["host_miq_request_new"].include?(params[:pressed]) 
        add_flash(_("Button not yet implemented"), :error)
        @refresh_partial = "layouts/flash_msg"
        @refresh_div = "flash_msg_div"
      elsif @flash_array && @lastaction == "show"
        @host = @record = identify_record(params[:id])
        @refresh_partial = "layouts/flash_msg"
        @refresh_div = "flash_msg_div"
      end
    end
    if @lastaction == "show" && ["custom_button", "host_miq_request_new"].include?(params[:pressed])
      @host = @record = identify_record(params[:id])
    end
    if !@flash_array.nil? && params[:pressed] == "host_delete" && @single_delete
      render :update do |page|
        page.redirect_to :action => 'show_list', :flash_msg => @flash_array[0][:message]  
      end
    elsif params[:pressed].ends_with?("_edit") || ["host_miq_request_new", "#{pfx}_miq_request_new",
                                                   "#{pfx}_clone", "#{pfx}_migrate",
                                                   "#{pfx}_publish"].include?(params[:pressed])
      if @flash_array
        show_list
        replace_gtl_main_div
      else
        if @redirect_controller
          if ["host_miq_request_new", "#{pfx}_clone", "#{pfx}_migrate", "#{pfx}_publish"].include?(params[:pressed])
            render :update do |page|
              if flash_errors?
                page.replace("flash_msg_div", :partial => "layouts/flash_msg")
              else
                page.redirect_to :controller     => @redirect_controller,
                                 :action         => @refresh_partial,
                                 :id             => @redirect_id,
                                 :prov_type      => @prov_type,
                                 :prov_id        => @prov_id,
                                 :org_controller => @org_controller,
                                 :escape         => false
              end
            end
          else
            render :update do |page|
              page.redirect_to :controller => @redirect_controller, :action => @refresh_partial, :id => @redirect_id, :org_controller => @org_controller
            end
          end
        else
          render :update do |page|
            page.redirect_to :action => @refresh_partial, :id => @redirect_id
          end
        end
      end
    else
      if @refresh_div == "main_div" && @lastaction == "show_list"
        replace_gtl_main_div
      else
        render_flash
      end
    end
  end
def button @edit = session [ :edit ] params [ :display ] = @display if [ "vms" , "storages" ] . include? ( @display ) if params [ :pressed ] . starts_with? ( "vm_" , "miq_template_" , "guest_" , "storage_" ) pfx = pfx_for_vm_button_pressed ( params [ :pressed ] ) process_vm_buttons ( pfx ) scanstorage if params [ :pressed ] == "storage_scan" refreshstorage if params [ :pressed ] == "storage_refresh" tag ( Storage ) if params [ :pressed ] == "storage_tag" return if [ "host_drift" , "#{pfx}_compare" , "#{pfx}_tag" , "#{pfx}_policy_sim" , "#{pfx}_retire" , "#{pfx}_protect" , "#{pfx}_ownership" , "#{pfx}_reconfigure" , "#{pfx}_retire" , "#{pfx}_right_size" , "storage_tag" ] . include? ( params [ :pressed ] ) && @flash_array . nil? unless [ "#{pfx}_edit" , "#{pfx}_miq_request_new" , "#{pfx}_clone" , "#{pfx}_migrate" , "#{pfx}_publish" ] . include? ( params [ :pressed ] ) @refresh_div = "main_div" @refresh_partial = "layouts/gtl" show end else params [ :page ] = @current_page unless @current_page . nil? @refresh_div = "main_div" drift_analysis if params [ :pressed ] == "common_drift" redirect_to :action => "new" if params [ :pressed ] == "new" deletehosts if params [ :pressed ] == "host_delete" comparemiq if params [ :pressed ] == "host_compare" refreshhosts if params [ :pressed ] == "host_refresh" scanhosts if params [ :pressed ] == "host_scan" check_compliance_hosts if params [ :pressed ] == "host_check_compliance" analyze_check_compliance_hosts if params [ :pressed ] == "host_analyze_check_compliance" tag ( Host ) if params [ :pressed ] == "host_tag" assign_policies ( Host ) if params [ :pressed ] == "host_protect" edit_record if params [ :pressed ] == "host_edit" custom_buttons if params [ :pressed ] == "custom_button" prov_redirect if params [ :pressed ] == "host_miq_request_new" if [ "host_shutdown" , "host_reboot" , "host_standby" , "host_enter_maint_mode" , "host_exit_maint_mode" , "host_start" , "host_stop" , "host_reset" ] . include? ( params [ :pressed ] ) powerbutton_hosts ( params [ :pressed ] . split ( "_" ) [ 1 .. - 1 ] . join ( "_" ) ) end perf_chart_chooser if params [ :pressed ] == "perf_reload" perf_refresh_data if params [ :pressed ] == "perf_refresh" return if [ "custom_button" ] . include? ( params [ :pressed ] ) return if [ "host_tag" , "host_compare" , "common_drift" , "host_protect" , "perf_reload" ] . include? ( params [ :pressed ] ) && @flash_array . nil? if @flash_array . nil? && ! @refresh_partial && ! [ "host_miq_request_new" ] . include? ( params [ :pressed ] ) add_flash ( _ ( "Button not yet implemented" ) , :error ) @refresh_partial = "layouts/flash_msg" @refresh_div = "flash_msg_div" elsif @flash_array && @lastaction == "show" @host = @record = identify_record ( params [ :id ] ) @refresh_partial = "layouts/flash_msg" @refresh_div = "flash_msg_div" end end if @lastaction == "show" && [ "custom_button" , "host_miq_request_new" ] . include? ( params [ :pressed ] ) @host = @record = identify_record ( params [ :id ] ) end if ! @flash_array . nil? && params [ :pressed ] == "host_delete" && @single_delete render :update do | page | page . redirect_to :action => 'show_list' , :flash_msg => @flash_array [ 0 ] [ :message ] end elsif params [ :pressed ] . ends_with? ( "_edit" ) || [ "host_miq_request_new" , "#{pfx}_miq_request_new" , "#{pfx}_clone" , "#{pfx}_migrate" , "#{pfx}_publish" ] . include? ( params [ :pressed ] ) if @flash_array show_list replace_gtl_main_div else if @redirect_controller if [ "host_miq_request_new" , "#{pfx}_clone" , "#{pfx}_migrate" , "#{pfx}_publish" ] . include? ( params [ :pressed ] ) render :update do | page | if flash_errors? page . replace ( "flash_msg_div" , :partial => "layouts/flash_msg" ) else page . redirect_to :controller => @redirect_controller , :action => @refresh_partial , :id => @redirect_id , :prov_type => @prov_type , :prov_id => @prov_id , :org_controller => @org_controller , :escape => false end end else render :update do | page | page . redirect_to :controller => @redirect_controller , :action => @refresh_partial , :id => @redirect_id , :org_controller => @org_controller end end else render :update do | page | page . redirect_to :action => @refresh_partial , :id => @redirect_id end end end else if @refresh_div == "main_div" && @lastaction == "show_list" replace_gtl_main_div else render_flash end end end
handle buttons pressed on the button bar
handle buttons pressed on the button bar
# Restore @edit for adv search box # Were we displaying vms/storages # Handle buttons from sub-items screen # Control transferred to another screen, so return # Handle Host buttons # Save current page for list refresh # Default div for button.rjs to refresh # Handle Host power buttons # Handle specific power button # custom button screen, so return, let custom_buttons method handle everything # Another screen showing, so return # if no button handler ran, show not implemented msg # redirect to build the retire screen