<header class='row'>
  <div class='span5 col-sm-5'>
    <h3><%=t 'CronJobs' %></h3>
  </div>
</header>
<% if @cron_jobs.size > 0 %>

  <table class="table table-hover table-bordered table-striped table-white">
    <thead>
      <th><%= t('Status') %></th>
      <th><%= t('Name') %></th>
      <th><%= t('Cron string') %></th>
      <th><%= t('Last enque') %></th>
      <th width="180"><%= t('Actions')%></th>
    </thead>

    <tbody>
      <% @cron_jobs.sort{|a,b| a.sort_name <=> b.sort_name }.each_with_index do |job, index| %>
        <% style = "#{job.status == 'disabled' ? "background: #ecc": ""}" %>
        <tr>
          <td style="<%= style %>"><%= t job.status %></td>
          <td style="<%= style %>">
            <b><%= job.name %></b>
            <hr style="margin:3px;border:0;">
            <small>
            <% if job.message and job.message.to_s.size > 100 %>
              <button data-toggle="collapse" data-target=".worker_<%= index %>" class="btn btn-xs"><%= t('ShowAll')%></button>
              <div class="toggle worker_<%= index %>" style="display: inline;"><%= job.message[0..100] + "... " %></div>
              <div class="toggle worker_<%= index %>" style="display: none;"><%= job.message %></div>
            <% else %>
              <%= job.message %>
            <% end %>
            </small>
          </td>
          <td style="<%= style %>"><b><%= job.cron.gsub(" ", "&nbsp;") %></b></td>
          <td style="<%= style %>"><%= job.last_enqueue_time ? relative_time(job.last_enqueue_time) : "-" %></td>
          <td style="<%= style %>">
            <% if job.status == 'enabled' %>
              <form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/enque" method="post">
                <%= csrf_tag if respond_to?(:csrf_tag) %>
                <input class='btn btn-xs pull-left' type="submit" name="enque" value="<%= t('EnqueueNow') %>"/>
              </form>
              <form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/disable" method="post">
                <%= csrf_tag if respond_to?(:csrf_tag) %>
                <input class='btn btn-xs pull-left' type="submit" name="disable" value="<%= t('Disable') %>"/>
              </form>
            <% else %>
              <form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/enque" method="post">
                <%= csrf_tag if respond_to?(:csrf_tag) %>
                <input class='btn btn-xs pull-left' type="submit" name="enque" value="<%= t('EnqueueNow') %>"/>
              </form>
              <form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/enable" method="post">
                <%= csrf_tag if respond_to?(:csrf_tag) %>
                <input class='btn btn-xs pull-left' type="submit" name="enable" value="<%= t('Enable') %>"/>
              </form>
              <form action="<%= root_path %>cron/<%= CGI.escape(job.name).gsub('+', '%20') %>/delete" method="post">
                <%= csrf_tag if respond_to?(:csrf_tag) %>
                <input class='btn btn-xs btn-danger pull-left' type="submit" name="delete" value="<%= t('Delete') %>" data-confirm="<%= t('AreYouSureDeleteCronJob', :job => job.name) %>"/>
              </form>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <span class='alert alert-success'><%= t('NoCronJobsFound') %></span>
<% end %>

