.row
  .col-md-12
    .page-header
      %h2
        Users
        - if @users
          = "(#{@users.length})"
        = link_to 'New User', new_admin_user_path, class: 'btn btn-success pull-right'
.row
  .col-md-12
    %table.table.table-striped.table-bordered.table-hover.datatable
      %thead
        %th ID
        %th State
        %th Email
        %th Name
        %th Attended Conferences
        %th Roles
        %th View
        %th Edit
        %th Delete
      %tbody
        - @users.each do |user|
          %tr
            %td
              = user.id
            %td
              - if user.confirmed?
                confirmed
              - else
                unconfirmed
            %td
              = user.email
            %td
              = user.name
            %td
              = user.registrations.where(attended: true).count
            %td
              - unless user.get_roles.blank?
                = show_roles(user.get_roles.first(2))
                - if user.get_roles.count > 2
                  = '...'
              - else
                None
            - if can? :show, user
              %td
                = link_to 'View', admin_user_path(user), class: 'btn btn-success'
            - if can? :update, user
              %td
                = link_to 'Edit', edit_admin_user_path(user), class: 'btn btn-primary'
            - if can? :destroy, user
              %td
                - if current_user.id == user.id or user.role_ids.include? 3
                  = link_to 'Delete',admin_user_path(user), :method => :delete , :data => {:confirm => 'Are you sure ?'},
                  disabled: true, class: 'btn btn-primary disabled btn-danger', role: 'button'
                - else
                  = link_to 'Delete',admin_user_path(user), method: :delete,
                  data: { confirm: 'Are you sure ?' }, class: 'btn btn-primary btn-danger'