- user_is_maintainer = (@package && User.current.can_modify_package?(@package)) || (@project && User.current.can_modify_project?(@project.api_obj))
- data = { 'save-user' => url_for(action: 'save_person'),
-          'remove' => url_for(action: 'remove_role'),
-          'save-group' => url_for(action: 'save_group'),
-          'project' => @project.name }
- data[:package] = @package.name if @package
#involved-users{ data: data }
  - if @users.present?
    %h3
      User Roles #{image_tag 'ajax-loader.gif', id: 'user_spinner', class: 'hidden'}
    %table.compact.stripe#user-table
      %thead
        %tr
          %td Username
          - @roles.each do |role|
            %td= role.title.capitalize
          %td
      %tbody
        - @users.each do |user|
          %tr{ id: "user-#{valid_xml_id(user.login)}" }
            %td= user_with_realname_and_icon(user)
            - @roles.each do |role|
              %td{ data: { user: user.login, role: role.title, type: 'user' } }
                - if defined? @package
                  = check_box_tag('user_' + role.title + '_' + user.login, '',
                    @package.user_has_role?(user, role), disabled: !user_is_maintainer, class: 'trigger')
                  - if @project.user_has_role?(user, role)
                    = link_to(sprite_tag('project', title: 'Inherited from project'), controller: 'project', action: 'users', project: @project)
                - else
                  = check_box_tag('user_' + role.title + '_' + user.login, '', @project.user_has_role?(user, role), disabled: !user_is_maintainer, class: 'trigger')
            %td.nowrap
              - unless User.current.is_nobody?
                - mail_subject = 'openSUSE Build Service - ' + @project.name
                - mail_subject += '/' + @package.name if defined? @package
                = mail_to user.email, sprite_tag('email', title: 'Send mail to user'), subject: mail_subject
                - if user_is_maintainer
                  = link_to sprite_tag('user_delete', title: 'Remove user'), { action: 'remove_role', project: @project, package: @package, userid: user.login }, { data: { confirm: "Really remove '#{user.login}'?" }, method: :post, class: 'remove-user' }
  - if user_is_maintainer
    %p
      = link_to(sprited_text('user_add', 'Add user'), { action: :add_person, package: @package, project: @project }, id: 'add-user')
  - unless @groups.blank?
    %h3
      Group Roles #{image_tag 'ajax-loader.gif', id: 'group_spinner', class: 'hidden'}
    %table.compact.stripe#group-table
      %thead
        %tr
          %td Group name
          - @roles.each do |role|
            %td= role.title.capitalize
          - if user_is_maintainer
            %td
      %tbody
        - @groups.each do |group|
          %tr
            %td= link_to(group.title, controller: 'groups', action: 'show', title: group.title)
            - @roles.each do |role|
              = content_tag(:td, data: { group: group.title, role: role.title, type: 'group' }) do
                - if @package
                  = check_box_tag('group_' + role.title + '_' + group.title, '', @package.group_has_role?(group, role), disabled: !user_is_maintainer, class: :trigger)
                  - if @project.group_has_role?(group, role)
                    = link_to(sprite_tag('project', title: 'Inherited from project'), controller: 'project', action: 'users', project: @project)
                - else
                  = check_box_tag('group_' + role.title + '_' + group.title, '',
                    @project.group_has_role?(group, role), disabled: !user_is_maintainer, class: :trigger)
            - if user_is_maintainer
              %td
                = link_to sprite_tag('group_delete', title: 'Remove group'), { action: 'remove_role', project: @project, package: @package, groupid: group }, { data: { confirm: "Really remove '#{group}'?" }, method: :post }
  - if user_is_maintainer
    %p
      = link_to sprited_text('group_add', 'Add group'), action: :add_group, package: @package, project: @project
= content_for :ready_function do
  - if @users && @users.length > 0
    $('#user-table').dataTable({
    'columns': [
    null,
    - @roles.length.times do
      null,
    {'orderable': false}
    ],
    'info': false,
    'paging': false,
    });
  - if @groups && @groups.length > 0
    $('#group-table').dataTable({
    'columns': [
    null,
    - @roles.length.times do
      null,
    - if user_is_maintainer
      {'orderable': false}
    ],
    'searching': false,
    'info': false,
    'paging': false,
    });
  - if user_is_maintainer
    $('.trigger').click(function() { change_role($(this)) } );
