<script type="text/javascript">

    {% if job.status != "COMPLETED" %}
    $("#update_job_status_btn").on("click", function() {
        var job_id = $(this).data("job_id");

        Swal.fire({
            title: "Are you sure?",
            text: "Job status will be updated to {{ nextJobPhase }}",
            icon: "warning",
            showCancelButton: true,
            confirmButtonColor: "#3085d6",
            cancelButtonColor: "#d33",
            confirmButtonText: "Update"
        }).then((result) => {
            if (result.isConfirmed) {

                $.ajax({
                    type: 'POST',
                    url: '{{ path('api_jobs_update_status') }}',
                    datatype: 'json',
                    data: {
                        id : {{ job.id }}
                    }
                })
                    .done(function (data) {
                        Swal.fire({
                            title: "Updated!",
                            text: "Job Status updated successfully!.",
                            icon: "success"
                        });
                        setTimeout(function(){ location.reload(); }, 1500);
                    })
                    .fail(function (jqXHR, textStatus, errorThrown) {
                        toastr.options.progressBar = true;
                        toastr.error('Failed to Update Job Status!', 'Error!');
                    });
            }
        });

    });
    {% endif %}

</script>
