ManageIQ/manageiq-ui-classic

View on GitHub
app/views/ops/_ap_form_registry.html.haml

Summary

Maintainability
Test Coverage
- scan_id = "#{@scan.id || 'new'}"
- url = url_for_only_path(:action => 'ap_edit',
                :id     => scan_id)
%h3= _("Registry Entry")
%table.table.table-striped.table-bordered.table-hover
  %thead
    %tr
      %th= _("Registry Hive")
      %th= _("Registry Key")
      %th= _("Registry Value")
      %th.action-cell= _("Actions")
  %tbody
    - if (!params[:add] && session[:reg_data].empty?) || params[:edit_entry]
      %tr{:title => _("Click to add a new entry"),
        :onclick => remote_function(:url => {:action => 'ap_ce_select', :add => 'new', :item1 => "registry", :id => "#{@scan.id || "new"}"})}
        %td= _("<New Entry>")
        %td= _("<New Entry>")
        %td= _("<New Entry>")
        %td.action-cell
          %button.btn.btn-default.btn-block.btn-sm
            = _("Add")
    - else
      %tr
        %td
          = _("HKLM")
        %td
          = text_field("entry", "kname",
            :maxlength => ViewHelper::MAX_NAME_LEN,
            "value"    => session[:reg_data][:key],
            :style     => "width: 100%;")
        %td
          = text_field("entry", "value",
            :maxlength => ViewHelper::MAX_NAME_LEN,
            "value"    => session[:reg_data][:value],
            :style     => "width: 100%;")

        %td.action-cell
          - url = url_for_only_path(:action => 'ap_edit',
                          :id     => scan_id,
                          :accept => 'accept',
                          :item_type => 'registry')
          %button.btn.btn-default.btn-block.btn-sm{:title => _("Add this entry"),
                                  "data-submit"         => 'ap_form_div',
                                  "data-miq_sparkle_on" => true,
                                  :remote               => true,
                                  "data-method"         => :post,
                                  'data-click_url'      => {:url => url}.to_json}
            = _("Save")
        = hidden_field("item", "type2", :value => "registry")
    - if !session[:reg_entries].nil? && !session[:reg_entries].empty?
      - session[:reg_entries].sort_by { |r| r["key"] }.each_with_index do |reg, i|
        - if session[:reg_data][:key] == reg["key"] && session[:reg_data][:value] == reg["value"]
          %tr#edit_tr
            %td
              = _("HKLM")
            %td
              = text_field("entry", "kname",
                :maxlength => ViewHelper::MAX_NAME_LEN,
                "value"    => session[:reg_data][:key],
                :style     => "width: 100%;")
            %td
              = text_field("entry", "value",
                :maxlength => ViewHelper::MAX_NAME_LEN,
                "value"    => session[:reg_data][:value],
                :style     => "width: 100%;")
            %td.action-cell
              - url = url_for_only_path(:action => 'ap_edit',
                          :id         => scan_id,
                          :accept     => 'accept',
                          :edit_entry => 'edit_entry',
                          :entry_id   => i)
              %button.btn.btn-default.btn-block.btn-sm{:title                 => _("Update this entry"),
                                                        "data-submit"         => 'ap_form_div',
                                                        "data-miq_sparkle_on" => true,
                                                        :remote               => true,
                                                        "data-method"         => :post,
                                                        'data-click_url'      => {:url => url}.to_json}
                = _("Save")
            = hidden_field("item", "type2", :value => "registry")
            = hidden_field("entry", "id", :value => i)
        - else
          %tr{:id => "registry_row_#{i}"}
            - url = {:action     => 'ap_ce_select',
                     :entry_id   => i,
                     :item2      => "registry",
                     :reg_key    => reg["key"],
                     :reg_value  => reg["value"],
                     :edit_entry => 'edit_registry',
                     :field      => "kname",
                     :id         => "#{@scan.id || "new"}"}
            - remote_link = remote_function(:url => url).to_str
            %td{:onclick => remote_link, :title => _("Click to update this entry")}
              = _("HKLM")
            %td{:onclick => remote_link, :title => _("Click to update this entry")}
              = h(reg["key"])
            %td{:onclick => remote_link, :title => _("Click to update this entry")}
              = h(reg["value"])
            - url[:action] = "ap_ce_delete"
            - remote_link = remote_function(:url => url).to_str
            %td.action-cell{:onclick => remote_link, :title => _("Click to delete this entry")}
              %button.btn.btn-default.btn-block.btn-sm
                = _("Delete")