HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: /var/www/admin.javaapp.co.uk/public/assets/js/tableAction.js
$(document).on("click", ".change-status", function () {
    const changeStatusUrl = $(this).data("href");
    const attr = $(this).prev("input");
    const status = attr.attr("checked") == "checked" ? 1 : 0;
    const tableElement = '#'+$(this).parents('table').attr('id');
    const showStatus = $(this).data('status');
    $.ajax({
        type: "POST",
        url: changeStatusUrl,
        data: {
            status: status,
        },
        dataType: "json",
        success: function (response) {
            if (response.status == 200) {
                if (status == 1) {
                    attr.removeAttr("checked");
                } else {
                    attr.attr("checked", "checked");
                }
                if(showStatus == "1"){
                    if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                        $(tableElement).DataTable().ajax.reload();
                    }
                }
                $.growl.notice({
                    title: "success",
                    message: response.message,
                });
            } else {
                if (status == 1) {
                    attr.attr("checked", "checked");
                } else {
                    attr.removeAttr("checked");
                }
                if(showStatus == "1"){
                    if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                        $(tableElement).DataTable().ajax.reload();
                    }
                }
                $.growl.error({
                    title: "error",
                    message: response.message,
                });
            }
        },
        error: function (error) {
            if (status == 1) {
                attr.attr("checked", "checked");
            } else {
                attr.removeAttr("checked");
            }
            if(showStatus == "1"){
                if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                    $(tableElement).DataTable().ajax.reload();
                }
            }
            $.growl.error({
                title: "error",
                message: somethingWentWrong,
            });
        },
    });
});

$(document).on("click", ".approve-btn", function () {
    const url = $(this).data("href");
    Swal.fire({
        title: areYouSure,
        text: wontRevert,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "var(--coffee-dark)",
        cancelButtonColor: "var(--coffee-light)",
        confirmButtonText: yesApprove,
    }).then(function (result) {
        if (result.value) {
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    _method: "PUT",
                },
                dataType: "json",
                beforeSend: function () {
                    swal.fire({
                        title: pleaseWait,
                        text: isWorking,
                        onOpen: function () {
                            swal.showLoading();
                        },
                    });
                },
                success: function (response) {
                    if (response.status == 500) {
                        swal.hideLoading();
                        swal.fire(oops, response.message, "error");
                    } else {
                        if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                            $(tableElement).DataTable().ajax.reload();
                        }
                        Swal.fire(approvedSuccess, response.message, "success");
                    }
                },
                complete: function () {
                    $(tableElement).DataTable().ajax.reload();
                    swal.hideLoading();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    swal.hideLoading();
                    swal.fire(oops, somethingWentWrong, "error");
                },
            });
        }
    });
});

$(document).on("click", ".delete-btn", function () {
    const url = $(this).data("href");
    Swal.fire({
        title: areYouSure,
        text: wontRevert,
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "var(--coffee-dark)",
        cancelButtonColor: "var(--coffee-light)",
        confirmButtonText: yesDelete,
    }).then(function (result) {
        if (result.value) {
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    _method: "DELETE",
                },
                dataType: "json",
                beforeSend: function () {
                    swal.fire({
                        title: pleaseWait,
                        text: isWorking,
                        onOpen: function () {
                            swal.showLoading();
                        },
                    });
                },
                success: function (response) {
                    if (response.status == 500) {
                        swal.hideLoading();
                        swal.fire(oops, response.message, "error");
                    } else {
                        if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                            $(tableElement).DataTable().ajax.reload();
                        }
                        Swal.fire(deleted, response.message, "success");
                    }
                },
                complete: function () {
                    $(tableElement).DataTable().ajax.reload();
                    swal.hideLoading();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    swal.hideLoading();
                    swal.fire(oops, somethingWentWrong, "error");
                },
            });
        }
    });
});

$(document).on("click", ".change-admin-approval", function () {
    const changeStatusUrl = $(this).data("href");
    const attr = $(this).prev("input");
    const status = attr.attr("checked") == "checked" ? 1 : 0;
    const tableElement = '#'+$(this).parents('table').attr('id');
    const showStatus = $(this).data('status');
    $.ajax({
        type: "POST",
        url: changeStatusUrl,
        data: {
            is_admin_approved: attr.is(':checked') ? 1 : 0,
        },
        dataType: "json",
        success: function (response) {
            if (response.status == 200) {
                if (status == 1) {
                    attr.removeAttr("checked");
                } else {
                    attr.attr("checked", "checked");
                }
                if(showStatus == "1"){
                    if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                        $(tableElement).DataTable().ajax.reload();
                    }
                }
                $.growl.notice({
                    title: "success",
                    message: response.message,
                });
            } else {
                if (status == 1) {
                    attr.attr("checked", "checked");
                } else {
                    attr.removeAttr("checked");
                }
                if(showStatus == "1"){
                    if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                        $(tableElement).DataTable().ajax.reload();
                    }
                }
                $.growl.error({
                    title: "error",
                    message: response.message,
                });
            }
        },
        error: function (error) {
            if (status == 1) {
                attr.attr("checked", "checked");
            } else {
                attr.removeAttr("checked");
            }
            if(showStatus == "1"){
                if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                    $(tableElement).DataTable().ajax.reload();
                }
            }
            $.growl.error({
                title: "error",
                message: somethingWentWrong,
            });
        },
    });
});
$(document).on("click", ".change-order-completed", function () {
    const changeStatusUrl = 'order-history/change-order-completed';
    const attr = $(this).prev("input");
    const status = attr.is(":checked") ? 0 : 1; // Toggle status
    const tableElement = '#' + $(this).closest('table').attr('id');
    const id = $(this).data('id');

    // Disable the checkbox while processing
    attr.prop("disabled", true);

    $.ajax({
        type: "POST",
        url: changeStatusUrl,
        data: {
            id: id,
            status: status,
        },
        success: function (response) {
            if (response.success) {
                // Update checkbox and message based on the new status
                if (status === 1) {
                    attr.prop("checked", true); // Check the box
                    attr.closest('label').hide(); // Hide the checkbox
                    attr.closest('label').siblings('.completed-message').show(); // Show completed message
                } else {
                    attr.prop("checked", false); // Uncheck the box
                    attr.closest('label').show(); // Show the checkbox
                    attr.closest('label').siblings('.completed-message').hide(); // Hide completed message
                }
                
                if ($.fn.DataTable.fnIsDataTable(tableElement)) {
                    $(tableElement).DataTable().ajax.reload();
                }
                $.growl.notice({
                    title: "Success",
                    message: response.message,
                });
            } else {
                attr.prop("checked", !status); // Revert checkbox state on failure
                $.growl.error({
                    title: "Error",
                    message: "Failed to update order status.",
                });
            }
        },
        error: function (error) {
            attr.prop("checked", !status); // Revert checkbox state on error
            $.growl.error({
                title: "Error",
                message: "Something went wrong.",
            });
        },
        complete: function () {
            attr.prop("disabled", false); // Re-enable the checkbox
        }
    });
});