{#
# 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 render_field with context %}

{% macro collection_tree(collection, children ) %}

<ul class="nav nav-list">
  <li class="dropdown-header">{{ collection.name }}</li>
  <li>
  <ul {{ kwargs|xmlattr }}  data-id="{{ collection.id }}">
    {% for c in collection|attr(children)|sort(attribute='score') recursive %}
    <li data-id-son="{{ c.id_son }}"
        data-id-dad="{{ c.id_dad }}"
        data-type="{{ c.type }}">
    {% if c.type == 'v' %}
    <i>
    <a  href="{{ url_for(".manage_collection", name=c.son.name) }}" >
        {{ c.son.name }}
    </a>
    </i>
    {% else %}
    <a  href="{{ url_for(".manage_collection", name=c.son.name) }}" >
        {{ c.son.name }}
    </a>
    {% endif %}
    <ul {{ kwargs|xmlattr }} data-id="{{ c.son.id }}">
    {% if c.son.sons %}
        {{ loop(c.son.sons|sort(attribute='score')) }}
    {% endif %}
    </ul>
    </li>
    {% endfor %}
  </ul>
  </li>
</ul>
{% endmacro %}

{% macro collection_translations(collection) %}
<div {{ kwargs|xmlattr }}>
    <h2>{{ _('Modify translations') }}</h2>
    {% if config.CFG_LANGUAGE_LIST_LONG %}
        <form class="form-horizontal" method="POST" action="{{ url_for('.update_translations', id=collection.id) }}">
        {% for field in translation_form%}
              {{ render_field(field)}}
        {% endfor %}
        <div class="form-actions">
            <p><input type="submit" name="send_button" value="{{ _("Send") }}" class="btn
            btn-primary"/></p>
        </div>
        </form>
    {% endif %}
</div>
{% endmacro %}

{% macro portalboxes_admin(collection) %}
    <a href="#" >{{ _('Create a new portalbox') }}</a>

    <ul id="sortable" class="nav nav-list" data-id="{{ collection.id }}">
    {% for k,l in collection.portalboxes_ln|groupby('position') -%}
        {% for portalbox in l %}
        <li data-id="{{portalbox.id_portalbox}}">
        <a href="#" data-id="{{ portalbox.id }}" class="modalloader" >{{ portalbox.portalbox.title }}</a>
        </li>
        {% endfor %}
    {% endfor %}
    </ul>
{% endmacro %}
