273 lines
13 KiB
PHP
273 lines
13 KiB
PHP
<style>
|
||
.dataTables_filter {position: absolute;}
|
||
.dataTables_length label {height: 21px !important;}
|
||
</style>
|
||
|
||
<!-- End ADD and EDIT Page HTML -->
|
||
<div class="row" id="List-page">
|
||
<div class="col-12">
|
||
<div class="card">
|
||
<div class="card-body maincard">
|
||
<table data-custom-table-css="table" class="table table-sm m-0 table-centered dt-responsive nowrap w-100" cellspacing="a" id="user-table">
|
||
<thead class="bg-light">
|
||
<tr>
|
||
<th class="font-weight-medium">S.No.</th>
|
||
<th class="font-weight-medium">RTO Office at</th>
|
||
<th class="font-weight-medium">RTO Code</th>
|
||
<th class="font-weight-medium">RTO State</th>
|
||
<!-- <th class="font-weight-medium">Status</th> -->
|
||
<th class="font-weight-medium">Action</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php if(isset($data)) { $slno = 1; ?>
|
||
<?php foreach($data as $index => $row) { ?>
|
||
<tr>
|
||
<td class="text-center"><?= $slno++; ?></td>
|
||
<td><?= $row['rto_name']; ?></td>
|
||
<td><?= $row['rto_code']; ?></td>
|
||
<td><?= $row['rto_state']; ?></td>
|
||
<!-- <td>
|
||
<span class="<?php if($row['is_active'] == 1){ echo 'badge badge-primary'; }else{ echo 'badge badge-danger'; } ?>">
|
||
<?php if($row['is_active'] == 1){ echo 'Active'; }else{ echo 'In-Active'; } ?>
|
||
</span>
|
||
</td> -->
|
||
<td>
|
||
<div class="btn-group dropdown" style="position: relative !important;left:0px !important;top:0px !important;">
|
||
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
|
||
<div class="dropdown-menu dropdown-menu-right" style="cursor: pointer;">
|
||
<a class="dropdown-item" data-id="<?= $row['id']; ?>" onclick="handleSaveEditAndDelete('edit', this)">
|
||
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
|
||
</a>
|
||
<?php if ($row['is_active'] == 1): ?>
|
||
<a class="dropdown-item" data-id="<?= $row['id']; ?>" onclick="handleSaveEditAndDelete('remove', this)">
|
||
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
|
||
</a>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php } ?>
|
||
<?php } else { ?>
|
||
<tr>
|
||
<td colspan="3" class="text-center">No data available</td>
|
||
</tr>
|
||
<?php } ?>
|
||
</tbody>
|
||
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- modal content -->
|
||
<div id="con-close-modal" class="modal fade app-font-family" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;" data-backdrop="static">
|
||
<div class="modal-dialog modal-dialog-centered">
|
||
<div class="modal-content">
|
||
<div class="modal-header">
|
||
<h4 class="modal-title" id="modalLabel">Add RTO Details</h4>
|
||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||
</div>
|
||
<div class="modal-body p-4">
|
||
<!-- <form class="parsley-examples" id="RTOForm" enctype="multipart/form-data"> -->
|
||
<form id="RTOForm" enctype="multipart/form-data">
|
||
<input type="hidden" name="pk" id="rto_id"/>
|
||
<div class="form-group">
|
||
<div class="form-row">
|
||
<div class="form-group col-md-12">
|
||
<label for="rto_name">RTO Office Name<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="rto_name" name="rto_name" placeholder="Enter RTO Office Name" required>
|
||
</div>
|
||
<div class="form-group col-md-12">
|
||
<label for="rto_code">RTO Code<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="rto_code" name="rto_code"
|
||
placeholder="Enter RTO Code" required
|
||
maxlength="2"
|
||
inputmode="numeric"
|
||
pattern="[0-9]{2}"
|
||
oninput="this.value = this.value.replace(/[^0-9]/g, '').slice(0,2);">
|
||
</div>
|
||
|
||
<div class="form-group col-md-12">
|
||
<label for="rto_state">RTO State<span class="text-danger">*</span></label>
|
||
<input type="text" class="form-control" id="rto_state" name="rto_state"
|
||
placeholder="Enter RTO State" required
|
||
maxlength="2"
|
||
pattern="[A-Z]{2}"
|
||
oninput="this.value = this.value.replace(/[^A-Za-z]/g, '').toUpperCase().slice(0,2);">
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="form-group text-right m-b-0">
|
||
<button type="button" class="btn app-btn-secondary waves-effect waves-light" id="btnSubmit" onclick="handleSaveEditAndDelete('submit')">Submit</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
var table;
|
||
$(document).ready(function () {
|
||
var ticketsTable = $('#user-table');
|
||
ticketsTable.DataTable({
|
||
scrollX: true,
|
||
// dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||
// "<'row'<'col-sm-12'tr>>" +
|
||
// "<'row'<'col-sm-5'i><'col-sm-7'p>>", // Pagination at the bottom, without page length selector
|
||
dom: "<'row'<'col-sm-7'f><'col-sm-5 text-right'B>>" + // Filter left, buttons right
|
||
"<'row'<'col-sm-12'tr>>" +
|
||
"<'row align-items-center'<'col-5 text-start'i><'col-7 d-flex justify-content-end align-items-center'<'me-2'l>p>>",
|
||
lengthMenu: [[10, 20, 50, 100], [10, 20, 50, 100]],
|
||
buttons: [
|
||
{
|
||
text: 'Add',
|
||
className: 'btn app-btn-primary mr-2',
|
||
action: function(e, dt, node, config) {
|
||
openModal()
|
||
}
|
||
},
|
||
{
|
||
extend: 'collection',
|
||
text: '<span class=" btn-custom"> Export </span><i class="mdi mdi-menu-down"></i>',
|
||
className: 'btn app-btn-secondary ',
|
||
buttons: [
|
||
{
|
||
extend: 'csv',
|
||
text: '<i class="mdi mdi-file-delimited " ></i><span class=" btn-custom"> CSV </span>',
|
||
title: 'RTO',
|
||
className: 'app-btn-primary ',
|
||
exportOptions: {
|
||
columns: ':not(:last-child)'
|
||
},
|
||
}
|
||
]
|
||
}
|
||
],
|
||
language: {
|
||
search: `
|
||
<div class="datatable-search-wrapper" style="position:relative; display:inline-block;">
|
||
_INPUT_
|
||
<i class="mdi mdi-magnify datatable-search-icon"
|
||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666;"></i>
|
||
<i class="mdi mdi-close-circle datatable-clear-icon"
|
||
style="position:absolute; right:10px; top:50%; transform:translateY(-50%); color:#666; display:none;"></i>
|
||
</div>`,
|
||
searchPlaceholder: "Search",
|
||
emptyTable: '<div class="text-center text-muted">No Data found</div>'
|
||
},
|
||
paging: true, // Enable pagination
|
||
pageLength: 10, // Set default number of rows per page (optional)
|
||
// ordering: false,
|
||
});
|
||
});
|
||
|
||
$('.close').click(function(){
|
||
resetValues()
|
||
})
|
||
|
||
function openModal(){
|
||
var myModal = new bootstrap.Modal(document.getElementById('con-close-modal'));
|
||
myModal.show();
|
||
}
|
||
|
||
function handleSaveEditAndDelete(type = 'submit', el = null) {
|
||
|
||
let url = '<?= base_url('util/rtoMaster') ?>';
|
||
let method = "POST";
|
||
let requestData = {};
|
||
|
||
let pk = null;
|
||
|
||
// If element is passed (from edit/remove button), get its data-id
|
||
if (el) { pk = $(el).data('id'); }
|
||
|
||
requestData.pk = pk;
|
||
|
||
if(type == 'submit'){
|
||
$("#RTOForm").find("input, select, textarea").each(function () {
|
||
let name = $(this).attr("name");
|
||
let value = $.trim($(this).val());
|
||
if (name) requestData[name] = value;
|
||
});
|
||
}
|
||
|
||
if(type == 'remove'){
|
||
method = "DELETE";
|
||
} else if (type == 'edit'){
|
||
method = "GET";
|
||
$('#modalLabel').text('Edit RTO details');
|
||
$('#vehicleTypeForm')[0].reset();
|
||
}
|
||
|
||
console.log("type", type)
|
||
console.log("url", url)
|
||
console.log("method", method)
|
||
console.log("requestData", requestData)
|
||
|
||
$('.loader').fadeIn();
|
||
$('.loader-mask').fadeIn();
|
||
|
||
// Send AJAX request
|
||
sendAjaxRequestForGlobal(url, method, requestData, function(response) {
|
||
|
||
console.log('Data fetched successfully:', response);
|
||
|
||
if (response.status) {
|
||
if(type == 'edit'){
|
||
appendEditData(response.data);
|
||
} else if(type == 'remove'){
|
||
toastr.success(response.message, 'Success');
|
||
if(el) $(el).closest('tr').remove();
|
||
window.location.reload();
|
||
} else if(type == 'submit'){
|
||
toastr.success(response.message, 'Success');
|
||
var myModal = new bootstrap.Modal(document.getElementById('con-close-modal'));
|
||
myModal.hide();
|
||
resetValues();
|
||
window.location.reload();
|
||
}
|
||
} else {
|
||
toastr.warning(response.message, 'Warning');
|
||
}
|
||
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
|
||
}, function(xhr, status, error) {
|
||
console.error('Error fetching data:', error);
|
||
console.error(xhr.responseText);
|
||
$('.loader').fadeOut();
|
||
$('.loader-mask').delay(350).fadeOut('slow');
|
||
if (xhr.status === 400) {
|
||
let response = JSON.parse(xhr.responseText);
|
||
if (response.errors) {
|
||
$.each(response.errors, function (field, message) {
|
||
toastr.warning(message, 'Validation Error');
|
||
});
|
||
} else {
|
||
toastr.warning(response.message || 'Validation failed', 'Warning');
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
function resetValues(){
|
||
$('#modalLabel').text('Add RTO Details');
|
||
$('#RTOForm')[0].reset();
|
||
}
|
||
|
||
function appendEditData(data){
|
||
$('#rto_id').val(data[0]['id']);
|
||
$('#rto_name').val(data[0]['rto_name']);
|
||
$('#rto_code').val(data[0]['rto_code']);
|
||
$('#rto_state').val(data[0]['rto_state']);
|
||
openModal()
|
||
}
|
||
</script>
|
||
|