app/controllers/storage_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 %w(all_vms vms hosts).include?(@display) 
    if params[:pressed].starts_with?("vm_", 
                                     "miq_template_",
                                     "guest_",
                                     "host_")
      scanhosts if params[:pressed] == "host_scan"
      analyze_check_compliance_hosts if params[:pressed] == "host_analyze_check_compliance"
      check_compliance_hosts if params[:pressed] == "host_check_compliance"
      refreshhosts   if params[:pressed] == "host_refresh"
      tag(Host) if params[:pressed] == "host_tag"
      assign_policies(Host) if params[:pressed] == "host_protect"
      edit_record  if params[:pressed] == "host_edit"
      deletehosts if params[:pressed] == "host_delete"
      pfx = pfx_for_vm_button_pressed(params[:pressed])
      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("_")) 
      else
        process_vm_buttons(pfx)
        return if ["host_tag", "#{pfx}_policy_sim", "host_scan", "host_refresh", "host_protect",
                   "#{pfx}_compare", "#{pfx}_tag", "#{pfx}_protect", "#{pfx}_retire",
                   "#{pfx}_ownership", "#{pfx}_right_size", "#{pfx}_reconfigure"].include?(params[:pressed]) &&
                  @flash_array.nil?   
        unless ["host_edit", "#{pfx}_edit", "#{pfx}_miq_request_new", "#{pfx}_clone", "#{pfx}_migrate", "#{pfx}_publish"].include?(params[:pressed])
          @refresh_div = "main_div"
          @refresh_partial = "layouts/gtl"
          show
          @display = "vms"
        end
      end
    else
      @refresh_div = "main_div" 
      refreshstorage if params[:pressed] == "storage_refresh"
      tag(Storage) if params[:pressed] == "storage_tag"
      scanstorage if params[:pressed] == "storage_scan"
      deletestorages if params[:pressed] == "storage_delete"
      custom_buttons if params[:pressed] == "custom_button"
    end
    return if ["custom_button"].include?(params[:pressed])    
    return if ["storage_tag"].include?(params[:pressed]) && @flash_array.nil?   
    if !@flash_array && !@refresh_partial 
      add_flash(_("Button not yet implemented"), :error)
      @refresh_partial = "layouts/flash_msg"
      @refresh_div = "flash_msg_div"
    elsif @flash_array && @lastaction == "show"
      @storage = @record = identify_record(params[:id])
      @refresh_partial = "layouts/flash_msg"
      @refresh_div = "flash_msg_div"
    end
    if !@flash_array.nil? && params[:pressed] == "storage_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") || ["#{pfx}_miq_request_new", "#{pfx}_clone",
                                                   "#{pfx}_migrate", "#{pfx}_publish"].include?(params[:pressed])
      render_or_redirect_partial(pfx)
    else
      if !flash_errors? && @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 %w( all_vms vms hosts ) . include? ( @display ) if params [ :pressed ] . starts_with? ( "vm_" , "miq_template_" , "guest_" , "host_" ) scanhosts if params [ :pressed ] == "host_scan" analyze_check_compliance_hosts if params [ :pressed ] == "host_analyze_check_compliance" check_compliance_hosts if params [ :pressed ] == "host_check_compliance" refreshhosts if params [ :pressed ] == "host_refresh" tag ( Host ) if params [ :pressed ] == "host_tag" assign_policies ( Host ) if params [ :pressed ] == "host_protect" edit_record if params [ :pressed ] == "host_edit" deletehosts if params [ :pressed ] == "host_delete" pfx = pfx_for_vm_button_pressed ( params [ :pressed ] ) 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 ( "_" ) ) else process_vm_buttons ( pfx ) return if [ "host_tag" , "#{pfx}_policy_sim" , "host_scan" , "host_refresh" , "host_protect" , "#{pfx}_compare" , "#{pfx}_tag" , "#{pfx}_protect" , "#{pfx}_retire" , "#{pfx}_ownership" , "#{pfx}_right_size" , "#{pfx}_reconfigure" ] . include? ( params [ :pressed ] ) && @flash_array . nil? unless [ "host_edit" , "#{pfx}_edit" , "#{pfx}_miq_request_new" , "#{pfx}_clone" , "#{pfx}_migrate" , "#{pfx}_publish" ] . include? ( params [ :pressed ] ) @refresh_div = "main_div" @refresh_partial = "layouts/gtl" show @display = "vms" end end else @refresh_div = "main_div" refreshstorage if params [ :pressed ] == "storage_refresh" tag ( Storage ) if params [ :pressed ] == "storage_tag" scanstorage if params [ :pressed ] == "storage_scan" deletestorages if params [ :pressed ] == "storage_delete" custom_buttons if params [ :pressed ] == "custom_button" end return if [ "custom_button" ] . include? ( params [ :pressed ] ) return if [ "storage_tag" ] . include? ( params [ :pressed ] ) && @flash_array . nil? if ! @flash_array && ! @refresh_partial add_flash ( _ ( "Button not yet implemented" ) , :error ) @refresh_partial = "layouts/flash_msg" @refresh_div = "flash_msg_div" elsif @flash_array && @lastaction == "show" @storage = @record = identify_record ( params [ :id ] ) @refresh_partial = "layouts/flash_msg" @refresh_div = "flash_msg_div" end if ! @flash_array . nil? && params [ :pressed ] == "storage_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" ) || [ "#{pfx}_miq_request_new" , "#{pfx}_clone" , "#{pfx}_migrate" , "#{pfx}_publish" ] . include? ( params [ :pressed ] ) render_or_redirect_partial ( pfx ) else if ! flash_errors? && @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 or hosts # Handle buttons from sub-items screen # Handle Host power buttons # Handle specific power button # Tag screen is showing, so return # Default div for button.rjs to refresh # custom button screen, so return, let custom_buttons method handle everything # Tag screen showing, so return # if no button handler ran, show not implemented msg # redirect to build the retire screen