Viewing file: index.blade.php (28.59 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
@extends('layouts.master')
@section('title') Agents @endsection
@section('content')
@component('components.breadcrumb')
@slot('li_1') Agents @endslot
@slot('title')Agents List @endslot
@endcomponent
<div class="row">
<div class="col-lg-12">
<div class="card">
@if ($errors->any())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
<span class="each-error">{{ $error }} </span><br/>
@endforeach
</div>
@endif
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
@endif
<div class="card-header border-0">
<div class="d-flex align-items-center">
<h5 class="card-title mb-0 flex-grow-1">Agents List</h5>
<div class="flex-shrink-0">
<button type="button" class="btn btn-success add-btn" data-bs-toggle="modal"
id="create-btn" data-bs-target="#addModal"><i
class="ri-add-line align-bottom me-1"></i> Create New
</button>
</div>
</div>
</div>
<div class="card-body">
<div class="">
<table id="alternative-pagination" class="table nowrap dt-responsive align-middle table-hover table-bordered" style="width:100%">
<thead>
<tr>
<th>Agent ID</th>
<th>Name</th>
<th>Phone Number</th>
<th>Email</th>
<th>Services</th>
<th>Reviewed</th>
<th>Rating</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@php
$i=1;
@endphp
@if(isset($users))
@foreach($users as $user)
<tr>
<td><a href="{{ route('rating.details',['user_id'=>$user->id]) }}" class="fw-medium link-primary">
{{ $user->agent_id}}
</a>
</td>
<td>
<a href="{{ route('rating.details',['user_id'=>$user->id]) }}" class="fw-medium link-primary">
{{ $user->name}}
</a>
</td>
<td>{{ $user->phone_no }}</td>
<td>{{ $user->email }}</td>
@php
$found = false;
@endphp
@foreach($ratings_summary as $rating)
@if($rating->user_id == $user->id)
<td>{{ $rating->total_rows }}</td>
<td>{{ $rating->rated_rows }}</td>
<td>{{ $rating->average_rating }}</td>
@php $found = true; @endphp
@break
@endif
@endforeach
@if(!$found)
<td>N/A</td>
<td>N/A</td>
<td>N/A</td>
@endif
<td>
<ul class="list-inline hstack gap-2 mb-0">
<li class="list-inline-item edit"
data-bs-toggle="tooltip" data-bs-trigger="hover"
data-bs-placement="top" title="Edit">
<a onclick="update_modal_open
('{{$user}}')" href="javascript:"
class="text-primary d-inline-block edit-item-btn">
<i class="ri-pencil-fill fs-16"></i>
</a>
</li>
<li class="list-inline-item edit"
data-bs-toggle="tooltip" data-bs-trigger="hover"
data-bs-placement="top" title="Set Password">
<a onclick="update_agent_password
('{{$user}}')" href="javascript:"
class="text-primary d-inline-block edit-item-btn">
<i class="ri-settings-3-fill fs-16"></i>
</a>
</li>
<li class="list-inline-item" data-bs-toggle="tooltip"
data-bs-trigger="hover" data-bs-placement="top"
title="Remove">
<a class="text-danger d-inline-block remove-item-btn" href="javascript:"
onclick="delete_modal_open
('{{$user->id}}')">
<i class="ri-delete-bin-5-fill fs-16"></i>
</a>
</li>
</ul>
</td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
<!-- New agent Modal start -->
<div class="modal fade" id="addModal" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-light p-3">
<h5 class="modal-title" id="exampleModalLabel">Add Agent</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close" id="close-modal"></button>
</div>
<form class="row p-3 needs-validation" novalidate method="POST"
action="{{ route('agent.create') }}" id="new-form">
@csrf
<div class=" col-md-6 mb-3">
<label for="name" class="form-label">Agent Name <span
class="text-danger">*</span></label>
<input type="text" class="form-control @error('name') is-invalid @enderror"
name="name" value="{{ old('name') }}" id="name"
placeholder="Enter agent name" required>
@error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<div class="invalid-feedback">
Please enter agent name
</div>
</div>
<div class="col-md-6 mb-3">
<label for="useremail" class="form-label">Email <span
class="text-danger">*</span></label>
<input type="email" class="form-control @error('email') is-invalid @enderror"
name="email" value="{{ old('email') }}" id="useremail"
placeholder="Enter email address" required>
@error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<div class="invalid-feedback">
Please enter email
</div>
</div>
<div class="col-md-6 mb-2">
<label for="add_phone_no" class="form-label">Phone Number <span
class="text-danger">*</span></label>
<input type="text"
class="form-control @error('phone_no') is-invalid @enderror" value="{{ old('phone_no') }}" name="phone_no"
id="add_phone_no" placeholder="Enter Phone number" required>
<div class="invalid-feedback">
Please enter phone number
</div>
</div>
<div class="col-md-6 mb-2" id="agent_id">
<label for="agent_id" class="form-label">Agent ID <span
class="text-danger">*</span></label>
<input type="text"
class="form-control @error('agent_id') is-invalid @enderror" value="{{ old('agent_id') }}" name="agent_id"
id="agent_id" placeholder="Enter Agent ID" required>
<div class="invalid-feedback">
Please enter agent ID
</div>
</div>
<div class="mb-2" id="div_password">
<label for="userpassword" class="form-label">Password <span
class="text-danger">*</span></label>
<div class="position-relative auth-pass-inputgroup">
<input type="password"
class="form-control @error('password') is-invalid @enderror" name="password" minlength="6"
id="userpassword" placeholder="Enter password" required>
<button class="btn btn-link position-absolute end-0 top-0 text-decoration-none toggle-password" type="button">
<i class="ri-eye-fill align-middle"></i>
</button>
<div class="invalid-feedback">
Please enter minimum 6 character password
</div>
</div>
</div>
<div class="modal-footer">
<div class="hstack gap-2 justify-content-end">
<button type="button" class="btn btn-light"
data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success"
id="add-btn">Submit</button>
<!-- <button type="button" class="btn btn-success"
id="edit-btn">Update</button> -->
</div>
</div>
</form>
</div>
</div>
</div>
<!-- New agent Modal end -->
<!-- Edit agent start -->
<div class="modal fade" id="editModal" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-light p-3">
<h5 class="modal-title" id="exampleModalLabel">Edit User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close" id="close-modal"></button>
</div>
<form class="row p-3 needs-validation" novalidate method="POST"
action="{{ route('agent.update') }}" id="edit-form">
@csrf
@method('PUT')
<input type="hidden" id="edit_user_id" name="user_id" />
<div class=" col-md-6 mb-3">
<label for="edit_name" class="form-label">Agent Name <span
class="text-danger">*</span></label>
<input type="text" class="form-control @error('name') is-invalid @enderror"
name="name" value="{{ old('name') }}" id="edit_name"
placeholder="Enter agent name" required>
@error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<div class="invalid-feedback">
Please enter agent name
</div>
</div>
<div class="col-md-6 mb-3">
<label for="edit_email" class="form-label">Email <span
class="text-danger">*</span></label>
<input type="email" class="form-control @error('email') is-invalid @enderror"
name="email" value="{{ old('email') }}" id="edit_email"
placeholder="Enter email address" required>
@error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
<div class="invalid-feedback">
Please enter email
</div>
</div>
<div class="col-md-6 mb-2">
<label for="edit_phone_no" class="form-label">Phone Number <span
class="text-danger">*</span></label>
<input type="number"
class="form-control @error('phone_no') is-invalid @enderror" name="phone_no"
id="edit_phone_no" placeholder="Enter Phone number" value="{{ old('phone_no') }}" required>
<div class="invalid-feedback">
Please enter phone number
</div>
</div>
<div class="col-md-6 mb-2">
<label for="edit_agent_id" class="form-label">Agent ID <span
class="text-danger">*</span></label>
<input type="text"
class="form-control @error('agent_id') is-invalid @enderror" value="{{ old('agent_id') }}" name="agent_id"
id="edit_agent_id" placeholder="Enter Agent ID" required>
<div class="invalid-feedback">
Please enter agent ID
</div>
</div>
<div class="modal-footer">
<div class="hstack gap-2 justify-content-end">
<button type="button" class="btn btn-light"
data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success"
id="edit-btn">Update</button>
<!-- <button type="button" class="btn btn-success"
id="edit-btn">Update</button> -->
</div>
</div>
</form>
</div>
</div>
</div>
<!-- Edit agent end -->
<!-- delete modal start -->
<div class="modal fade flip" id="deleteuser" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-body p-5 text-center">
<lord-icon src="https://cdn.lordicon.com/gsqxdxog.json"
trigger="loop" colors="primary:#405189,secondary:#f06548"
style="width:90px;height:90px"></lord-icon>
<div class="mt-4 text-center">
<h4>You are about to delete a User ?</h4>
<div class="hstack gap-2 justify-content-center remove">
<form method="POST"class="needs-validation" action="{{route('agent.delete')}}">
@csrf
@method('DELETE')
<input type="hidden" id="del_id" name="user_id" />
<button type="button"
class="btn btn-link link-success fw-medium text-decoration-none"
data-bs-dismiss="modal" id="deleteRecord-close" ><i
class="ri-close-line me-1 align-middle"></i>
Close</button>
<button class="btn btn-danger" type="submit" id="delete-record">Yes,
Delete It</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- delete modal end -->
<!-- change password start -->
<div class="modal fade" id="passwordModal" tabindex="-1"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header bg-light p-3">
<h5 class="modal-title" id="exampleModalLabel">Set New Password for <span class="text-primary" id="p_agent_name"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close" id="close-modal"></button>
</div>
<form class="needs-validation" novalidate method="POST"
action="{{ route('agent.password') }}">
@csrf
@method('PUT')
<div class="modal-body">
<input type="hidden" id="p_user_id" name="user_id" />
<div class="mb-2" id="div_password">
<label for="password-input" class="form-label" >Password <span
class="text-danger">*</span></label>
<div class="position-relative auth-pass-inputgroup mb-3">
<input type="password"
class="form-control @error('password') is-invalid @enderror" minlength="6" name="password"
id="password-input" placeholder="Enter password" required>
<button class="btn btn-link position-absolute end-0 top-0 text-decoration-none toggle-password" type="button">
<i class="ri-eye-fill align-middle"></i>
</button>
<div class="invalid-feedback">
Please enter minimum 6 character password
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="hstack gap-2 justify-content-end">
<button type="button" class="btn btn-light"
data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success"
id="edit-btn">Update</button>
<!-- <button type="button" class="btn btn-success"
id="edit-btn">Update</button> -->
</div>
</div>
</form>
</div>
</div>
</div>
<!-- change password end -->
</div>
</div>
</div>
<!--end col-->
</div>
<!--end row-->
@endsection
@section('script')
<script>
$(document).ready(function() {
$("#edit_userGroup-field").select2({
dropdownParent: $("#editModal")
});
$("#userGroup-field").select2({
dropdownParent: $("#addModal")
});
document.querySelectorAll('.toggle-password').forEach(function(button) {
button.addEventListener('click', function() {
const input = this.closest('.auth-pass-inputgroup').querySelector('input');
const icon = this.querySelector('i');
const type = input.getAttribute('type') === 'password' ? 'text' : 'password';
input.setAttribute('type', type);
icon.classList.toggle('ri-eye-fill');
icon.classList.toggle('ri-eye-off-fill');
});
});
const passwordInput = document.getElementById('password-input');
const toggleBtn = document.getElementById('toggle-password');
const toggleIcon = document.getElementById('toggle-password-icon');
if (toggleBtn && passwordInput && toggleIcon) {
toggleBtn.addEventListener('click', function(e) {
e.preventDefault();
if (passwordInput.type === 'password') {
passwordInput.type = 'text';
toggleIcon.classList.remove('ri-eye-fill');
toggleIcon.classList.add('ri-eye-off-fill');
} else {
passwordInput.type = 'password';
toggleIcon.classList.remove('ri-eye-off-fill');
toggleIcon.classList.add('ri-eye-fill');
}
});
}
// Bangladeshi phone number validation
function isValidBDPhone(phone) {
return /^(\+?88)?01[3-9]\d{8}$/.test(phone);
}
// Add form validation
$("#edit-form").on("submit", function(e) {
var editPhoneInput = $(this).find("#edit_phone_no");
if(editPhoneInput.length && !isValidBDPhone(editPhoneInput.val())) {
editPhoneInput.addClass("is-invalid");
editPhoneInput.removeClass("is-valid");
editPhoneInput.nextAll('.invalid-feedback').first().text("Please enter a valid Bangladeshi phone number");
editPhoneInput.focus();
e.preventDefault();
} else {
editPhoneInput.removeClass("is-invalid");
editPhoneInput.addClass("is-valid");
editPhoneInput.nextAll('.invalid-feedback').first().text("Please enter phone number");
}
});
// Add form validation for create modal
$("#new-form").on("submit", function(e) {
var phoneInput = $(this).find("#add_phone_no");
if(phoneInput.length && (!phoneInput.val() || !isValidBDPhone(phoneInput.val()))) {
phoneInput.removeClass("is-valid");
phoneInput.addClass("is-invalid");
if(!phoneInput.val()) {
phoneInput.nextAll('.invalid-feedback').first().text("Please enter phone number");
} else {
phoneInput.nextAll('.invalid-feedback').first().text("Please enter a valid Bangladeshi phone number");
}
phoneInput.focus();
e.preventDefault();
} else {
phoneInput.removeClass("is-invalid");
phoneInput.addClass("is-valid");
phoneInput.nextAll('.invalid-feedback').first().text("Please enter phone number");
}
});
});
function update_agent_password(data) {
data=JSON.parse(data);
$("#p_user_id").val(data.id);
$("#p_agent_name").text(data.name);
$('#passwordModal').modal('toggle');
}
function update_modal_open(data) {
data=JSON.parse(data);
$("#edit_user_id").val(data.id);
$("#edit_name").val(data.name);
$("#edit_email").val(data.email);
$("#edit_phone_no").val(data.phone_no);
$("#edit_agent_id").val(data.agent_id);
$('#editModal').modal('toggle');
}
function delete_modal_open(id) {
$("#del_id").val(id);
$('#deleteuser').modal('toggle');
}
</script>
@endsection
|