{% extends "base.html" %}

{% load umap_tags compress i18n %}

{% block body_class %}content{% endblock %}

{% block extra_head %}
    {% compress css %}
      {% umap_css %}
    {% endcompress css %}
    {% umap_js %}
{% endblock %}

{% block header %}
  <header class="wrapper row">
    {% include 'umap/navigation.html' with title=SITE_NAME %}
  </header>
{% endblock %}

{% block content %}
  {% block maincontent %}
  {% endblock maincontent %}
{% endblock content %}

{% block bottom_js %}
  {{ block.super }}
  <script type="text/javascript">
    !(function() {
    var ui = new L.U.UI(document.querySelector('header'));
    var xhr = new L.U.Xhr(ui);
    var login = document.querySelector('a.login');
    if (login) {
      L.DomEvent.on(login, 'click', function (e) {
        L.DomEvent.stop(e);
        xhr.login({
            "login_required": this.getAttribute('href'),
            "redirect": "/"
        });
      });
    }
    var logout = document.querySelector('a.logout');
    if (logout) {
      L.DomEvent.on(logout, 'click', function (e) {
        L.DomEvent.stop(e);
        xhr.logout(this.getAttribute('href'));
      });
    }
    var getMore = function (e) {
      L.DomEvent.stop(e);
      xhr._ajax({
        uri: this.href,
        verb: 'GET',
        callback: function (data) {
            var container = this.parentNode;
            container.innerHTML = data;
            Array.prototype.forEach.call(container.querySelectorAll('script'), function (item) {
                eval(item.firstChild.textContent);
            });
            var more = document.querySelector('.more_button');
            if (more) {
              L.DomEvent.on(more, 'click', getMore, more);
            }
        },
        context: this
      });
    };
    var more = document.querySelector('.more_button');
    if (more) {
      L.DomEvent.on(more, 'click', getMore, more);
    }
    })(this);
  </script>
{% endblock bottom_js %}

{% block footer %}
  {{ block.super }}
  {% include "umap/content_footer.html" %}
{% endblock footer %}
