Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- $(document).on('click', '#employee_type_restore', function(event) {
- event.preventDefault();
- /* Act on the event */
- var id = $(this).data('id');
- // Select parent row
- const parent = event.target.closest('tr');
- // Get permission name
- const firstColName = parent.querySelectorAll('td')[1].innerText;
- // SweetAlert2 pop up --- official docs reference: https://sweetalert2.github.io/
- Swal.fire({
- // text: "Are you sure you want to Restore " + firstColName + "?",
- html: "Are you sure you want to Restore <strong>" + firstColName + " </strong>?", // Wrap firstColName in <strong> for bold text
- icon: "warning",
- showCancelButton: true,
- buttonsStyling: false,
- confirmButtonText: "Yes, Restore!",
- cancelButtonText: "No, cancel",
- customClass: {
- confirmButton: "btn fw-bold btn-success",
- cancelButton: "btn fw-bold btn-active-light-primary"
- }
- }).then(function (result) {
- if(result.value)
- {
- var formData = new FormData();
- let ajax_url = backend_url+'/employee-types/'+id+'/restore';
- let _method = 'POST';
- formData.append('_method', _method);
- $.ajax({
- url: ajax_url,
- type: 'POST',
- data: formData,
- cache: false,
- contentType: false,
- processData: false,
- dataType: 'json',
- headers: {
- 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
- },
- beforeSend: function() {
- // ✅ Show loading indicator
- Swal.fire({
- title: 'Restoring...',
- html: 'Please wait while we restore the record.',
- allowOutsideClick: false,
- allowEscapeKey: false,
- didOpen: () => {
- Swal.showLoading();
- }
- });
- },
- success: function (res)
- {
- if(res.status == true)
- {
- Swal.fire({
- // text: "You have Restored " + firstColName + "!.",
- html: "You have Restored <strong>" + firstColName + " </strong> !", // Wrap firstColName in <strong> for bold text
- icon: "success",
- buttonsStyling: false,
- showConfirmButton: false, // This removes the confirm button
- // confirmButtonText: "Ok, got it!",
- timer: 2000, // The alert will close automatically after 2 seconds
- timerProgressBar: true, // Optional: Show a progress bar while waitin
- customClass: {
- confirmButton: "btn fw-bold btn-primary",
- }
- });
- toastr.success(res.message); //Message
- window.LaravelDataTables["employee-types-table"].row($(parent)).remove().draw();
- }else{
- //Message
- toastr.error(res.message); //Message
- }
- },
- error: function(xhr) {
- // if error occured
- if (xhr.responseJSON && xhr.responseJSON.errors) {
- $.each(xhr.responseJSON.errors, function(key, value) {
- toastr.error(value);
- });
- } else if (xhr.responseJSON && xhr.responseJSON.message) {
- toastr.error(xhr.responseJSON.message);
- } else {
- toastr.error('An unexpected error occurred.');
- }
- },
- complete: function(xhr, status) {
- // var res = JSON.parse(xhr.responseText);
- // Remove Loader
- // ✅ Close loader no matter what
- Swal.close();
- },
- statusCode: {
- 404: function(xhr) {
- // Get Response ==> xhr.responseJSON
- // alert("page not found");
- },
- 403: function(xhr) {
- // alert("Forbidden");
- },
- 419: function(xhr) {
- // alert("CSRF Token Not Valid / Session Invalid");
- },
- 422: function(xhr) {
- // alert("Unprocessable Entity");
- },
- 500: function(xhr) {
- // alert("Internal Server Error");
- }
- }
- });
- }
- });
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment