{% load url from future %}
<!DOCTYPE html>
<html>
<head>
  <title>Jasmine Spec Runner</title>
  <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}horizon/lib/jasmine/jasmine.css">

  <script src="{% url 'horizon:jsi18n' 'horizon' %}"></script>
  <script src="{{ STATIC_URL }}horizon/lib/jasmine/jasmine.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/jasmine/jasmine-html.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/jasmine/boot.js"></script>
  <script src='{{ STATIC_URL }}horizon/lib/jquery/jquery.js'></script>
  <script src='{{ STATIC_URL }}horizon/lib/spin.js'></script>
  <script src='{{ STATIC_URL }}horizon/lib/spin.jquery.js'></script>
  <script src="{{ STATIC_URL }}horizon/lib/angular/angular.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/angular/angular-mocks.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/angular/angular-cookies.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/angular/angular-bootstrap.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/angular/angular-sanitize.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/angular/smart-table.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/angular/lrdragndrop.js"></script>
  <script src="{{ STATIC_URL }}horizon/lib/d3.js"></script>

  <script type="text/javascript">
    /* Load angular modules extensions list before we include angular/horizon.js */
    var angularModuleExtension = {{ HORIZON_CONFIG.angular_modules|default:"[]"|safe }};
  </script>

  <!-- source files -->
  {% for file in sources %}
    <script src="{{ STATIC_URL }}{{ file }}"></script>
  {% endfor %}

  <!-- spec files -->
  {% for file in specs %}
    <script src="{{ STATIC_URL }}{{ file }}"></script>
  {% endfor %}

  <!-- plugin source files -->
  {% for file in HORIZON_CONFIG.js_files %}
    <script src='{{ STATIC_URL }}{{ file }}'></script>
  {% endfor %}

  <!-- plugin spec files -->
  {% for file in HORIZON_CONFIG.js_spec_files %}
    <script src='{{ STATIC_URL }}{{ file }}'></script>
  {% endfor %}

</head>
<body>
  <div id="main_content" class="hidden" style="visibility:hidden; height: 0">
    {% block content %}
    {% endblock %}
  </div>

  <script type="text/javascript">
    (function () { 'use strict';

      // Caching all external angular templates

      var templates = [
        {% for externalTemplate in externalTemplates %}
          '{{ STATIC_URL }}{{ externalTemplate }}',
        {% endfor %}
      ];

      var tplmodule = angular.module('templates', []);

      templates.forEach(function (template) {
        cacheTemplate(template, tplmodule);
      });

      function cacheTemplate(template, tplmodule) {
        tplmodule.run(function ($templateCache) {
          $templateCache.put(template, loadSync(template));
        });
      }

      function loadSync(url) {
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, false);
        xhr.send();
        return xhr.status === 200 ? xhr.responseText : null;
      }

    })();
  </script>
</body>
</html>
