This commit is contained in:
sayliraut
2024-07-24 13:37:06 +05:30
3 changed files with 423 additions and 250 deletions

View File

@@ -85,58 +85,101 @@ class RestaurantAppController extends Controller
* Created at : 03 June 2024
* Use : To change the status restaturant user.
*/
// public function change_rest_user_status(Request $request)
// {
// try {
// 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
// } else {
// $status->deleted_by_admin = 1;
// $detail = [
// 'first_name' => $status->first_name,
// 'last_name' => $status->last_name,
// 'email' => $status->email_address,
// ];
// Mail::to($status->email_address)->send(new RestUserDisapproval($detail));
// }
// $status->save();
// if ($request->status == 1) {
// // Fetch user data based on user ID
// $user = IamPrincipal::find($request->rest_user_id);
// if ($user) {
// // Send email only if user exists
// $data = [
// 'first_name' => $user->first_name,
// 'last_name' => $user->last_name,
// 'email' => $user->email_address,
// 'password' => $randomPassword, // Pass the random password to the email template
// ];
// Mail::to($user->email_address)->send(new RestUserApproval($data));
// }
// }
// DB::commit();
// return jsonResponseWithSuccessMessage(__('success.update_data'));
// } catch (Exception $e) {
// Log::error("Update Status function Load Failed " . $e->getMessage());
// return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
// }
// }
public function change_rest_user_status(Request $request)
{
try {
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
} else {
$status->deleted_by_admin = 1;
$detail = [
// Send approval email
$data = [
'first_name' => $status->first_name,
'last_name' => $status->last_name,
'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,
'last_name' => $status->last_name,
'email'=> $status->email_address,
];
Mail::to($status->email_address)->send(new RestUserDisapproval($detail));
}
$status->save();
if ($request->status == 1) {
// Fetch user data based on user ID
$user = IamPrincipal::find($request->rest_user_id);
if ($user) {
// Send email only if user exists
$data = [
'first_name' => $user->first_name,
'last_name' => $user->last_name,
'email' => $user->email_address,
'password' => $randomPassword, // Pass the random password to the email template
];
Mail::to($user->email_address)->send(new RestUserApproval($data));
}
}
DB::commit();
return jsonResponseWithSuccessMessage(__('success.update_data'));
return response()->json(['success' => true]);
} catch (Exception $e) {
DB::rollBack();
Log::error("Update Status function Load Failed " . $e->getMessage());
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
return response()->json(['success' => false, 'message' => __('auth.something_went_wrong')], 500);
}
}

View File

@@ -85,6 +85,25 @@
font-size: 14px;
/* Adjust font size as needed */
}
.modal-body {
text-align: center;
}
.modal-btn {
gap: 10px; /* Optional: Adds space between the buttons */
}
.modal-text {
text-align: center;
margin-bottom: 1.5rem; /* Adjust margin as needed */
}
.extra-btn {
margin-right: 10px; /* Adjust margin as needed */
}
</style>
<div class="layout-px-spacing">
@@ -315,53 +334,72 @@
</div>
</div>
</div>
<!-- Confirmation Modal -->
<!-- <div class="modal fade" id="confirm-modal" tabindex="-1" aria-labelledby="confirmModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirmModalLabel">Confirmation</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to <span id="action-type"></span> this user?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No</button>
<button type="button" class="btn btn-primary" id="confirm-btn">Yes</button>
</div>
</div>
</div>
</div> -->
<!-- Confirmation Modal -->
<!-- <div class="modal fade" id="confirm-modal" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="modal-header">
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close">x</button>
</div>
<input type="hidden" id="user_id" name="user_id">
<h5>
<p class="modal-text">Are you sure you want to<br><span id="action-type"></span> this user?</p></h5>
<div class="modal-btn d-flex">
<a class="extra-btn pointer" data-dismiss="modal">No</a>
<a class="download-btn-custom" id="confirm-btn" href="#">Yes, <span id="action-word"></span></a>
</div>
</div>
</div>
</div>
</div> -->
<div class="modal fade" id="confirm-modal" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="modal-header">
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close">x</button>
</div>
<input type="hidden" id="user_id" name="user_id">
<h5>
<p class="modal-text">Are you sure you want to<br><span id="action-type"></span> this user?</p>
</h5>
<div class="modal-btn d-flex justify-content-center">
<a class="extra-btn pointer" data-dismiss="modal">No</a>
<a class="download-btn-custom" id="confirm-btn" href="#">Yes, <span id="action-word"></span></a>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('section_script')
<script src="{{ asset('public/assets/js/admin/manage_restaurant/main.js') }}"></script>
<script>
// $(document).ready(function() {
// var filterButton = $('<div class="filter-btn-wrapper">' +
// '<ul class="navbar-item flex-row ms-lg-auto ms-0">' +
// '<li class="nav-item dropdown action-dropdown order-lg-0 order-1">' +
// '<a href="javascript:void(0);" class="nav-link dropdown-toggle user extra-btn" id="actionDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' +
// '<div class="avatar-container"><div class="avatar avatar-sm avatar-indicators avatar-online"><h3>Filter</h3></div></div>' +
// '</a>' +
// '<div class="dropdown-menu position-absolute" aria-labelledby="actionDropdown">' +
// '<div class="dropdown-item"><a href="{{ route('restraunt_users') }}" id="allFilter" class="default-filter"><span>All</span></a></div>' +
// '<div class="dropdown-item"><a href="{{ route('restraunt_users', ['active' => true]) }}" id="activeFilter"><span>Active</span></a></div>' +
// '<div class="dropdown-item"><a href="{{ route('restraunt_users', ['active' => false]) }}" id="expiredFilter"><span>Inactive</span></a></div>' +
// '</div>' +
// '</li>' +
// '</ul>' +
// '</div>');
// filterButton.insertBefore("#zero-config_filter");
// var selectedFilter = localStorage.getItem('selectedFilter');
// if (selectedFilter) {
// handleChange(selectedFilter);
// } else {
// $('#allFilter').trigger('click');
// }
// $('#activeFilter').on('click', function() {
// handleChange('active');
// localStorage.setItem('selectedFilter', 'active');
// });
// $('#expiredFilter').on('click', function() {
// handleChange('expired');
// localStorage.setItem('selectedFilter', 'expired');
// });
// $('#allFilter').on('click', function() {
// handleChange('all');
// localStorage.setItem('selectedFilter', 'all');
// });
// });
$(document).ready(function() {
// Create the filter button
@@ -492,191 +530,283 @@
</script>
<!-- <script>
//old code start
$(document).ready(function() {
// Handle approve button click
$(".approve-btn").on("click", function() {
// alert('sdjdh');
let base_url = url_path;
var rest_user_id = $(this).data("id");
// console.log(rest_user_id);
// return;
var switchElement = $('#switch' + rest_user_id);
// Check current status
if (switchElement.prop('checked')) {
toastr.options = {
"timeOut": 500
}
toastr.warning("User is already approved. !!");
return;
}
$.ajax({
type: "GET",
dataType: "json",
url: base_url + '/change_rest_status',
data: {
status: 1,
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
switchElement.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 switchElement = $('#switch' + rest_user_id);
// Check current status
if (!switchElement.prop('checked')) {
toastr.options = {
"timeOut": 500
}
toastr.warning("User is already disapproved. !!");
return;
}
$.ajax({
type: "GET",
dataType: "json",
url: base_url + '/change_rest_status',
data: {
status: 0,
rest_user_id: rest_user_id,
},
success: function(data) {
toastr.error(
"User disapproved and status deactivated successfully. !!");
// Update the switch to inactive
switchElement.prop('checked', false);
},
});
});
// 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.");
});
});
//old code is empty
</script> -->
<script>
$(document).ready(function() {
// Handle approve button click
$(".approve-btn").on("click", function(e) {
e.preventDefault(); // Prevent form submission
let base_url = url_path;
var rest_user_id = $(this).data("id");
var switchElement = $('#switch' + rest_user_id);
// Check current status
if (switchElement.prop('checked')) {
toastr.options = {
"timeOut": 500
}
toastr.warning("User is already approved. !!");
return;
// old code Handle approve button click
// $(".approve-btn").on("click", function(e) {
// e.preventDefault(); // Prevent form submission
// let base_url = url_path;
// var rest_user_id = $(this).data("id");
// var switchElement = $('#switch' + rest_user_id);
// // Check current status
// if (switchElement.prop('checked')) {
// toastr.options = {
// "timeOut": 100
// }
// toastr.warning("User is already approved. !!");
// return;
// }
// $('#approve-btn').text('Please wait...');
// $('#approve-btn').attr('disabled', true);
// $.ajax({
// type: "GET",
// dataType: "json",
// url: base_url + '/change_rest_status',
// data: {
// status: 1,
// rest_user_id: rest_user_id,
// },
// success: function(data) {
// toastr.options = {
// "timeOut": 500
// }
// toastr.success("User approved and status activated successfully. !!");
// setTimeout(function() {
// window.location.href = base_url + "/restaurant_users";
// }, 2000); // Update the switch to active
// switchElement.prop('checked', true);
// },
// });
// });
// below is updated code of disapprove button start
// $(".approve-btn").on("click", function(e) {
// e.preventDefault(); // Prevent form submission
// let base_url = url_path;
// var rest_user_id = $(this).data("id");
// var switchElement = $('#switch' + rest_user_id);
// var approveButton = $(this); // Target the clicked button
// // Check current status
// if (switchElement.prop('checked')) {
// toastr.options = {
// "timeOut": 100
// }
// toastr.warning("User is already approved. !!");
// return;
// }
// approveButton.text('Please wait...');
// approveButton.attr('disabled', true);
// $.ajax({
// type: "GET",
// dataType: "json",
// url: base_url + '/change_rest_status',
// data: {
// status: 1,
// rest_user_id: rest_user_id,
// },
// success: function(data) {
// toastr.options = {
// "timeOut": 500
// }
// toastr.success("User approved and status activated successfully. !!");
// setTimeout(function() {
// window.location.href = base_url + "/restaurant_users";
// }, 2000); // Update the switch to active
// switchElement.prop('checked', true);
// },
// error: function() {
// // Re-enable the button in case of an error
// approveButton.text('Approve');
// approveButton.attr('disabled', false);
// }
// });
// });
// below is updated code of disapprove button start
// old code Handle disapprove button click
// $(document).ready(function() {
// $(".disapprove-btn").on("click", function(e) {
// e.preventDefault(); // Prevent form submission
// let base_url = url_path;
// var rest_user_id = $(this).data("id");
// var deleted_by_admin = $(this).data(
// "deleted_by_admin"); // Fetch the deleted_by_admin value
// var switchElement = $('#switch' + rest_user_id);
// // console.log(
// // deleted_by_admin); // Log the value to check if it is correctly fetched
// // Check current status
// if (deleted_by_admin == 1) {
// toastr.options = {
// "timeOut": 500
// }
// toastr.warning("User is already disapproved. !!");
// return;
// }
// $('#disapprove-btn').text('Please wait...');
// $('#disapprove-btn').attr('disabled', true);
// $.ajax({
// type: "GET",
// dataType: "json",
// url: base_url + '/change_rest_status',
// data: {
// status: 0,
// rest_user_id: rest_user_id,
// },
// success: function(data) {
// toastr.error(
// "User disapproved and status deactivated successfully. !!"
// );
// setTimeout(function() {
// window.location.href = base_url +
// "/restaurant_users";
// }, 2000);
// // Update the switch to inactive
// switchElement.prop('checked', false);
// },
// error: function(error) {
// toastr.error(
// "There was an error processing the request. Please try again."
// );
// }
// });
// });
// });
// below is updated code of disapprove button start
// $(document).ready(function() {
// $(".disapprove-btn").on("click", function(e) {
// e.preventDefault(); // Prevent form submission
// let base_url = url_path;
// var rest_user_id = $(this).data("id");
// var deleted_by_admin = $(this).data("deleted_by_admin"); // Fetch the deleted_by_admin value
// var switchElement = $('#switch' + rest_user_id);
// var disapproveButton = $(this); // Target the clicked button
// // Check current status
// if (deleted_by_admin == 1) {
// toastr.options = {
// "timeOut": 500
// }
// toastr.warning("User is already disapproved. !!");
// return;
// }
// disapproveButton.text('Please wait...');
// disapproveButton.attr('disabled', true);
// $.ajax({
// type: "GET",
// dataType: "json",
// url: base_url + '/change_rest_status',
// data: {
// status: 0,
// rest_user_id: rest_user_id,
// },
// success: function(data) {
// toastr.error("User disapproved and status deactivated successfully. !!");
// setTimeout(function() {
// window.location.href = base_url + "/restaurant_users";
// }, 2000);
// // Update the switch to inactive
// switchElement.prop('checked', false);
// },
// error: function(error) {
// toastr.error("There was an error processing the request. Please try again.");
// // Re-enable the button in case of an error
// disapproveButton.text('Disapprove');
// disapproveButton.attr('disabled', false);
// }
// });
// });
// });
// above is updated code of disapprove button end
$(document).ready(function() {
let actionType = '';
let restUserId = '';
let switchElement = null;
let actionButton = null;
$(".approve-btn, .disapprove-btn").on("click", function(e) {
e.preventDefault();
actionType = $(this).hasClass('approve-btn') ? 'approve' : 'disapprove';
restUserId = $(this).data("id");
switchElement = $('#switch' + restUserId);
actionButton = $(this);
// Check current status for approve
if (actionType === 'approve' && switchElement.prop('checked')) {
toastr.options = { "timeOut": 100 };
toastr.warning("User is already approved. !!");
return;
}
// 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;
}
$('#action-type').text(actionType);
$('#action-word').text(actionType);
$('#confirm-btn').attr('data-action', actionType);
$('#confirm-btn').attr('data-id', restUserId);
$('#confirm-modal').modal('show');
});
$('#confirm-btn').on('click', function() {
let base_url = url_path;
let actionType = $(this).attr('data-action');
let restUserId = $(this).attr('data-id');
$(this).text('Please wait...').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);
}
});
$('#approve-btn').text('Please wait...');
$('#approve-btn').attr('disabled', true);
$('#confirm-modal').modal('hide');
});
});
$.ajax({
type: "GET",
dataType: "json",
url: base_url + '/change_rest_status',
data: {
status: 1,
rest_user_id: rest_user_id,
},
success: function(data) {
toastr.options = {
"timeOut": 500
}
toastr.success("User approved and status activated successfully. !!");
setTimeout(function() {
window.location.href = base_url + "/restaurant_users";
}, 2000); // Update the switch to active
switchElement.prop('checked', true);
},
});
});
// Handle disapprove button click
$(document).ready(function() {
$(".disapprove-btn").on("click", function(e) {
e.preventDefault(); // Prevent form submission
let base_url = url_path;
var rest_user_id = $(this).data("id");
var deleted_by_admin = $(this).data(
"deleted_by_admin"); // Fetch the deleted_by_admin value
var switchElement = $('#switch' + rest_user_id);
console.log(
deleted_by_admin); // Log the value to check if it is correctly fetched
// Check current status
if (deleted_by_admin == 1) {
toastr.options = {
"timeOut": 500
}
toastr.warning("User is already disapproved. !!");
return;
}
$('#disapprove-btn').text('Please wait...');
$('#disapprove-btn').attr('disabled', true);
$.ajax({
type: "GET",
dataType: "json",
url: base_url + '/change_rest_status',
data: {
status: 0,
rest_user_id: rest_user_id,
},
success: function(data) {
toastr.error(
"User disapproved and status deactivated successfully. !!"
);
setTimeout(function() {
window.location.href = base_url +
"/restaurant_users";
}, 2000);
// Update the switch to inactive
switchElement.prop('checked', false);
},
error: function(error) {
toastr.error(
"There was an error processing the request. Please try again."
);
}
});
});
});

View File

@@ -89,7 +89,7 @@ Route::group(['middleware' => ['checkStatus']], function () {
// Route::get('/manage-restaurants_app', [RestaurantAppController ::class, 'index'])->name('manage.restaurants_app');
// Route::get('/restraunt_users', [RestaurantAppController::class, 'index_restraunt_users'])->name('restraunt_users');
Route::get('/restaurant_users', [RestaurantAppController::class, 'index_restraunt_users'])->name('restraunt_users');
Route::get('/change_rest_status', [RestaurantAppController::class, 'change_rest_user_status']);
Route::post('/change_rest_status', [RestaurantAppController::class, 'change_rest_user_status']);
Route::get('/view_restaurant_users/{id}', [RestaurantAppController::class, 'view_rest'])->name('restaurantViewUsers');
Route::get('/edit_restaurant_users/{id}', [RestaurantAppController::class, 'edit_Restaurant'])->name('EditRestUsers');