CommunityGrows/communitygrows

View on GitHub
app/views/category/_category_table.html.haml

Summary

Maintainability
Test Coverage
%h5 
  = link_to "Sort Categories By Name", category_index_path(:sort_by => "name")
%div#categories
  %ul#invisible#sortable1
    - @categories.each do |category|
      %table.table.table-striped.table-bordered{:id => "table_#{category.id}"}
        %thead.bg-info
          %tr
            %th Category Name
            %th Hide/Show Category
            %th Delete Category
        %tbody
          %td= link_to "#{category.name}", edit_category_path(category.id)
          - if category.hidden?
            %td
              = button_to show_category_path(category.id), method: :get, class: 'btn btn-info btn-xs hidden-xs' do
                %span.glyphicon.glyphicon-eye-open
                Show #{category.name}
              = button_to show_category_path(category.id), method: :get, class: 'btn btn-info visible-xs' do
                %span.glyphicon.glyphicon-eye-open
          - elsif category.documents.length != 0
            %td
              = button_to hide_category_path(category.id), method: :get, class: 'btn btn-warning btn-xs hidden-xs', data: { confirm: "There are documents in this category, are you sure you want to hide it?"} do
                %span.glyphicon.glyphicon-eye-close
                Hide #{category.name}
              = button_to hide_category_path(category.id), method: :get, class: 'btn btn-warning visible-xs', data: { confirm: "There are documents in this category, are you sure you want to hide it?"} do
                %span.glyphicon.glyphicon-eye-close
          -else 
            %td
              = button_to hide_category_path(category.id), method: :get, class: 'btn btn-warning btn-xs hidden-xs' do
                %span.glyphicon.glyphicon-eye-close
                Hide #{category.name}
              = button_to hide_category_path(category.id), method: :get, class: 'btn btn-warning visible-xs' do
                %span.glyphicon.glyphicon-eye-close
          %td
            = button_to delete_category_path(category.id), :method => :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-xs hidden-xs' do
              %span.glyphicon.glyphicon-remove
              Delete #{category.name}
            = button_to delete_category_path(category.id), :method => :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger visible-xs' do
              %span.glyphicon.glyphicon-remove
          %tr
            %td{colspan: 3}
              %table.table.table-striped.table-bordered
                %thead.bg-info
                  %tr
                    %th File name
                    %th Updated at
                    %th Read Status
                  %tbody#sortable2
                    = render :partial => "documents/documents_table", :locals => { :docs => category.documents, :curr_user => curr_user }
            %hr