ManageIQ/manageiq-ui-classic

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

Summary

Maintainability
Test Coverage
:javascript
  ManageIQ.gridChecks = [];

- grid_name  = options[:grid_name]
- grid_id    = options[:grid_id]
- grid_hash  = options[:grid_hash]
- button_div = options[:button_div]

- unless @parent.nil?
  - layout = @layout
  :javascript
    ManageIQ.record.parentId    = "#{@parent.id}";
    ManageIQ.record.parentClass = "#{j @parent.class.base_class.to_s.underscore}";

    if (ManageIQ.record.parentClass == "policy_set") {
      ManageIQ.record.parentClass = "policy";
    } else if (ManageIQ.record.parentClass == "ext_management_system") {
      ManageIQ.record.parentClass = "#{j layout}";
    }

- if options[:action_url]
  - action_url = options[:action_url]
  :javascript
    ManageIQ.actionUrl = "#{j action_url}";

:javascript
  ManageIQ.grids["#{j grid_name}"] = {
    g_id: "#{j grid_id}",
    opts: #{raw js_options.to_json},
    hash: #{raw grid_hash.to_json},
  };

-# ensure row_url ends with a trailing / or = (or is nil)
- row_url = js_options[:row_url]
- if row_url.ends_with? '_none_'
  - row_url = nil
- if row_url && (! row_url.ends_with? '/') && (! row_url.ends_with? '=')
  - row_url += '/'

-# pre-escape
- row_url = row_url.nil? ? 'null' : "'#{j row_url}'"
- row_url_ajax = !! js_options[:row_url_ajax] # force bool to prevent JS syntax errors

%table.table.table-striped.table-bordered.table-hover.table-selectable
  %thead
    %tr
      - grid_hash[:head].each do |h|
        %th{:class => h[:is_narrow] ? 'table-view-pf-select' : ''}
          - text = translate_header_text(h[:text])
          - if h[:sort]
            %a{:href => '#',
               :onclick => "miqGridSort(#{h[:col_idx] + 1})"}
              = text
          - else
            = text

          - if @sortcol && @sortcol == h[:col_idx]
            .pull-right
              - sorticon = (@sortdir.nil? || @sortdir == 'ASC') ? 'fa fa-sort-asc' : 'fa fa-sort-desc'
              %i{:class => sorticon}
  %tbody
    - grid_hash[:rows].each do |row|
      %tr{:onclick => "miqRowClick('#{j row[:id]}', #{row_url}, #{j row_url_ajax.to_s}); return false;"}
        - row[:cells].each do |cell|
          - click = cell[:is_checkbox] || cell[:is_button]
          - narrow = click || cell[:icon]
          %td{:class => narrow ? 'table-view-pf-select' : '', :onclick => click ? "event.stopPropagation()" : false}
            - if cell[:is_checkbox]
              = check_box_tag("check_#{row[:id]}", row[:id], false,
                :onchange => "miqGridOnCheck(this, '#{button_div}')",
                :class => "list-grid-checkbox")
            - elsif cell[:is_button]
              %button.btn.btn-primary{:onclick => cell[:onclick] + "; return false;",
                                      :title   => cell[:title],
                                      :alt     => cell[:title]}
                = cell[:text]
            - elsif cell[:span]
              %span{:class => "#{cell[:span]}"}
                = cell[:text]
            - else
              - if cell[:icon]
                %i{:class => cell[:icon], :title => cell[:title]}
              - elsif cell[:image]
                = image_tag(image_path(cell[:image]), :alt => cell[:title], :title => cell[:title])
              = cell[:text]