{#
# 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_field with context %}
{% from "search/admin_helpers.html" import collection_translations, portalboxes_admin with context %}
{% extends "page.html" %}
{% if collection %}
{% set title = _(" Edit Collection") %}
{% else %}
{% set title = _("Create Collection") %}
{% endif %}
{% set personalize_selected = True %}

{% block global_bundles %}
  {{ super() }}
  {% bundle "admin/search.js" %}
{% endblock -%}

{% block body %}
<div class="tabbable">
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab1" data-toggle="tab">Edit Collection</a></li>
        <li><a href="#tab2" data-toggle="tab">Translations</a></li>
        <li><a href="#tab3" data-toggle="tab">Portalboxes</a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tab1">
            <form method="POST" action="{{ url_for('.update', id = collection.id) }}">
                {{ form.csrf_token }}
                {{ form.id }}
                {{ render_field(form.name) }}
                {{ render_field(form.dbquery) }}
                <p><input type="submit" name="send_button" value="{{ _("Send") }}" class="btn
                btn-primary"/></p>
            </form>
        </div>
        {% if collection %}
        <div class="tab-pane" id="tab2">
            {{ collection_translations(collection) }}
        </div>
        <div class="tab-pane" id="tab3">
            {{ portalboxes_admin(collection) }}
          </div>
        {% endif %}
    </div>
</div>

{% endblock body %}

{% block javascript %}
<script type="text/javascript">
require(["jquery", "js/admin/search/portalboxes"], function($, portalboxes) {
  $(function() {
    portalboxes({
      url: "{{url_for('.manage_portalboxes_order')}}"
    })
  })
})
</script>
{% endblock javascript %}
