{* Cron jobs tab — read-only observer. *}
<div style="margin-bottom:8px;">
    <button type="button" class="btn btn-default btn-xs" id="puq-svc-cron-reload"><i class="fa fa-sync"></i> Reload</button>
    <span class="text-muted small" id="puq-svc-cron-count" style="margin-left:8px;"></span>
</div>
<table class="table table-striped table-condensed" id="puq-svc-cron-table" style="width:100%;">
    <thead><tr>
        <th>ID</th><th>Schedule</th><th>Command</th><th>Status</th><th>Created</th><th>Error</th>
    </tr></thead>
    <tbody></tbody>
</table>
{literal}
<script>
(window.puqSvc = window.puqSvc || {}).init_cron = function(ctx){
    var esc = ctx.esc, baseUrl = ctx.baseUrl, puqId = ctx.puqId, fmtDate = ctx.fmtDate;
    var dt = null;
    function load() {
        puqAjax({ container: '#puq-svc-cron-table', loadingCaption: 'Loading cron jobs…',
            url: baseUrl + 'listServiceCron&id=' + puqId, dataType: 'json',
            success: function(r){
                var rows = (r.status === 'success' && r.data) ? r.data : [];
                $('#puq-svc-cron-count').text(rows.length + ' cron(s)');
                if (dt) { dt.destroy(); $('#puq-svc-cron-table tbody').empty(); }
                rows.forEach(function(c){
                    var cls = ({queued:'default',deploying:'info',active:'success',error:'danger',pending_delete:'warning',deleting:'warning'})[c.deploy_status] || 'default';
                    $('#puq-svc-cron-table tbody').append('<tr>' +
                        '<td>' + esc(c.id) + '</td>' +
                        '<td><code>' + esc(c.schedule) + '</code></td>' +
                        '<td><code style="font-size:11px;">' + esc(c.command) + '</code></td>' +
                        '<td><span class="label label-' + cls + '">' + esc(c.deploy_status) + '</span></td>' +
                        '<td>' + fmtDate(c.created_at) + '</td>' +
                        '<td><small class="text-danger">' + esc(c.deploy_error || '') + '</small></td>' +
                        '</tr>');
                });
                dt = $('#puq-svc-cron-table').DataTable({ order: [[0, 'desc']], pageLength: 25, autoWidth: false });
            }
        });
    }
    $('#puq-svc-cron-reload').on('click', load);
    load = ctx.armAutoRefresh('cron', { selector: '#puq-svc-cron-table', load: load });
    load();
};
</script>
{/literal}
