{% extends 'nova/base.html' %}
{% load i18n %}

{% block page_header %}
  {% url horizon:nova:instances_and_volumes:instances:index as refresh_link %}
  {# to make searchable false, just remove it from the include statement #}
  {% include "horizon/common/_page_header.html" with title=_("Instances") refresh_link=refresh_link searchable="true" %}
{% endblock page_header %}

{% block dash_main %}
  {% if instances %}
    {% include 'nova/instances_and_volumes/instances/_list.html' %}
  {% else %}
    {% include 'nova/instances_and_volumes/instances/_no_instances.html' %}
  {% endif %}
{% endblock %}

{% block footer_js %}
  <script type="text/javascript" charset="utf-8">
  $(function(){
    function loadInstances(){
      if ($("#ajax_option_box").is(':checked')) {
        $('.refresh').addClass("refreshing");
        $('#instances').load('{% url horizon:nova:instances_and_volumes:instances:refresh %}', function(){
          $('.refresh').removeClass("refreshing");
        });
      };
    }
    setInterval(function(){
      loadInstances();
    }, 15000);

    loadOptionsWidget();

    $("a.refresh").click(function(e){
      e.preventDefault()
      loadInstances();
    })

    function loadOptionsWidget(){
      checkbox = document.createElement("input");
        cb = $(checkbox);
        cb.attr('id', 'ajax_option_box');
        cb.attr('class', 'refreshOption');
        cb.attr('type', 'checkbox');
      checkbox_label = document.createElement("label");
        cbl = $(checkbox_label);
        cbl.attr('class', 'refreshOption');
        cbl.text('auto refresh');
        cbl.attr('for', 'ajax_option_box');
        $('.right').append(cb);
        $('.right').append(cbl);
    }
  })
  </script>
{% endblock footer_js %}
