
<div id="tl_maintenance_index" class="maintenance_<?= $this->isActive ? 'active' : 'inactive' ?>">

  <h2 class="sub_headline_index"><?= $this->indexHeadline ?></h2>

  <?php if ($this->indexMessage): ?>
    <div class="tl_message">
      <p class="tl_error"><?= $this->indexMessage ?></p>
    </div>
  <?php endif; ?>

  <?php if ($this->isRunning): ?>
    <div id="tl_rebuild_index">
      <p id="index_loading"><?= $this->loading ?></p>
      <p id="index_complete" style="display:none"><?= $this->complete ?></p>
      <p style="margin-bottom:0"><?= $this->content ?></p>
    </div>

    <script>
      window.addEvent('domready', function() {
        var queue = new Request.Queue({
          onEnd: function() {
            $('index_loading').setStyle('display', 'none');
            $('index_complete').setStyle('display', 'block');
          },
          concurrent: 1,
          stopOnFailure: false
        });
        $$('.page_url').each(function(el, i) {
          el.getAttribute('data-url') && queue.addRequest(i, new Request({
            onSuccess: function() {
              el.addClass('tl_green');
            },
            onFailure: function(xhr) {
              el.addClass('tl_red');
              el.set('text', '[' + xhr.status + '] ' + el.get('text'));
            },
            url: el.getAttribute('data-url')
          }));
        });
        Object.values(queue.requests).invoke('get');
      });
    </script>

    <form action="<?= $this->action ?>" class="tl_form" method="get">
      <div class="tl_submit_container">
        <input type="hidden" name="do" value="maintenance">
        <input type="submit" id="index" class="tl_submit" value="<?= $this->indexContinue ?>">
      </div>
    </form>

  <?php else: ?>
    <form action="<?= $this->action ?>" class="tl_form" method="get">
      <div class="tl_formbody_edit">
        <input type="hidden" name="act" value="index">
        <input type="hidden" name="do" value="maintenance">
        <input type="hidden" name="rt" value="<?= REQUEST_TOKEN ?>">
        <div class="tl_tbox">
          <h3><label for="ctrl_user"><?= $this->indexLabel ?></label></h3>
          <select name="user" id="ctrl_user" class="tl_select">
            <?php foreach ($this->user as $id=>$name): ?>
              <option value="<?= $id ?>"><?= $name ?></option>
            <?php endforeach; ?>
          </select>
          <?php if ($this->indexHelp): ?>
            <p class="tl_help tl_tip"><?= $this->indexHelp ?></p>
          <?php endif; ?>
        </div>
      </div>
      <div class="tl_submit_container">
        <input type="submit" id="index" class="tl_submit" value="<?= $this->indexSubmit ?>">
      </div>
    </form>
  <?php endif; ?>

</div>
