<%+tasks/embed%>

<script>
window.addEventListener("load", function(){
    const taskd = window.taskd;
    const logfunc = function(e) {
        taskd.show_log(this);
        return false;
    };
    const delfunc = function(e) {
        taskd.remove(this).then(()=>{
            location.reload();
        });
        return false;
    };
    const rows = document.querySelectorAll('#cbi-tasks-table tr.cbi-section-table-row');
    rows.forEach(row => {
        if (row.id) {
            const task_id = row.id.match(/cbi-tasks-(.*)/)[1];
            row.querySelector('td[data-name=_log] .cbi-button').onclick = logfunc.bind(task_id);
            row.querySelector('td[data-name=_remove] .cbi-button').onclick = delfunc.bind(task_id);
        }
    });
<% if self.show_log_taskid then -%>
    taskd.show_log("<%=self.show_log_taskid%>");
<%- end %>
});
</script>
