<table id="permissions_manage" class="noborder">
    <tr>
        <td>${_('none')}</td>
        <td>${_('read')}</td>
        <td>${_('write')}</td>
        <td>${_('admin')}</td>
        <td>${_('member')}</td>
        <td></td>
    </tr>
    ## USERS
    %for r2p in c.repos_group.repo_group_to_perm:
        <tr id="id${id(r2p.user.username)}">
            <td>${h.radio('u_perm_%s' % r2p.user.username,'group.none')}</td>
            <td>${h.radio('u_perm_%s' % r2p.user.username,'group.read')}</td>
            <td>${h.radio('u_perm_%s' % r2p.user.username,'group.write')}</td>
            <td>${h.radio('u_perm_%s' % r2p.user.username,'group.admin')}</td>
            <td style="white-space: nowrap;">
                <img class="perm-gravatar" src="${h.gravatar_url(r2p.user.email,14)}"/>${r2p.user.username}
            </td>
            <td>
              %if r2p.user.username !='default':
                <span class="delete_icon action_button" onclick="ajaxActionUser(${r2p.user.user_id},'${'id%s'%id(r2p.user.username)}')">
                ${_('revoke')}
                </span>
              %endif
            </td>
        </tr>
    %endfor

    ## USERS GROUPS
    %for g2p in c.repos_group.users_group_to_perm:
        <tr id="id${id(g2p.users_group.users_group_name)}">
            <td>${h.radio('g_perm_%s' % g2p.users_group.users_group_name,'group.none')}</td>
            <td>${h.radio('g_perm_%s' % g2p.users_group.users_group_name,'group.read')}</td>
            <td>${h.radio('g_perm_%s' % g2p.users_group.users_group_name,'group.write')}</td>
            <td>${h.radio('g_perm_%s' % g2p.users_group.users_group_name,'group.admin')}</td>
            <td style="white-space: nowrap;">
                <img class="perm-gravatar" src="${h.url('/images/icons/group.png')}"/>${g2p.users_group.users_group_name}
            </td>
            <td>
                <span class="delete_icon action_button" onclick="ajaxActionUsersGroup(${g2p.users_group.users_group_id},'${'id%s'%id(g2p.users_group.users_group_name)}')">
                ${_('revoke')}
                </span>
            </td>
        </tr>
    %endfor
    <tr id="add_perm_input">
        <td>${h.radio('perm_new_member','group.none')}</td>
        <td>${h.radio('perm_new_member','group.read')}</td>
        <td>${h.radio('perm_new_member','group.write')}</td>
        <td>${h.radio('perm_new_member','group.admin')}</td>
        <td class='ac'>
            <div class="perm_ac" id="perm_ac">
                ${h.text('perm_new_member_name',class_='yui-ac-input')}
                ${h.hidden('perm_new_member_type')}
                <div id="perm_container"></div>
            </div>
        </td>
        <td></td>
    </tr>
    <tr>
        <td colspan="6">
            <span id="add_perm" class="add_icon" style="cursor: pointer;">
            ${_('Add another member')}
            </span>
        </td>
    </tr>
</table>
<script type="text/javascript">
function ajaxActionUser(user_id, field_id) {
    var sUrl = "${h.url('delete_repos_group_user_perm',group_name=c.repos_group.group_name)}";
    var callback = {
        success: function (o) {
            var tr = YUD.get(String(field_id));
            tr.parentNode.removeChild(tr);
        },
        failure: function (o) {
            alert("${_('Failed to remove user')}");
        },
    };
    var postData = '_method=delete&user_id=' + user_id;
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
};

function ajaxActionUsersGroup(users_group_id,field_id){
    var sUrl = "${h.url('delete_repos_group_users_group_perm',group_name=c.repos_group.group_name)}";
    var callback = {
        success:function(o){
            var tr = YUD.get(String(field_id));
            tr.parentNode.removeChild(tr);
        },
        failure:function(o){
            alert("${_('Failed to remove users group')}");
        },
    };
    var postData = '_method=delete&users_group_id='+users_group_id;
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
};

YUE.onDOMReady(function () {
    if (!YUD.hasClass('perm_new_member_name', 'error')) {
        YUD.setStyle('add_perm_input', 'display', 'none');
    }
    YAHOO.util.Event.addListener('add_perm', 'click', function () {
        YUD.setStyle('add_perm_input', 'display', '');
        YUD.setStyle('add_perm', 'opacity', '0.6');
        YUD.setStyle('add_perm', 'cursor', 'default');
    });
    MembersAutoComplete(
            ${c.users_array|n},
            ${c.users_groups_array|n},
            "${_('Group')}",
            "${_('members')}"
          );
});

</script>
