{% extends 'main/base.html' %}

{% load i18n %}
{% load staticfiles %}

{% block javascript %}

  <script type="text/javascript" src="{% static 'rest_framework_swagger/lib/shred.bundle.js' %}"></script>
  <script src='{% static "rest_framework_swagger/lib/jquery.slideto.min.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/lib/jquery.wiggle.min.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/lib/jquery.ba-bbq.min.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/lib/jquery.cookie.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/lib/handlebars-1.0.0.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/lib/underscore-min.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/lib/backbone-min.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/lib/swagger.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/swagger-ui.min.js" %}' type='text/javascript'></script>
  <script src='{% static "rest_framework_swagger/lib/highlight.7.3.pack.js" %}' type='text/javascript'></script>

  <script type="text/javascript">
    $(function () {
      window.swaggerUi = new SwaggerUi({
      url: "{{ swagger_settings.discovery_url }}",
      apiKey: "{{ swagger_settings.api_key }}",
      dom_id: "swagger-ui-container",
      supportedSubmitMethods: {{ swagger_settings.enabled_methods }},
      onComplete: function(swaggerApi, swaggerUi){
        if(console) {
          console.log("Loaded SwaggerUI")
        }
        $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
      },
      onFailure: function(data) {
        if(console) {
          console.log("Unable to Load SwaggerUI");
          console.log(data);
        }
      },
      docExpansion: "none"
    });

    $('#input_apiKey').change(function() {
      var key = $('#input_apiKey')[0].value;
      console.log("key: " + key);
      if(key && key.trim() != "") {
        console.log("added key " + key);
        window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "Token " + key, "header"));
      }
    })
    {% if swagger_settings.api_key %}
    window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "Token " + "{{ swagger_settings.api_key }}", "header"));
    {% endif %}
    window.swaggerUi.load();
  });

  </script>
{% endblock %}

{% block stylesheets %}
  <link href="{% static 'rest_framework_swagger/css/highlight.default.css' %}" media="screen" rel="stylesheet" type="text/css"/>
  <link href='{% static "rest_framework_swagger/css/rest_framework_swagger.css" %}' media='screen' rel='stylesheet' type='text/css'/>
  <link href='{% static "rest_framework_swagger/css/screen.css" %}' media='screen' rel='stylesheet' type='text/css'/>
{% endblock %}

{% block title %} :: {% trans 'API documentation' %}{% endblock %}

{% block content %}
    <div class="content">
        <h2 class="title">{% trans 'API documentation' %}</h2>
        <div class="inner">
            <div id="message-bar" class="swagger-ui-wrap">
              &nbsp;
            </div>
            <div id="swagger-ui-container" class="swagger-ui-wrap">
            </div>
        </div>
    </div>
{% endblock content %}
