{% extends "newman/ajax_content_base.html" %}
{% load newman cache %}

{% block breadcrumbs %}{% endblock %}
{% block content_toolbar %}{% endblock %}

{% block content %}

{% cache 300 'nm-hp-cal' user %}
<div class="hpcol" style="width: 25%;">
    {% if show_calendar %}
        {# ein Kalendar, bitte #}
        <div class="hpbox calendar">
            <h3><span>{% trans "Calendar" %}</span></h3>
            <div class="cnt">
                <div class="cal">
                </div>
                {% comment %}
                <div class="shortcuts">
                    <a href="">{% trans 'This month' %}</a>
                    | <a href="">{% trans 'This year' %}</a>
                </div>
                {% endcomment %}
            </div>
        </div>
    {% endif %}
{% endcache %}
    {% if site_filter_form %}
    <div class="hpbox setup">
        <h3><span>{% trans "Quick Settings" %}</span></h3>
        <div class="cnt" id="id-hpbox-setup-main-category-filters">
        {# hpbox setup div is handled by JavaScript (Ajax widget -- Filtering by main categories). #}
        </div>
    </div>
    {% endif %}

    <div class="hpbox errmsg">
        <h3><span>{% trans "Report Error" %}</span></h3>
        <div class="cnt">
            <form class="js-form js-reset-on-submit" action="{% url newman:err-report %}" method="post">
                {% csrf_token %}
                <label for="id_err_subject" class="required">{% trans "Subject" %} <span class="help"></span></label>
                <input id="id_err_subject" name="err_subject" type="text" />
                <label for="id_err_message" class="required">{% trans "Message" %}</label>
                <textarea id="id_err_message" name="err_message" rows="4" cols="53"></textarea>
                <div class="submit-row">
                    <a class="icn btn eclear js-reset">{% trans "Clear" %}</a>
                    <a class="icn btn ok def js-submit" title="{% trans "Click to report a bug" %}">{% trans "Send" %}</a>
                </div>
            </form>
        </div>
    </div>

</div>

{% cache 300 'nm-hp-search' user %}
<div class="hpcol" style="width: 50%;">

    <div class="hpbox search" id="search-form">
        <h3><span>{% trans "Search" %}</span></h3>
        <div class="cnt">
            <input type="search" size="50" placeholder="{% trans 'Enter search term...' %}" name="q" />
            <select name="action" size="1">
                {% for ct in searchable_content_types %}
                    <option{% ifequal ct.model 'publishable' %} selected="selected"{% endifequal %} value="/{{ ct.app_label }}/{{ ct.model }}/">{% filter capfirst %}{% trans ct.name %}{% endfilter %}</option>
                {% endfor %}
            </select>
            <a class="icn btn search def">{% trans 'Go' %}</a>
        </div>
    </div>
{% endcache %}

    <div class="hpbox placements" id="search-form">
        <h3><span>{% trans "Future placements" %}</span></h3>
        <div class="cnt">
            {% if not future_placements %}
                <p style="margin: 5px 0; padding: 5px;">{% trans 'No future placements available.' %}</p>
            {% endif %}
            {% for p in future_placements %}
                <div style="background: #{% cycle 'ffe' 'fff' %}; margin: 5px 0; padding: 5px;">
                    <h4>{% trans p.publishable.content_type.name %}: {{ p.publishable.title }}</h4>
                    <p>
                        {% trans "Publish from" %}: <strong>{{ p.publish_from|date }} {{ p.publish_from|time }}</strong>
                        | {% trans "Category" %}: {{ p.category }}
                        | {% trans 'Author' %}: {{ p.publishable.authors.all|join:", " }}
                    </p>
                    {{ p.publishable.description|striptags|truncatewords:32 }}
                    <div class="submit-row ar">
                        <a class="icn btn web" href="{% url newman:index %}r/{{ p.publishable.content_type.pk }}/{{ p.publishable.pk }}/">{% trans 'View on site' %}</a>
                        <a class="icn btn edit def" href="{% url newman:index %}#/{{ p.publishable.content_type.app_label }}/{{ p.publishable.content_type.model }}/{{ p.publishable.pk }}/">{% trans 'Change' %}</a>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>
</div>

<div class="hpcol" style="width: 25%;">

  {% cache 30 'nm-hp-lastlog' user %}
    <div class="hpbox lastlog">
        <h3><span>{% trans "Last edited objects" %}</span></h3>
        <div class="cnt">
            {% newman_log 20 as log_entries %}
            {% if not log_entries %}
            <p>{% trans 'None available' %}</p>
            {% else %}
            <ul class="actionlist">
            {% for entry in log_entries %}
                <li>
                    <h4>
                    {% if not entry.is_deletion %}
                        <a class="js-hashadr icn {% if entry.is_addition %}add{% endif %}{% if entry.is_change %}eclear{% endif %}" href="/{{ entry.content_type.app_label }}/{{ entry.content_type.model }}/{{ entry.object_id }}/">{{ entry.object_repr }}</a>
                    {% else %}
                        <a class="icn cancel">{{ entry.object_repr }}</a>
                    {% endif %}
                    </h4>
                    <span class="mini quiet">
                        {% trans entry.content_type.name %}
                        | {{ entry.action_time|date:"Y-m-d H:i" }}
                        {% if user.is_superuser %}
                        | {{ entry.user }}
                        {% endif %}
                    </span>
                </li>
            {% endfor %}
            </ul>
            {% endif %}
        </div>
    </div>
  {% endcache %}

</div>
<!-- Last changelist filters state -->
<script type="text/javascript">
var changelistFilters = {};
{% for fname, qstring in last_filters.items %}
changelistFilters["{{ fname }}"] = "{{ qstring }}";
{% endfor %}
</script>

{% endblock %}


{% block content_js %}
    {{ block.super }}

    {% cache 300 'nm-hp-js' %}
    <script type="text/javascript">
    request_media('{{ NEWMAN_MEDIA_URL }}css/dashboard.css');
    request_media('{{ NEWMAN_MEDIA_URL }}jquery/jquery-ui-smoothness.css');

    var pubYear = '{{ publishable_lookup_fields.year }}';
    var pubMonth = '{{ publishable_lookup_fields.month }}';
    var pubDay = '{{ publishable_lookup_fields.day }}';
    var selectedYear = 0;
    var selectedMonth = 0;
    var selectedDay = 0;
    $( document ).one('media_loaded', function() {
        var options = new DATEPICKER_OPTIONS({
            onChangeMonthYear: function(year, month, inst) {
                selectedMonth = month;
                selectedYear = year;
            },
            onSelect: function(dateText, inst) {
                adr('/core/publishable/?' +
                    pubYear  + '=' + selectedYear  + '&' +
                    pubMonth + '=' + selectedMonth + '&' +
                    pubDay   + '=' + dateText
                );
            }
        });
        $(".hpbox.calendar .cal").datepicker(options).slideDown('fast');
    });
    </script>
    {% endcache %}
{% endblock %}
