diff --git a/app/Http/Controllers/Admin/RestaurantAppController.php b/app/Http/Controllers/Admin/RestaurantAppController.php index d6a3406..a9eeb86 100644 --- a/app/Http/Controllers/Admin/RestaurantAppController.php +++ b/app/Http/Controllers/Admin/RestaurantAppController.php @@ -142,12 +142,12 @@ class RestaurantAppController extends Controller DB::beginTransaction(); $status = IamPrincipal::find($request->rest_user_id); $status->is_active = $request->status; - + // Generate a random password if status is 1 (approved) if ($request->status == 1) { $randomPassword = \Str::random(8); // Adjust the length as per your requirements $status->password = bcrypt($randomPassword); // Make sure to hash the password - + // Send approval email $data = [ 'first_name' => $status->first_name, @@ -155,10 +155,10 @@ class RestaurantAppController extends Controller 'email' => $status->email_address, 'password' => $randomPassword, // Pass the random password to the email template ]; - + Mail::to($status->email_address)->send(new RestUserApproval($data)); } else { - + $status->deleted_by_admin = 1; $detail = [ 'first_name'=> $status->first_name, @@ -167,11 +167,11 @@ class RestaurantAppController extends Controller ]; Mail::to($status->email_address)->send(new RestUserDisapproval($detail)); } - + $status->save(); - + DB::commit(); - + return response()->json(['success' => true]); } catch (Exception $e) { DB::rollBack(); @@ -179,7 +179,7 @@ class RestaurantAppController extends Controller return response()->json(['success' => false, 'message' => __('auth.something_went_wrong')], 500); } } - + diff --git a/public/assets/js/admin/manage_restaurant/main.js b/public/assets/js/admin/manage_restaurant/main.js index b5682de..8999d9d 100644 --- a/public/assets/js/admin/manage_restaurant/main.js +++ b/public/assets/js/admin/manage_restaurant/main.js @@ -78,194 +78,197 @@ $(document).on("click", ".restaurant_unarchive", function (e) { }); }); -//old code for change status +$(document).on('click', "#delete_restaurant", function() { + var delete_restaurant_user_id = $(this).data('id'); + $("#news_delete").val(delete_restaurant_user_id); +}) - // $(".rest_users_table").on("change", ".active_rest_user", function () { - // let base_url = url_path; - // var status = $(this).prop("checked") == true ? 1 : 0; - // var rest_user_id = $(this).data("id"); +$(document).on('click', '#delete_restaurant_user', function(e) { + let base_url = url_path; + e.preventDefault(); + $.ajaxSetup({ + headers: { + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') + } + }); - // $.ajax({ - // type: "GET", - // dataType: "json", - // url: base_url + '/change_rest_status', - // data: { - // status: status, - // rest_user_id: rest_user_id, - // }, - // success: function (data) { - // if (status == 1) { - // toastr.options = { - // "timeOut": 500 - // } - // toastr.success("Status Activate successfully. !!"); - // } else { - // toastr.error("Status Deactivate successfully. !!"); - // } - // }, - // }); - // }); + var id = $('#news_delete').val(); + console.log('id' , id); + $('#delete_restaurant_user').text('Please wait...'); + $('#delete_restaurant_user').attr('disabled', true); - // $(document).ready(function () { - // // Handle approve button click - // $(".approve-btn").on("click", function () { - // let base_url = url_path; - // var rest_user_id = $(this).data("id"); - // var status = 1; - - // $.ajax({ - // type: "GET", - // dataType: "json", - // url: base_url + '/change_rest_status', - // data: { - // status: status, - // rest_user_id: rest_user_id, - // }, - // success: function (data) { - // toastr.options = { - // "timeOut": 500 - // } - // toastr.success("User approved and status activated successfully. !!"); - - // // Update the switch to active - // $('#switch' + rest_user_id).prop('checked', true); - // }, - // }); - // }); - - // // Handle disapprove button click - // $(".disapprove-btn").on("click", function () { - // let base_url = url_path; - // var rest_user_id = $(this).data("id"); - // var status = 0; - - // $.ajax({ - // type: "GET", - // dataType: "json", - // url: base_url + '/change_rest_status', - // data: { - // status: status, - // rest_user_id: rest_user_id, - // }, - // success: function (data) { - // toastr.error("User disapproved and status deactivated successfully. !!"); - - // // Update the switch to inactive - // $('#switch' + rest_user_id).prop('checked', false); - // }, - // }); - // }); + $.ajax({ + type: 'POST', + url: base_url + '/delete_restaurant_user/' + id, + success: function(result) { + if (result.status == 200) { + toastr.success('Restaurant Deleted Sucessfully'); + setTimeout(function() { + window.location.href = base_url + "/restaurant_users"; + }, 2000); + } else { + toastr.error('Something Went Wrong'); + setTimeout(function() { + window.location.href = base_url + "/restaurant_users"; + }, 2000); + } + } + }); +}); - // $(".rest_users_table").on("change", ".active_rest_user", function () { - // // Revert the switch change - // var rest_user_id = $(this).data("id"); - // var currentStatus = $(this).prop("checked"); - // // Revert the switch state - // $(this).prop("checked", !currentStatus); +$(document).ready(function() { + let actionType = ''; + let restUserId = ''; + let switchElement = null; + let actionButton = null; - // toastr.options = { - // "timeOut": 6000 - // } - // toastr.error("You can only change the status using Approve/Disapprove buttons."); - // }); + $(".approve-btn, .disapprove-btn").on("click", function(e) { + e.preventDefault(); - // }); - - // $(document).ready(function() { - // // console.log('dfkjb'); - // $('#rest_user_form').validate({ - // ignore: [], - // debug: false, - // rules: { - // first_name: { - // required: true, - // fullNameCharactersOnly: true - // }, - // last_name:{ - // required: true, - // }, - // user_birth:{ - // required: true, - // }, + actionType = $(this).hasClass('approve-btn') ? 'approve' : 'disapprove'; + restUserId = $(this).data("id"); + switchElement = $('#switch' + restUserId); + actionButton = $(this); - // restaurant_email: { - // required: true, - // email: true, - // }, + // Check current status for approve + if (actionType === 'approve' && switchElement.prop('checked')) { + toastr.options = { "timeOut": 100 }; + toastr.warning("User is already approved. !!"); + return; + } - // restaurant_phone: { - // required: true, - // numericCharactersOnly: true - // }, + // Check current status for disapprove + if (actionType === 'disapprove' && $(this).data("deleted_by_admin") == 1) { + toastr.options = { "timeOut": 500 }; + toastr.warning("User is already disapproved. !!"); + return; + } - // }, - // messages: { - // first_name: { - // required: "Please enter first name", - // alphaCharactersOnly: "Please enter only alphabetical characters" - // }, - // last_name:{ - // required: "Please enter last name", - // }, - // user_birth:{ - // required: "Please enter date of birth", - // }, + $('#action-type').text(actionType); + $('#action-word').text(actionType); + $('#confirm-btn').attr('data-action', actionType); + $('#confirm-btn').attr('data-id', restUserId); + $('#confirm-modal').modal('show'); + }); - // restaurant_email: { - // required: "Enter email address", - // email: "Please enter a valid email address" - // }, + $('#confirm-btn').on('click', function() { + let base_url = url_path; + let actionType = $(this).attr('data-action'); + let restUserId = $(this).attr('data-id'); - // restaurant_phone: { - // required: "Enter Phone Number", - // numericCharactersOnly: "Please enter only numeric characters" - // }, + $(this).text('Please wait...').attr('disabled', true); - // }, - // errorClass: 'error-message', - // submitHandler: function(form) { - // let base_url = url_path; - // var formData = new FormData(form); - // // console.log(formData); - // $('#restaturant_btn').text('Please wait...'); - // $('#restaturant_btn').attr('disabled', true); + $.ajax({ + type: "POST", + dataType: "json", + url: base_url + '/change_rest_status', + data: { + status: actionType === 'approve' ? 1 : 0, + rest_user_id: restUserId, + _token: $('meta[name="csrf-token"]').attr('content') + }, + success: function(data) { + toastr.options = { "timeOut": 500 }; + if (actionType === 'approve') { + toastr.success("User approved and status activated successfully. !!"); + switchElement.prop('checked', true); + } else { + toastr.error("User disapproved and status deactivated successfully. !!"); + switchElement.prop('checked', false); + } + setTimeout(function() { + window.location.href = base_url + "/restaurant_users"; + }, 2000); + }, + error: function() { + toastr.error("There was an error processing the request. Please try again."); + $('#confirm-btn').text('Yes, ' + actionType).attr('disabled', false); + } + }); - // $.ajaxSetup({ - // headers: { - // 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') - // } - // }); - // $.ajax({ - // url: base_url + '/update_restaurant', - // type: 'POST', - // data: formData, - // processData: false, - // contentType: false, - // success: function(result) { - // if (result.status_code == 200) { - // toastr.success('Restaurant Updated Sucessfully'); - // setTimeout(function() { - // window.location.href = base_url + "/restaurant_users"; - // }, 2000); - // } else { - // toastr.error('Something Went Wrong'); - // setTimeout(function() { - // window.location.href = base_url + "/restaurant_users"; - // }, 2000); - // } - // $('#restaturant_btn').attr('disabled', false); - // $('#restaturant_btn').text('Submit'); - // }, - // error: function() { - // toastr.error('Something Went Wrong'); - // $('#restaturant_btn').attr('disabled', false); - // $('#restaturant_btn').text('Submit'); - // } - // }); - // } - // }); - // }) + $('#confirm-modal').modal('hide'); + }); +}); + + + // Handle switch change + $(".rest_users_table").on("change", ".active_rest_user", function() { + // Revert the switch change + var currentStatus = $(this).prop("checked"); + + // Revert the switch state + $(this).prop("checked", !currentStatus); + + + toastr.options = { + "timeOut": 500 + } + toastr.error("You can only change the status using Approve/Disapprove buttons."); + }); + + + $(function(e) { + // Select/Deselect all checkboxes + $("#select-all-ids").click(function() { + $(".form-check-input").prop('checked', $(this).prop('checked')); + }); + + $(".form-check-input").click(function() { + if (!$(this).prop('checked')) { + $("#select-all-ids").prop('checked', false); + } else { + if ($(".form-check-input:checked").length === $(".form-check-input").length) { + $("#select-all-ids").prop('checked', true); + } + } + }); + + // Handle download selected action + $(document).on("click", "#download-selected", function(e) { + e.preventDefault(); + + var selectedIds = []; + + var table = $('#zero-config').DataTable(); + for (var i = 0; i < table.page.info().pages; i++) { + table.page(i).draw(false); // Switch to page i without resetting the table + $('#zero-config tbody input.form-check-input:checked').each(function() { + selectedIds.push($(this).val()); + }); + } + + if (selectedIds.length > 0) { + // If there are selected customers + $('#selected_ids').prop('disabled', false); + $('#all_id').prop('disabled', true); + $('#selected_ids').val(selectedIds.join(',')); // Join all IDs into a single string + + // Log the selected IDs for debugging + // console.log(selectedIds); + + $('#restaurant-form').submit(); + + setTimeout(function() { + location.reload(); + }, 5000); // Adjust the timeout as needed + } else { + toastr.error("Please select at least one restaurant to download."); + } + }); + + // Handle download all action + $(document).on("click", "#download_all", function(e) { + e.preventDefault(); + $('#all_id').prop('disabled', false); + $('#selected_ids').prop('disabled', true); + $('#restaurant-form').submit(); + + setTimeout(function() { + location.reload(); + }, 5000); // Adjust the timeout as needed + }); + }); diff --git a/resources/views/Admin/pages/manage_users/restaurants_app/restaurants_users.blade.php b/resources/views/Admin/pages/manage_users/restaurants_app/restaurants_users.blade.php index 288c47e..0e212f1 100644 --- a/resources/views/Admin/pages/manage_users/restaurants_app/restaurants_users.blade.php +++ b/resources/views/Admin/pages/manage_users/restaurants_app/restaurants_users.blade.php @@ -276,7 +276,7 @@ Edit - @@ -335,43 +335,7 @@ - - - - +