public/js/env-employee.js
//Update Employee Upon Submitting Modal Form
Update Employee Upon Submitting Modal Form
Update Employee Upon Submitting Modal Form
function employeeUpdate() {
    $("#update-employee-form").on("submit", function (e) {
        e.preventDefault();
        var id = $("#id").val();
        $.ajax({
            type: "PUT",
            url: "/update-employee/" + id,
            data: $("#update-employee-form").serialize(),
            success: function (r) {
                console.log(r);
                const dataTable = $("#employeeTable").DataTable();
                dataTable
                    .row($("#" + id))
                    .remove()
                    .draw();
                dataTable.row
                    .add([
                        "<span class='text-black-50'>" + r["id"] + "</span>",
                        "<span class='text-black-50'>" +
                            r["last_name"] +
                            "</span>",
                        "<span class='text-black-50'>" +
                            r["first_name"] +
                            "</span>",
                        "<span class='text-black-50'>" +
                            r["position"] +
                            "</span>",
                        "<span class='text-black-50'>" +
                            r["gender"] +
                            "</span>",
                        "<img src='storage/" +
                            r["profile_picture"] +
                            "' class='modal-image' height='30' style='border-radius: 50%;' onError=this.onerror=null;this.src='images/defaultuser.png'>",
                        "<span class='text-black-50'>" +
                            r["contact_number"] +
                            "</span>",
                        "<span class='text-black-50'>" + r["email"] + "</span>",
                        r["active_status"] == "1"
                            ? `<div class="custom-control custom-switch"><input class="custom-control-input" type="checkbox" id="` +
                              r["id"] +
                              `" value="` +
                              r["active_status"] +
                              `"checked disabled><label class="custom-control-label" for="` +
                              r["id"] +
                              `"></label></div>`
                            : `<div class="custom-control custom-switch"><input class="custom-control-input toggle" type="checkbox" id="` +
                              r["id"] +
                              `" value="` +
                              r["active_status"] +
                              `"><label class="custom-control-label" for="` +
                              r["id"] +
                              `"></label></div>`,
                        '<a href="#" class="btn btn-success btn-sm rounded-0 editBtn" type="button"><i class="fa fa-edit"></i></a>',
                    ])
                    .node().id = id;
                dataTable.draw();
                successNotification("Employee SuccessFully Updated!");
                $("#update-employee-modal").modal("hide");
                $("#update-employee-form")[0].reset();
            },
            error: () =>
                dangerNotification("There was an error upon updating!"),
        });
    });
}
function employeeUpdate ( ) { $ ( "#update-employee-form" ) . on ( "submit" , function ( e ) { e . preventDefault ( ) ; var id = $ ( "#id" ) . val ( ) ; $ . ajax ( { type : "PUT" , url : "/update-employee/" + id , data : $ ( "#update-employee-form" ) . serialize ( ) , success : function ( r ) { console . log ( r ) ; const dataTable = $ ( "#employeeTable" ) . DataTable ( ) ; dataTable . row ( $ ( "#" + id ) ) . remove ( ) . draw ( ) ; dataTable . row . add ( [ "<span class='text-black-50'>" + r [ "id" ] + "</span>" , "<span class='text-black-50'>" + r [ "last_name" ] + "</span>" , "<span class='text-black-50'>" + r [ "first_name" ] + "</span>" , "<span class='text-black-50'>" + r [ "position" ] + "</span>" , "<span class='text-black-50'>" + r [ "gender" ] + "</span>" , "<img src='storage/" + r [ "profile_picture" ] + "' class='modal-image' height='30' style='border-radius: 50%;' onError=this.onerror=null;this.src='images/defaultuser.png'>" , "<span class='text-black-50'>" + r [ "contact_number" ] + "</span>" , "<span class='text-black-50'>" + r [ "email" ] + "</span>" , r [ "active_status" ] == "1" ? ` ` + r [ "id" ] + ` ` + r [ "active_status" ] + ` ` + r [ "id" ] + ` ` : ` ` + r [ "id" ] + ` ` + r [ "active_status" ] + ` ` + r [ "id" ] + ` ` , '<a href="#" class="btn btn-success btn-sm rounded-0 editBtn" type="button"><i class="fa fa-edit"></i></a>' , ] ) . node ( ) . id = id ; dataTable . draw ( ) ; successNotification ( "Employee SuccessFully Updated!" ) ; $ ( "#update-employee-modal" ) . modal ( "hide" ) ; $ ( "#update-employee-form" ) [ 0 ] . reset ( ) ; } , error : ( ) => dangerNotification ( "There was an error upon updating!" ) , } ) ; } ) ; }
Update Employee Upon Submitting Modal Form
Update Employee Upon Submitting Modal Form