ManageIQ/manageiq-ui-classic

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

Summary

Maintainability
Test Coverage
- scan_id = "#{@scan.id || 'new'}"
- url = url_for_only_path(:action => 'ap_edit',
                :id     => scan_id)
%h3= _("File Entry")
%table.table.table-striped.table-bordered.table-hover
  %thead
    %tr
      %th= _("Name")
      %th= _("Collect Contents?")
      %th.action-cell= _("Actions")
  %tbody
    - if !params[:add] && params[:add] != "new"
      %tr{:title => _("Click to add a new entry"), :onclick => remote_function(:url => {:action => 'ap_ce_select', :add => 'new', :item => "file", :id => scan_id})}
        %td= _("<New Entry>")
        %td
        %td.action-cell
          %button.btn.btn-default.btn-block.btn-sm
            = _("Add")
    - else
      %tr
        %td
          = text_field("entry", "fname", :maxlength => ViewHelper::MAX_NAME_LEN, :style => "width: 100%;")
          = hidden_field("item", "type1", :value => "file")
        %td
          = check_box_tag("entry_content", 1, false, :id => "entry_content")
        %td.action-cell
          %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}?accept=accept"}.to_json}
            = _("Save")
    - Array(session[:file_names]).sort_by { |r| r["target"] }.each do |entry|
      - if session[:edit_filename] != entry["target"]
        %tr{:class => cycle('row0', 'row1'), :id => "#{entry['target']}_tr"}
          %td{:onclick => remote_function(:url => {:action => 'ap_ce_select', :file_name => entry["target"], :edit_entry => 'edit_file', :field => "fname", :id => scan_id}), :title => _("Click to update this entry")}
            = h(entry["target"])
          %td{:onclick => remote_function(:url => {:action => 'ap_ce_select', :file_name => entry["target"], :edit_entry => 'edit_file', :field => "fname", :id => scan_id}), :title => _("Click to update this entry")}
            = h(entry["content"] ? entry["content"] : false)

          %td.action-cell{:onclick => remote_function(:url => {:action => 'ap_ce_delete', :file_name => entry["target"], :id => scan_id}), :title => _("Click to delete this entry")}
            %button.btn.btn-default.btn-block.btn-sm
              = _("Delete")
      - else
        - if params[:add] != "new"
          %tr{:class => cycle('row0', 'row1'), :id => "edit_tr"}
            %td
              = text_field("entry", "fname", :maxlength => ViewHelper::MAX_NAME_LEN, "value" => session[:edit_filename], :style => "width: 100%;")
              = hidden_field("item", "type1", :value => "file")
            %td
              - checked = !!entry["content"]
              = check_box_tag("entry_content", 1, checked, :id => "entry_content")
              = hidden_field("item", "type1", :value => "file")
            %td.action-cell
              %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}?accept=accept"}.to_json}
                = _("Save")