ManageIQ/manageiq-ui-classic

View on GitHub
app/views/layouts/_x_edit_buttons.html.haml

Summary

Maintainability
Test Coverage
- if @angular_form
  - @angular_form = false
  - return
-# Set default action url, if none passed in
- action_url ||= nil
- return if action_url == "tagging_edit"
-# Set default record id to nil, if none passed in
- record_id ||= nil
- align ||= "right"
-# Default button for menus editor
- default_button ||= nil
-# don't need cancel button in OPS
- no_cancel ||= nil
-# don't need reset button
- no_reset ||= nil
-# need to show save/cancel button, for screens editing multiple records or when @record is not set
- multi_record ||= nil
-# need to show submit button instead of save button
- submit_button ||= nil
-# need to show apply button instead of save button
- apply_button ||= nil
-# need to show continue button instead of save button
- continue_button ||= nil
-# need to show copy button instead of save button
- copy_button ||= nil
-# need to show create button instead of save button
- create_button ||= nil
-# need to show confirm message when save button is pressed on database config screen
- save_confirm_text ||= nil
-# need to show title on save button on database config screen
- save_text ||= nil
-# need to show title on apply button on import config screens
- apply_text ||= nil
-# should apply :get or :post the request
- apply_method ||= :get
-# need to show export button on Reports-import/export screen
- export_button ||= nil
-# need to pass this as true if need to send up serialized form data when save is pressed
- serialize ||= false
-# use miqAjaxButton with observeQueue: true (waits for miq-observe inputs first)
- observe_queue ||= false

%div{:style => 'padding-top: 5px'}
  - if action_url && !export_button
    #buttons_on{:style => session[:changed] ? "" : "display: none;"}
      - if record_id.blank? && multi_record.nil? && submit_button.nil? && continue_button.nil?
        = button_tag(t = _('Add'),
          :class   => "btn btn-primary",
          :alt     => t,
          :title   => t,
          :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :button => "add")}', #{serialize}, #{observe_queue ? '{ observeQueue: true }' : 'null'});")
      - else
        - if apply_button
          = link_to(_("Apply"),
            {:action => action_url, :button => "apply", :id => record_id},
            :method => apply_method,
            :class => "btn btn-primary",
            :alt   => apply_text,
            :title => apply_text)
        - elsif export_button
          - t = _("Download Report to YAML")
          = link_to(_("Export"),
            {:action => action_url},
            :class  => "btn btn-primary",
            :type   => "application/txt",
            :alt    => t,
            :title  => t)
        - elsif submit_button
          = button_tag(t = _('Submit'),
            :class   => "btn btn-primary",
            :alt     => t,
            :title   => t,
            :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "submit")}');")
        - elsif continue_button
          = button_tag(t = _('Continue'),
            :class   => "btn btn-primary",
            :alt     => t,
            :title   => t,
            :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "continue")}');")
        - elsif create_button
          = button_tag(t = _('Create'),
            :class   => "btn btn-primary",
            :alt     => t,
            :title   => t,
            :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "create")}',true);")
        - elsif copy_button
          = button_tag(t = _('Copy'),
            :class   => "btn btn-primary",
            :alt     => t,
            :title   => t,
            :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "copy")}',true);")
        - else
          - if save_confirm_text
            -# Ask for confirmation before saving
            = button_tag(_('Save'),
              :class   => "btn btn-primary",
              :alt     => save_text,
              :title   => save_text,
              :onclick => "if (confirm('#{save_confirm_text}')) miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "save")}', #{serialize}, #{observe_queue ? '{ observeQueue: true }' : 'null'});")
          - else
            = button_tag(_('Save'),
              :class   => "btn btn-primary",
              :alt     => t = _("Save Changes"),
              :title   => t,
              :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "save")}', #{serialize}, #{observe_queue ? '{ observeQueue: true }' : 'null'});")

        - unless no_reset
          = button_tag(_('Reset'),
            :class   => "btn btn-default",
            :alt     => t = _("Reset Changes"),
            :title   => t,
            :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "reset")}');")
      - if default_button
        = button_tag(_('Default'),
          :class   => "btn btn-default",
          :alt     => t = _("Reset All menus to %{product} defaults") % {:product => Vmdb::Appliance.PRODUCT_NAME},
          :title   => t,
          :onclick => "miqAjaxButton('#{url_for_only_path(:action => "menu_update", :button => "default")}');")
      - unless no_cancel
        = button_tag(t = _('Cancel'),
          :class   => "btn btn-default",
          :alt     => t,
          :title   => t,
          :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "cancel")}');")

    #buttons_off{:style => session[:changed] ? "display: none;" : ""}
      - if record_id.blank? && multi_record.nil? && submit_button.nil? && continue_button.nil?
        = button_tag(_("Add"), :class => "btn btn-primary disabled")
      - else
        - if apply_button
          = button_tag(_("Apply"), :class => "btn btn-primary disabled")
        - elsif submit_button
          = button_tag(_("Submit"), :class => "btn btn-primary disabled")
        - elsif continue_button
          = button_tag(_("Continue"), :class => "btn btn-primary disabled")
        - elsif copy_button
          = button_tag(_("Copy"), :class => "btn btn-primary disabled")
        - else
          = button_tag(_("Save"), :class => "btn btn-primary disabled")

        - unless no_reset
          = button_tag(_("Reset"), :class => "btn btn-default disabled")

      - if default_button
        = button_tag(_('Default'),
          :class   => "btn btn-default",
          :alt     => t = _("Reset All menus to %{product} defaults") % {:product => Vmdb::Appliance.PRODUCT_NAME},
          :title   => t,
          :onclick => "miqAjaxButton('#{url_for_only_path(:action => "menu_update", :button => "default")}');")

      - unless no_cancel
        = button_tag(t = _('Cancel'),
          :class   => "btn btn-default",
          :alt     => t,
          :title   => t,
          :onclick => "miqAjaxButton('#{url_for_only_path(:action => action_url, :id => record_id, :button => "cancel")}');")
  - elsif record_id || export_button
    -# show button to go back
    #buttons
      - if params[:action] == "policies" || %w(chargeback right_size).include?(@sb[:action])
        - action = (params[:action] == "policies" ? "policy_sim" : "x_history")
        -# Button to go back to policy simulation screen from 1 VMs policies
        = button_tag(t = _('Back'),
          :class   => "btn btn-default",
          :alt     => t,
          :title   => t,
          :onclick => "miqAjaxButton('#{url_for_only_path(:controller => controller_for_vm(model_for_vm(@record)), :action => action, :continue => true)}');")
      - elsif %w(drift policy_sim).include?(@sb[:action])
        -# Button to cancel policy simulation/drift and return to latest tree node
        = button_tag(t = _('Cancel'),
          :class   => "btn btn-default",
          :alt     => t,
          :title   => t,
          :onclick => "miqAjaxButton('#{url_for_only_path(:action => "x_history", :item => 0)}');")
      - else
        -# export_button
        = link_to(_("Export"),
          {:action => action_url},
          :class    => "btn btn-primary disabled",
          :type     => "application/txt",
          :alt      => t = _("Download Report to YAML"),
          :title    => t,
          :id       => "export_button")

  - elsif ["compare"].include?(@sb[:action])
    #buttons
      -# Button to cancel policy simulation and return to latest tree node
      = button_tag(t = _('Cancel'),
        :class   => "btn btn-default",
        :alt     => t,
        :title   => t,
        :onclick => "miqAjaxButton('#{url_for_only_path(:action => "x_history", :item => 0)}');")