ManageIQ/manageiq-ui-classic

View on GitHub
app/views/miq_policy/_miq_policy_edit_conditions.haml

Summary

Maintainability
Test Coverage
- url = url_for_only_path(:action => 'policy_field_changed', :id => (@policy.id || 'new'))
- observe_with_interval = {:interval => '.5', :url => url}.to_json
#policy_conditions_div
  - if @policy
    #policy_info_div
      = render :partial => "layouts/flash_msg"
      -# Description and active fields
      %h3= _("Condition Selection")
      .col-md-5
        = _("Available %{model} Conditions:") % {:model => ui_lookup(:model => @edit[:new][:towhat])}
        %span#choices_chosen_div
          = select_tag('choices_chosen[]',
            options_for_select(@edit[:choices].sort),
            :multiple => true,
            :size     => 15,
            :class    => "form-control",
            :style    => "overflow-x: scroll;",
            :id       => "choices_chosen",
            :onchange => 'rightArrowSwitch()')
        %small
          = _("* If all Conditions are removed from a Policy, it will be unconditional and always evaluate to true.")
        :javascript
          function rightArrowSwitch() {
            document.querySelector('#btn-mv-right').disabled = (document.querySelector('#choices_chosen').selectedIndex == -1);
          }

      .col-md-1{:style => "padding: 10px"}
        .spacer
        .spacer
        - [['btn-mv-right', _("Move selected Conditions into this Policy"),   'choices_chosen_div', 'move_right',   'fa-angle-right',       true],
           ['btn-rm-all',   _("Remove all Conditions from this Policy"),      nil,                  'move_allleft', 'fa-angle-double-left', @edit[:new][:conditions].empty?],
           ['btn-mv-left',  _("Remove selected Conditions from this Policy"), 'members_chosen_div', 'move_left',    'fa-angle-left',        true]].each do |id, title, chosen_div, action, arrow_style, disabled|
          %button.btn.btn-default.btn-block{:title       => title,
                                  :id                    => id,
                                  :disabled              => disabled,
                                  :remote                => true,
                                  "data-submit"          => chosen_div,
                                  "data-method"          => :post,
                                  "data-miq_sparkle_on"  => true,
                                  "data-miq_sparkle_off" => true,
                                  "data-click_url"       => {:url => url_for_only_path(:action => 'miq_policy_edit',
                                                                                       :button => action,
                                                                                       :id => @policy)}.to_json}
            %i.fa.fa-lg.hidden-xs.hidden-sm{:class => arrow_style}
            %i.fa.fa-lg.fa-rotate-90.hidden-md.hidden-lg{:class => arrow_style}
        .spacer

      .col-md-5
        = _("Policy Conditions:")
        %br
        %span#members_chosen_div
          = select_tag('members_chosen[]',
            options_for_select(@edit[:new][:conditions].sort),
            :multiple => true,
            :size     => 15,
            :class    => "form-control",
            :style    => "overflow-x: scroll;",
            :id       => "members_chosen",
            :onchange => "leftArrowSwitch()")
        :javascript
          function leftArrowSwitch() {
            document.querySelector('#btn-mv-left').disabled = (document.querySelector('#members_chosen').selectedIndex == -1);
          }
    = render :partial => '/layouts/edit_form_buttons',
             :locals  => {:action_url => "miq_policy_edit_conditions", :record_id => @edit[:rec_id], :ajax_buttons => true}