{% extends "base_objectbrowser.html" %}

{% load i18n %}
{% load cycle from future %}

{% block title %}List Objects{% endblock %}
{% block smallheader %}ObjectBrowser{% endblock %}
{% block largeheader %}Search results{% endblock %}
{% block nav1 %}<a href="{% url "objectbrowser" %}">{% trans "objectbrowser" %}</a>{% endblock %}



{% block footer %}
{{ block.super }}
<script>
$(document).ready(function() {
    $('table#objectsearch').dataTable();
});
</script>
{% endblock %}
{% block content %}

    {% if objects %}
        <h2>{% blocktrans with length=objects|length %}{{ length }} potential matches to what you were looking for{% endblocktrans %}</h2>
        <hr>
        <div class="objectbrowser_list_objects ui-tabs ui-widget ui-widget-content ui-corner-all">

            <table border=1 id="objectsearch">
            <thead>
            <tr>
                <th>{% trans "Short Name" %}</th>
                <th>{% trans "Object Type" %}</th>
                <th>{% trans "Object Name" %}</th>
                <th>{% trans "Filename" %}</th>
            </tr>
            </thead>
            <tbody>
            {% for o in objects %}
                <tr class="{% cycle 'even' 'odd' %}">
                    <td><a href="{% url "adagios.objectbrowser.views.edit_object" o.id %}">{{ o.description }}</a></td>
                    <td><a href="{% url "search" %}?object_type={{ o.object_type }}">{{ o.object_type }}</a></td>
                    <td><a href="{% url "adagios.objectbrowser.views.edit_object" o.id %}">{{ o.name }} </a></td>
                    <td><a href="{% url "search" %}?filename={{ o.filename }}">{{ o.filename }}</a></td>
                </tr>
            {% endfor %}
            </tbody>
            </table>
        <br><br>
        </div>
    {% else %}
        {% if services %}
            <h1>{% trans "You are editing a service that is applied to a hostgroup" %}</h1>
            {% trans "The service you want to edit is applied to all hosts in a specific hostgroup. What do you want to do ?" %}
            <ul>
                {% for i in services %}
                    <li>
                        <a href="{% url "adagios.objectbrowser.views.edit_object" object_id=i.id %}">
                            {% blocktrans with name=i.hostgroup_name %}Edit service for all hosts in hostgroup {{ name }}{% endblocktrans %}
                        </a>
                    </li>
                    <li>
                        <a href="{% url "adagios.objectbrowser.views.copy_and_edit_object" object_id=i.id %}?host_name={{ host_name }}&hostgroup_name=None&service_description={{ service_description }}">
                            {% blocktrans %}Create '{{ host_name }}/{{ service_description }}' and edit that one.{% endblocktrans %}
                        </a>
                    </li>
                {% endfor %}
            </ul>
        {% else %}
            <h2>{% trans "Oh no! We couldn't find the objects you are looking for :/" %}</h2>
	    {% url "adagios.objectbrowser.views.list_object_types" as the_url %}
	    {% blocktrans %}
            Perhaps you try browsing for what you were looking for <a href="{{ the_url }}">here</a>
	    {% endblocktrans %}
        {% endif %}
    {% endif %}





{% endblock %}



{% block sidebar %}
    {% if request.GET %}
        {% trans "You searched for the following:" %}
        <table class="" border=1>
        <tr>
            <th>{% trans "Attribute" %}</th>
            <th>Value </th>
        </tr>
        {% for k,v in request.GET.items %}
            <tr>
                <td>{{ k }}</td>
                <td>{{ v }}</td>
            </tr>
        {% endfor %}
        </table>
    {% else %}
        <p>{% trans "No search parameters were used. Showing all items." %}</p>
        <p>{% trans 'Try looking for all <a href="?object_type=host">hosts</a> ' %}</p>
    {%  endif %}
{% endblock %}
