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

  <script>
    window.STATIC_URL = '/static/';
    window.WEBROOT = '/';
  </script>
  <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-route.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-gettext.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 src="{{ STATIC_URL }}horizon/js/horizon.js"></script>

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

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

  <!-- Magic Search library must be after magic-search override widget -->
  <script src="{{ STATIC_URL }}horizon/lib/magic_search/magic_search.js"></script>

  {% block source %}
  {% endblock %}

  <!-- test files - mock and spec -->
  {% block spec %}
    {% for file in HORIZON_CONFIG.js_spec_files %}
      <script src='{{ STATIC_URL }}{{ file }}'></script>
    {% endfor %}
  {% endblock %}

</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 external_template in HORIZON_CONFIG.external_templates %}
          '{{ STATIC_URL }}{{ external_template }}',
        {% 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>
