<%page args="parent,group_name=''" />
    <div class="panel panel-primary">
        <div class="panel-heading clearfix">
            <div class="pull-left panel-title">
                %if c.group is not None:
                    %for group in c.group.parents:
                        ${h.link_to(group.name, url('repos_group_home', group_name=group.group_name))}
                        &raquo;
                    %endfor
                    ${c.group.name}
                %endif
            </div>

            %if request.authuser.username != 'default':
              <div class="pull-right">
                <%
                    gr_name = c.group.group_name if c.group else None
                    # create repositories with write permission on group is set to true
                    group_admin = h.HasRepoGroupPermissionLevel('admin')(gr_name, 'can write into group index page')
                    group_write = h.HasRepoGroupPermissionLevel('write')(gr_name, 'can write into group index page')
                %>
                %if h.HasPermissionAny('hg.admin','hg.create.repository')() or group_admin or group_write:
                  %if c.group:
                        <a href="${h.url('new_repo',parent_group=c.group.group_id)}" class="btn btn-default btn-xs"><i class="icon-plus"></i>${_('Add Repository')}</a>
                        %if h.HasPermissionAny('hg.admin')() or h.HasRepoGroupPermissionLevel('admin')(c.group.group_name):
                            <a href="${h.url('new_repos_group', parent_group=c.group.group_id)}" class="btn btn-default btn-xs"><i class="icon-plus"></i>${_('Add Repository Group')}</a>
                        %endif
                  %else:
                    <a href="${h.url('new_repo')}" class="btn btn-default btn-xs"><i class="icon-plus"></i>${_('Add Repository')}</a>
                    %if h.HasPermissionAny('hg.admin')():
                        <a href="${h.url('new_repos_group')}" class="btn btn-default btn-xs"><i class="icon-plus"></i>${_('Add Repository Group')}</a>
                    %endif
                  %endif
                %endif
                %if c.group and h.HasRepoGroupPermissionLevel('admin')(c.group.group_name):
                    <a href="${h.url('edit_repo_group',group_name=c.group.group_name)}" title="${_('You have admin right to this group, and can edit it')}" class="btn btn-default btn-xs"><i class="icon-pencil"></i>${_('Edit Repository Group')}</a>
                %endif
              </div>
            %endif
        </div>
        <div class="panel-body">
            <table class="table" id="repos_list_wrap" width="100%"></table>
        </div>
    </div>

      <script>
        'use strict';
        var data = ${h.js(c.data)};
        $("#repos_list_wrap").DataTable({
                data: data.records,
                columns: [
                    {data: "raw_name", visible: false, searchable: false},
                    {title: ${h.jshtml(_('Repository'))}, data: "name", orderData: [0,], render: {
                        filter: function(data, type, row) {
                            return row.just_name;
                        }
                    }},
                    {data: "following", defaultContent: '', sortable: false},
                    {data: "desc", title: ${h.jshtml(_('Description'))}, searchable: false},
                    {data: "last_change_iso", defaultContent: '', visible: false, searchable: false},
                    {data: "last_change", defaultContent: '', title: ${h.jshtml(_('Last Change'))}, orderData: [4,], searchable: false},
                    {data: "last_rev_raw", defaultContent: '', visible: false, searchable: false},
                    {data: "last_changeset", defaultContent: '', title: ${h.jshtml(_('Tip'))}, orderData: [6,], searchable: false},
                    {data: "owner", defaultContent: '', title: ${h.jshtml(_('Owner'))}, searchable: false},
                    {data: "atom", defaultContent: '', sortable: false}
                ],
                order: [[1, "asc"]],
                dom: '<"dataTables_left"f><"dataTables_right"ip>t',
                pageLength: 100
            });
      </script>
