<h1>Retry an autopkgtest job</h1>

<noscript>
  <p>
  To retry an autopkgtest job via this page, you need Javascript enabled on your
  browser.
  </p>

  <p>
  Without it, you will need to make a HTTP POST request to this page URL,
  for example using <code>curl</code> or <code>wget</code>, authenticated
  with a valid SSL client certificate or with a valid Debci key (see
  the <a href="/doc/file.API.html">API documentation</a>).
  </p>
</noscript>

<form method="POST">
  <p>
  Once you click the "Retry" button below, an autopkgtest with the same
  settings as the original will be triggered on the infrastructure.
  </p>

  <%== erb(:_job_info, locals: {job: @original_job}) %>

  <div id='result-info' style='display: none'>
    <p>
      Your request has been successfully submitted.
    </p>
  </div>

  <% if @same_jobs > 0 %>
    <p class="retry-warning">
      <i class="fa fa-exclamation-triangle"></i>
      <strong>Warning: There <%= @same_jobs == 1 ? " is 1 existing job ": "are #{@same_jobs} existing jobs" %> with the same parameters.</strong>
    </p>
  <% end %>
  <input type='button' value='Retry' onclick='retry(this)' class='btn btn-primary'/>
</form>

<script type='text/javascript'>
  function displayresult() {
    var status = this.status
    if (Math.floor(status/100) == 2) {
      var resinfo = document.getElementById('result-info')
      resinfo.style.display = 'block'
    } else {
      var text = this.statusText
      alert("An error occurred while requesting a retry: " + status + " " + text)
    }
  }

  function retry(button) {
    var request = new XMLHttpRequest();
    request.addEventListener('load', displayresult)
    request.open("POST", document.location.href)
    request.send()
  }
</script>
<noscript>
  <style type='text/css'>
    form { display: none }
  </style>
</noscript>
