{#
# 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 %}
{% from "search/admin_helpers.html" import collection_tree with context %}
{% from "search/helpers.html" import search_also with context %}
{% extends "page.html" %}
{% set title = _("WebSearch Admin") %}

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

{% block header %}
  {{ super() }}

<style type="text/css">
    /* This minimal height is important to be able to attach
     * an item to any list of collection tree.
     */
    .sortable ul { min-height:10px; }

    .sortable ul li:first-child {
        margin-top: 10px !important;
    }

    .invenio-state-active {
        background-color: #EEE;
    }

    ul.sortable:hover:empty
    ,.invenio-state-highlight {
        height: 1.5em; line-height: 1.2em;
        border: 0.2em dashed #ccc;
        border-radius-topright: 30px 20px;
        border-radius-topleft: 30px 20px;
    }

</style>
{% endblock header %}

{% block body %}
<div class="subnav">
    <ul class="nav nav-pills" >
        <li class="dropdown">
        <a  class="dropdown-toggle"
            data-toggle="dropdown"
            href="#">{{ _('Collection') }}
            <b class="caret"></b>
        </a>
        <ul class="dropdown-menu">
            <li><a href="#">{{ _('Create New') }}</a></li>
            <li><a href="#">{{ _('Add to Tree') }}</a></li>
        </ul>
        </li>
        <li> <a href="#">{{ _('Manage Collection Tree') }}</a></li>
    </ul>
</div>

<div class="row">
  <div style="min-height: 30px; padding: 10px;" class="trash droppable connectedSortable col-md-8" data-id="0">
    <i class="glyphicon glyphicon-trash"></i> {{ _('Drop here to delete.') }}
  </div>
</div>


<div class="row">
  <div class="col-md-4 collection">
    <h4>{{ _("Narrow by collections") }}</h4>
    {{ collection_tree(collection, '_collection_children_r', class="nav nav-list sortable
    connectedSortable" ) }}
  </div>

  <div class="col-md-4 collection">
    <h4>{{ _("Focus on") }}</h4>
    {{ collection_tree(collection, '_collection_children_v', class="nav nav-list sortable
    connectedSortable") }}
  </div>

  <div class="col-md-4 collection">
    <ul class="nav nav-list">
      <li class="dropdown-header">{{ _('Orphans') }}</li>
      <li>
        <ul class="nav nav-list draggable" data-id="0" data-len="{{ orphans|length() }}" >
      {% if orphans %}
      {% for c in orphans %}
      <li data-id-son="{{ c.id }}"
          data-id-dad="0"
          data-type="{{ c.type }}">
        <a  href="{{ url_for(".manage_collection", name=c.name) }}" >
          {{ c.name }}
        </a>
      </li>
      {% endfor %}
      {% endif %}
      </ul>
      </li>
    </ul>
  </div>
</div>
{% endblock %}

{% block javascript %}
<script type="text/javascript">
require(['jquery', 'js/admin/search/index'], function($, index) {
  $(function() {
    index({
      url: {
        modifycollectiontree: '{{url_for('.modifycollectiontree')}}'
      },
      message: {
        invalid: "{{ _('Invalid tree modification.') }}"
      }
    })
  })
})
</script>
{% endblock %}
