{% extends "admin/base_site.html" %}
{% load i18n static %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
&rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
&rsaquo; {{ opts.verbose_name_plural|capfirst }}
</div>
{% endblock %}

{% block content %}
<h1>{% trans "Django Updater Status" %}</h1>
{% if token %}
    {% if status.registered %}
        <p id="online-status">Checking status online <img src="{% static "updater/ajax-loader.gif" %}"/> </p>
    {% else %}
        <p></p>
    {% endif %}

{% else %}
    <p>Please add your token to <code>settings.py</code></p>
{% endif %}

{% endblock %}

{% block extrahead %}
    {% for js_file in js %}
    <script type="text/javascript" src="{{ js_file }}"></script>
    {% endfor %}
    <script type="text/javascript">
    (function($) {
        $(document).ready(function(){
           if(document.getElementById("online-status")){
               $.ajax({
               url: '{{ service_url }}',
               beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Token {{ token }}');},
               error: function() {
                  $('#online-status').html('<p>An error has occurred</p>');
               },
               success: function(data) {
                   console.log(data);
                  $('#online-status').html(JSON.stringify(data));
               },
               type: 'GET'
            });
           }
        });
    })(django.jQuery);
</script>
{% endblock %}