{#
# This file is part of Invenio.
# Copyright (C) 2012, 2014 CERN.
#
# Invenio is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#}
{% from "_formhelpers.html" import th with context %}
{% from "_formhelpers.html" import render_filter_form with context %}
{% extends "page.html" %}
{% set title = _("Action Administrator") %}
{% block title %}
<div class="page-header">
  <h1>{{ title }} <small>{{ _('administration with actions as access point') }}</small></h1>
</div>
{% endblock title %}

{% block body %}
<script type="text/javascript">
$(document).ready(function() {
  $('#toggleids').change(function() {
    var toggle = $('#toggleids').attr("checked")
    $(".ids").attr("checked", function(i, val) {
      return ! $(this).attr("checked");
    });
  });
});
</script>

<ul class="nav nav-pills">
  <li>
    <a rel="tooltip" title="{{ _('go here to add a new role.') }}" href="{{ url_for('.addrole') }}">
      <i class="glyphicon glyphicon-pencil"></i> {{ _("Create new role") }}
    </a>
  </li>
{#  <li><button class="btn" data-toggle="collapse" data-target="#filter" href="#filter">{{ _("Toggle Filter") }}</button></li>#}
</ul>

<dl>
    <dt>{{ _('Authorizations') }}/{{ _('Roles') }}:</dt>
    <dd>{{ _('these terms means almost the same, but an authorization is a connection between a role and an action (possibly) containing arguments.') }}</dd>
    <dt>{{ _('Actions') }}:</dt>
    <dd>{{ _('see all the information attached to an action.') }}</dd>
</dl>

{#
<div id="filter" class="collapse">
{{ render_filter_form(filter_form, id="filter", class="well form-horizontal") }}
</div>

<form name="message" action="{{ url_for('.delete') }}" method="post">
#}
<table class="table table-striped table-bordered table-condensed">
  <thead class="mailboxheader">
    <tr class="inboxheader">
      <th><input type="checkbox" id="toggleids" /></th>
      {% set filter_args = request.values|invenio_url_args(append='&', filter=['sort_by', 'order']) %}
      {{ th('name', _("name"), filter_args) }}
      {{ th('description', _("authorizations")+'/'+_("roles"), filter_args) }}
      <th>{{ _("Action") }}</th>
    </tr>
  </thead>
  <tfoot>
    <tr class="mailboxfooter">
      <td colspan="5">
        <input type="submit" id="delete-selected" name="delete" value="{{ _("Delete Selected") }}" class="btn btn-danger" />
      </td>
    </tr>
  </tfoot>
  <tbody>
    {% if not actions %}
        <tr style="height: 100px;">
        <td colspan="4" style="text-align: center;">
            <b>{{ _("No actions") }}</b>
        </td>
        </tr>
    {% else %}
        {% for a in actions %}
            <tr>
                <td>
                    <input class="ids" type="checkbox" name="id" value="{{ a.id }}" />
                </td>
                <td><a href="{{ url_for('.showactiondetails', id=a.id) }}">
                    {{ a.name }}
                </a></td>
                <td>{{ a.description }}</td>
                <td><a href="{{url_for('.delete', id=a.id) }}">{{ _("Delete") }}</a></td>
            </tr>
        {% endfor %}
    {% endif %}
  </tbody>
</table>
{#</form>#}
{% endblock %}
