373 lines
19 KiB
PHP
Executable File
373 lines
19 KiB
PHP
Executable File
<?php include('layout/header.php'); ?>
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="page-title-box page-title-box-alt">
|
|
<h5 class="page-title">Bike Model List - <span style="font-weight: 500;"><?php echo $make_name; ?></span></h5>
|
|
<div class="page-title-right">
|
|
<ol class="breadcrumb m-0">
|
|
<li class="">
|
|
<a href="#" data-toggle="modal" data-target="#bike_model_login-modal_1" class="btn btn-primary waves-effect" onclick="clearDetials(this)">
|
|
Add Model
|
|
</a>
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<!-- <h4 class="header-title">Business List</h4> -->
|
|
<table id="datatable-bikeModel" class="table table-striped dt-responsive nowrap w-100" style="width:100% !important;text-align: center;width: 100%;">
|
|
<thead>
|
|
<tr>
|
|
<th>Model Name</th>
|
|
<th>Cubic Capacity</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($model as $index => $item): ?>
|
|
<tr class="model_tr_<?php echo $index+1;?>">
|
|
<td class="model_name"><?php echo $item['model_name']; ?></td>
|
|
<td class="cubic_capacity"><?php echo $item['value']; ?></td>
|
|
<td>
|
|
<?php if($item['isactive'] == 1): ?>
|
|
<span style="color:green">Active</span>
|
|
<?php else: ?>
|
|
<span style="color:red">Inactive</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td>
|
|
|
|
<div class="btn-group dropdown">
|
|
<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">
|
|
<a data-toggle="modal" data-target="#bike_model_login-modal_1" data-value="<?php echo $item['model_id']; ?>" class="dropdown-item edit-button" onclick="editModel(this), datatableBikeModel('model_tr_<?php echo $index+1; ?>')"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
|
|
<a data-value="<?php echo $item['model_id']; ?>" class="dropdown-item" onclick="deleteModel(this), datatableBikeModel('model_tr_<?php echo $index+1; ?>')"><i style="color: #526dee;" class="ri-delete-bin-line mr-2 text-muted font-18 vertical-middle"></i>Delete</a>
|
|
<?php if($item['isactive'] == 1): ?>
|
|
<a class="dropdown-item" data-id="<?php echo $item['model_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Deactivate" onclick="statusChange(this), datatableBikeModel('model_tr_<?php echo $index+1; ?>')"><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i>Deactivate</a>
|
|
<?php else: ?>
|
|
<a class="dropdown-item" data-id="<?php echo $item['model_id']; ?>" data-isactive="<?php echo $item['isactive']; ?>" title="Activate" onclick="statusChange(this), datatableBikeModel('model_tr_<?php echo $index+1; ?>')"><i class="fa fa-bicycle"></i>Activate</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div> <!-- end table-responsive-->
|
|
</div>
|
|
</div> <!-- end card -->
|
|
</div> <!-- end col -->
|
|
</div>
|
|
|
|
|
|
<!-- Start Bike Model Create Pop-UP -->
|
|
<div id="bike_model_login-modal_1" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-body">
|
|
<div class="text-center mt-2 mb-4">
|
|
<h4 id="form_add_edit">Add Models</h4>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<input type="text" id="edit_model_id" hidden>
|
|
<input type="text" id="cubic_capacity_id" hidden>
|
|
|
|
<div class="form-group">
|
|
|
|
<input class="form-control" type="text" id="make_id" required="" value="<?php echo $make_id; ?>" placeholder="Make Name...." style="display:none;">
|
|
<label for="makename">Make Name </label>
|
|
<input class="form-control" type="text" id="makename" required="" value="<?php echo $make_name; ?>" placeholder="Make Name...." disabled>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="cubiccapacity">Cubic capacity</label>
|
|
<select class="form-control" id="cubiccapacity" required data-toggle="select2">
|
|
<option value="0">Select Cubic capacity</option>
|
|
<?php foreach ($cubiccapacity as $item): ?>
|
|
<option value="<?= $item['id'] ?>"><?= $item['value'] ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="modelname">Model Name </label>
|
|
<input class="form-control" type="text" id="modelname" required="" placeholder="Model Name....">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group text-center">
|
|
<button class="btn btn-rounded btn-primary" type="submit" onclick="submitModels(this)">Submit</button>
|
|
</div>
|
|
|
|
</div>
|
|
</div><!-- /.modal-content -->
|
|
</div><!-- /.modal-dialog -->
|
|
</div><!-- /.modal -->
|
|
<!-- End Bike Model Create Pop-UP -->
|
|
<?php include('layout/footer.php'); ?>
|
|
|
|
|
|
<script>
|
|
function submitModels(params) {
|
|
var edit_model_id = $('#edit_model_id').val();
|
|
if (!edit_model_id) {
|
|
edit_model_id =0;
|
|
}
|
|
|
|
var formData = {
|
|
make_id: $('#make_id').val(),
|
|
modelname: $('#modelname').val(),
|
|
cubiccapacity: $('#cubiccapacity').val()
|
|
};
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '<?php echo base_url()."create_model/"?>'+edit_model_id,
|
|
data: formData,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
// console.log(response);
|
|
if (response.status == "failed") {
|
|
toastr.warning(response.data, 'Warning');
|
|
}else{
|
|
$('#bike_model_login-modal_1').modal('hide');
|
|
$('#makename').val('');
|
|
$('#modelname').val('');
|
|
$('#cubiccapacity').val('');
|
|
|
|
toastr.success(response.data, 'Success');
|
|
|
|
// $('tbody').html('');
|
|
|
|
// response.model_list.forEach(function(item) {
|
|
// var row = '<tr>' +
|
|
// '<td class="make">' + item.model_name + '</td>' +
|
|
// '<td>';
|
|
|
|
// if (item.isactive == 1) {
|
|
// row += '<span style="color:green">Active</span>';
|
|
// } else if (item.isactive == 0) {
|
|
// row += '<span style="color:red">Inactive</span>';
|
|
// }
|
|
|
|
// row += '</td><td>' +
|
|
// '<div class="btn-group dropdown">' +
|
|
// '<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">' +
|
|
// '<a data-toggle="modal" data-target="#bike_model_login-modal_1" data-value="' + item.model_id + '" class="dropdown-item edit-button" onclick="editModel(this)"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>'+
|
|
// '<a data-value="' + item.model_id + '" class="dropdown-item" onclick="deleteModel(this)"><i style="color: #526dee;" class="ri-delete-bin-line mr-2 text-muted font-18 vertical-middle"></i>Delete</a>';
|
|
// if (item.isactive == 1) {
|
|
// row += '<a class="dropdown-item" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Deactivate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i>Deactivate</a>';
|
|
// } else if (item.isactive == 0) {
|
|
// row += '<a class="dropdown-item" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Activate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i>Activate</a>';
|
|
// }
|
|
|
|
// row += '</td><td></td></tr>';
|
|
|
|
// // Append the row to the tbody
|
|
// $('tbody').append(row);
|
|
// });
|
|
}
|
|
window.location.reload();
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function statusChange(params) {
|
|
var status = params.getAttribute('data-isactive');
|
|
var model_id = params.getAttribute('data-id');
|
|
if(status == 1){
|
|
var isactive= 0;
|
|
}else{
|
|
var isactive= 1;
|
|
}
|
|
|
|
var formData = {
|
|
model_id: model_id,
|
|
isactive: isactive
|
|
};
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '<?php echo base_url()."status_model"?>',
|
|
data: formData,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
|
|
if (response.status == "success") {
|
|
// $('tbody').html('');
|
|
|
|
response.data.forEach(function(item) {
|
|
var row = '<tr>' +
|
|
'<td class="make">' + item.model_name + '</td>' +
|
|
'<td>';
|
|
|
|
if (item.isactive == 1) {
|
|
row += '<span style="color:green">Active</span>';
|
|
} else if (item.isactive == 0) {
|
|
row += '<span style="color:red">Inactive</span>';
|
|
}
|
|
|
|
row += '</td><td>' +
|
|
'<div class="btn-group dropdown">' +
|
|
'<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">' +
|
|
'<a data-toggle="modal" data-target="#bike_model_login-modal_1" data-value="' + item.model_id + '" class="dropdown-item edit-button" onclick="editModel(this)"><i class="ri-pencil-line mr-2 text-muted font-18 vertical-middle"></i>Edit</a>'+
|
|
'<a data-value="' + item.model_id + '" class="dropdown-item" onclick="deleteModel(this)"><i style="color: #526dee;" class="ri-delete-bin-line mr-2 text-muted font-18 vertical-middle"></i>Delete</a>';
|
|
if (item.isactive == 1) {
|
|
row += '<a class="dropdown-item" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Deactivate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i><i class="fa fa-times" style="font-size: x-small;"></i>Deactivate</a>';
|
|
} else if (item.isactive == 0) {
|
|
row += '<a class="dropdown-item" data-id="' + item.model_id + '" data-isactive="' + item.isactive + '" title="Activate" onclick="statusChange(this)" ><i class="fa fa-bicycle"></i>Activate</a>';
|
|
}
|
|
|
|
row += '</td><td></td></tr>';
|
|
|
|
// Append the row to the tbody
|
|
// $('tbody').append(row);
|
|
window.location.reload();
|
|
});
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function editModel(params) {
|
|
|
|
$('#edit_model_id').val($(params).data('value'));
|
|
|
|
$('#form_add_edit').text('Edit Models');
|
|
|
|
var full_div = $(params).closest('tr')[0];
|
|
$('#modelname').val($(full_div).find('.model_name').text());
|
|
var cubicCapacity = $(full_div).find('.cubic_capacity').text();
|
|
console.log(cubicCapacity);
|
|
|
|
$('#cubiccapacity option').each(function() {
|
|
if ($(this).text().trim() === cubicCapacity.trim()) {
|
|
$(this).prop('selected', true).trigger('change');
|
|
}
|
|
});
|
|
// var cc_id = $(full_div).find('.cubic_capacity_id').text();
|
|
// var selectElementForCC = document.getElementById('cubiccapacity');
|
|
// var ccOptions = selectElementForCC.options;
|
|
// for (var j = 0; j < ccOptions.length; j++) {
|
|
// if (ccOptions[j].value === cc_id) {
|
|
// ccOptions[j].selected = true;
|
|
// break;
|
|
// }
|
|
// }
|
|
}
|
|
|
|
function clearDetials(params) {
|
|
$('#form_add_edit').text('Add Models');
|
|
|
|
$('#modelname').val('');
|
|
$('#cubiccapacity').val('');
|
|
}
|
|
|
|
function deleteModel(params) {
|
|
|
|
var model_id = $(params).data('value');
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '<?php echo base_url()."delete_model/"?>'+model_id,
|
|
dataType: 'json',
|
|
success: function(response) {
|
|
console.log(response);
|
|
if (response == "delete_done") {
|
|
window.location.reload();
|
|
}
|
|
},
|
|
error: function(xhr, status, error) {
|
|
// Handle error response here
|
|
console.error(xhr.responseText);
|
|
}
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
<script>
|
|
var datatable_bikeModel ='';
|
|
$(document).ready(function() {
|
|
datatable_bikeModel = $('#datatable-bikeModel').DataTable({
|
|
"order": [[0, 'asc']], // Set initial sorting to descending on the first column
|
|
"dom": 'Bfrtip', // Show export buttons
|
|
"buttons": [{extend: 'pdfHtml5',title: 'Products', text: 'PDF',},
|
|
{extend: 'print',title: 'Products',text: 'Print',},
|
|
{extend: 'copy',text: 'Copy', titleAttr: 'Copy',},
|
|
{extend: 'csv',text: 'CSV', title: 'Products', }],
|
|
"language": {
|
|
"search": "Search: " // Customize search label
|
|
},
|
|
});
|
|
|
|
|
|
//Start DataTable Paging is session is set
|
|
var savedPage = sessionStorage.getItem('currentPage');
|
|
var hightlight_tr = sessionStorage.getItem('hightlight_tr');
|
|
// console.log(savedPage);
|
|
// console.log(hightlight_tr);
|
|
// Ensure savedPage is a number
|
|
savedPage = parseInt(savedPage);
|
|
// Check if savedPage is not null and adjust if necessary
|
|
if (savedPage !== null && !isNaN(savedPage)) {
|
|
// Check if the saved page number is within the bounds of the current DataTable
|
|
var totalPages = datatable_bikeModel.page.info().pages; // Total number of pages in the DataTable
|
|
if (savedPage >= totalPages) {
|
|
// adjust to the last page of the DataTable
|
|
savedPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
}
|
|
// Move DataTable to the saved page and draw
|
|
datatable_bikeModel.page(savedPage).draw(false);
|
|
|
|
// Select the highlighted row
|
|
var $row = $('.' + hightlight_tr);
|
|
|
|
// Smoothly scroll to the row and center it in the viewport
|
|
$('html, body').animate({
|
|
scrollTop: $row.offset().top - ($(window).height() / 2) + ($row.height() / 2)
|
|
}, 500, function() {
|
|
|
|
// After focusing, change background color
|
|
$row.css('background', '#faf6ca');
|
|
|
|
// Remove background color after 4 seconds
|
|
setTimeout(function() {
|
|
$row.css('background', '');
|
|
}, 4000);
|
|
});
|
|
}
|
|
sessionStorage.removeItem('currentPage');
|
|
//End DataTable Paging is session is set
|
|
|
|
|
|
|
|
})
|
|
function datatableBikeModel(value) {
|
|
console.log(value);
|
|
|
|
var currentPage = datatable_bikeModel.page.info().page;
|
|
sessionStorage.setItem('currentPage', currentPage);
|
|
sessionStorage.setItem('hightlight_tr', value);
|
|
|
|
}
|
|
</script>
|