{% extends "freeadmin/generic_model_datagrid.html" %}
{% load humanize_size %}

{% block actions_static_buttons %}
{{ block.super }}
    <div class="gridAdd left">
      <button id="datagridBtn_Boot_Add" data-dojo-type="dijit.form.Button" type="button">
          {% blocktrans with name=verbose_name %}Create{% endblocktrans %}
      <script type="dojo/method" data-dojo-event="onClick" data-dojo-args="evt">
          editObject('{% trans "Create Boot"|escapejs %}', '{% url "system_bootenv_add" %}', [this,]);
      </script>
      </button>
      <button id="datagridBtn_Boot_Scrub" data-dojo-type="dijit.form.Button" type="button">
          {% blocktrans %}Scrub Boot{% endblocktrans %}
      <script type="dojo/method" data-dojo-event="onClick">
          editObject('Boot Scrub', '{% url "system_bootenv_scrub" %}', [this,]);
      </script>
      <button id="datagridBtn_Status" data-dojo-type="dijit.form.Button" type="button">
          {% blocktrans %}Status{% endblocktrans %}
      <script type="dojo/method" data-dojo-event="onClick">
          viewModel('Boot Status', '{% url "freeadmin_system_bootstatus_datagrid" %}', [this,]);
      </script>
      </button>
    </div>
    {% if bootme %}
      <div class="gridAdd left" style="padding-left: 10px">
        <strong>{% trans "Boot Volume Condition" %}: {{ stats.0 }} {{ stats.1 }}</strong><br />
          {% if bootme.scrub.status == "IN_PROGRESS" %}
            <p style="padding: 3px;">{% trans "Scrub Status" %}: {{ bootme.scrub.status_verbose }}</p>
            <!-- comment this till one can find a auto refresh method
            <p style="padding: 3px;">
              {% if bootme.scrub.progress %}{% trans "Progress" %}: {{ bootme.scrub.progress }}% &nbsp; &nbsp; {% endif %}
              {% if bootme.scrub.scanned %}{% trans "Scan" %}: {% blocktrans with scanned=bootme.scrub.scanned total=bootme.scrub.total %}{{ scanned }} out of {{ total }}{% endblocktrans %} &nbsp; &nbsp; {% endif %}
            </p>
            -->
          {% endif %}
        {% if bootme.scrub.date %}<p style="padding-bottom: 0px;">{% trans "Last Scrub Run on" %}: {{ bootme.scrub.date }} &nbsp; &nbsp; </p>{% endif %}
      </div>
    {% endif %}
      <div class="gridAdd left" style="padding-left: 10px">
        <strong>{% trans "Size" %}:</strong> {{ zlist.size|humanize_size }}<br />
        <p style="padding-bottom: 0px;">
	  <strong>{% trans "Used" %}:</strong> {{ zlist.alloc|humanize_size }} ({{ zlist.capacity }}%)
	</p>
      </div>
    <div style="clear: both;"></div>
    <div class="gridAdd" style="padding: 4px;">
        <div data-dojo-type="dijit/form/TextBox" style="width: 30px; margin-right: 2px;" value="{{ advanced.adv_boot_scrub }}">
            <script type="dojo/method" data-dojo-event="onChange" data-dojo-args="value">
	        var textbox = this;
                this.set('disabled', true);
                require([
                    "dojo/request/xhr",
	            "dijit/TooltipDialog",
	            "dijit/popup"
                ], function(
	            xhr,
	            TooltipDialog,
	            popup
	        ) {
                    xhr.post('{% url "system_bootenv_scrub_interval" %}', {
                       headers: {"X-CSRFToken": CSRFToken},
                       data: {"interval": value},
	               handleAs: 'json'
	            }).then(function(data) {

                        if(data.error == true) {
                          var td = new TooltipDialog({
                            content: data.message,
                            onMouseLeave: function() {
                              popup.close(td);
                              td.destroyRecursive();
                            }
                          });
                          popup.open({
                            popup: td,
                            around: textbox.domNode,
                            orient: ["above", "after", "below-alt"]
                          });
                        }
                        textbox.set('disabled', false);

	            });
                });
            </script>
	</div> <span>{% trans "Automatic scrub interval (in days)" %}</span>
    </div>
{% endblock %}
