{% extends "rpt_base.html" %}
{% load staticfiles %}

{% block extra_css %}
table.universe_choices tr {
    vertical-align: top;
}

table.universe_choices td {
    padding: 0.5em;
}

table.universe_choices p {
    margin-top: 0.5em;
    margin-bottom: 0;
    padding: 0;
}

table.universe_choices h3 {
    margin: 0;
    padding: 0;
}

table.universe_choices ul.lookup_list {
    margin: 0;
}
{% endblock %}

{% block content %}
{% if universes|length == 0 %}
    <p>There are no reporting universes specified! Please investigate the reporting definitions, editions, and reporting table objects in the admin panel.</p>
{% else %}
    <p>Choose a reporting universe to begin building your query.</p>
    
    <form method="GET" action="">
        <table class="universe_choices">
        {% for u in universes %}
            <tr>
                <td><input type="radio" name="universe_pk" value="{{ u.pk }}" /></td>
                <td>
                    <h3>{{ u.name }} (Universe {{ u.pk }})</h3>
                    {% if u.description and u.description|length > 0 %}
                        {{ u.description|linebreaks }}
                    {% endif %}
                    {% with dtbl=u.data.via %}
                        {% if dtbl %}
                            <h4>Data Table</h4>
                            <ul>
                                {% with def=dtbl.definition %}
                                    <li>Definition {{ def.pk }}: {{ def.data_source.abbreviation }} {{ def.category }}</li>
                                {% endwith %}
                                {% with ed=dtbl.edition %}
                                    <li>Edition {{ ed.pk }}: {{ ed.name }} ({{ ed.created_at }})</li>
                                {% endwith %}
                                <li>Database Object: {{ dtbl.name }}</li>
                            </ul>
                        {% endif %}
                    {% endwith %}
                    {% with lu_all=u.lookups.all  %}
                        {% if lu_all|length > 0 %}
                            <h4>{{ lu_all|length }} Lookup Table(s) Available</h4>
                            <ul class="lookup_list">
                                {% for lu in lu_all %}
                                <li>{{ lu.name }}
                                    <ul>
                                        {% with def=lu.via.definition %}
                                            <li>Definition {{ def.pk }}: {{ def.data_source.abbreviation }} {{ def.category }}</li>
                                        {% endwith %}
                                        {% with ed=lu.via.edition %}
                                            <li>Edition {{ ed.pk }}: {{ ed.name }} ({{ ed.created_at }})</li>
                                        {% endwith %}
                                        <li>Database Object: {{ lu.via.name }}</li>
                                    </ul>
                                </li>
                                {% endfor %}
                            </ul>
                        {% else %}
                            <p>No lookups in this universe.</p>
                        {% endif %}
                    {% endwith %}
                </td>
            </tr>
        {% endfor %}
        <tr>
            <td>&nbsp;</td><td><input type="submit" value="Next&rarr;" /></td>
        </tr>
        </table>
    </form>
{% endif %}
<!--
    <ol>
        <li>Filter on any of the columns represented by Column objects.</li>
        <li>Add these dynamically, and finally concatenate a JSON string with the contents.</li>
    </ol>

    <div class="filtergroup top_level_filtergroup" id="top_level_filtergroup">
        <input type="radio" name="filtergroup_op[]" class="filtergroup_op" value="or" checked="checked" />Match any
        <br /><input type="radio" name="filtergroup_op[]" class="filtergroup_op" value="all" />Match all
        <ul class="filter_list" id="filter_list-0">
        </ul>
        <input type="button" value="More filters" class="add_filter" />
    </div>

    <input type="button" value="to_json" class="to_json" />
-->
{% endblock %}
