ManageIQ/manageiq-ui-classic

View on GitHub
app/views/miq_ae_class/_inputs.html.haml

Summary

Maintainability
Test Coverage

- url = url_for_only_path(:action => 'form_method_field_changed', :id => (@ae_method.id || 'new'))
- obs = {:interval => '.5', :url => url}.to_json
- prefix = row_selected_in_grid? ? "cls_" : ""
%table.table.table-striped.table-bordered.table-hover
  %thead
    %tr
      %th.table-view-pf-select
      %th= _('Name')
      %th= _('Data Type')
      %th= _('Default Value')
  %tbody
    - @edit[:new][:fields].each_with_index do |flds, i|
      - unless @edit[:fields_to_delete].include?(flds["id"])
        %tr
          %td
            = link_to({:action => "field_method_delete", :id => flds["id"].to_s, :arr_id => i},
              "data-miq_sparkle_on"  => true,
              "data-miq_sparkle_off" => true,
              'data-method'          => :post,
              :remote                => true,
              :class                 => 'btn btn-default',
              :confirm               => _('Are you sure you want to delete input field from method?'),
              :title                 => _("Click to delete this input field from method")) do
              %i.pficon.pficon-delete
          %td
            = text_field_tag("#{prefix}fields_name_#{i}",
              flds["name"],
              :maxlength         => 50,
              "data-miq_observe" => obs)
          %td
            = select_tag("#{prefix}fields_datatype_#{i}",
              options_for_select(@edit[:new][:available_datatypes], flds["datatype"]),
              "data-miq_observe" => {:url => url}.to_json)
          %td
            = text_field_tag("#{prefix}fields_value_#{i}", flds["default_value"],
              :style             => flds["datatype"] == "password" ? "display:none" : "",
              "data-miq_observe" => obs)
            = password_field_tag("#{prefix}fields_password_value_#{i}", '',
              :placeholder       => placeholder_if_present(flds['default_value']),
              :style             => flds["datatype"] == "password" ? "" : "display:none",
              "data-miq_observe" => obs)
    - if !params[:add] && params[:add] != "new" && session[:field_data].blank?
      %tr{:title => _("Click to add a new parameter"),
        :onclick => remote_function(:url => {:action => 'field_method_select', :add => 'new', :item => "field"})}
        %td
          %button.btn.btn-default
            %i.fa.fa-plus
        %td
          = h("<#{_('New Parameter')}>")
        %td
          &nbsp;
        %td
          &nbsp;
    - else
      %tr
        %td
          = link_to({:action => "field_method_accept", :button => "accept"},
          "data-miq_sparkle_on"  => true,
          "data-miq_sparkle_off" => true,
          'data-method'          => :post,
          :remote                => true,
          :class                 => 'btn btn-default',
          :title                 => _("Add this entry")) do
            %i.pficon.pficon-save
        %td
          = text_field_tag("#{prefix}field_name",
            session[:field_data][:name],
            "data-miq_observe" => obs)
        %td
          = select_tag("#{prefix}field_datatype", options_for_select(@edit[:new][:available_datatypes], session[:field_data][:datatype]), "data-miq_observe" => {:url => url}.to_json)
        %td
          = text_field_tag("#{prefix}field_default_value",
            session[:field_data][:default_value],
            :style             => session[:field_data][:datatype] == "password" ? "display:none" : "",
            "data-miq_observe" => obs)
          = password_field_tag("#{prefix}field_password_value", '',
            :placeholder       => placeholder_if_present(session[:field_data][:data_value]),
            :style             => session[:field_data][:datatype] == "password" ? "" : "display:none",
            "data-miq_observe" => obs)