nhance/app/Views/frontend_content_list2.php
2025-11-29 10:40:49 +05:30

320 lines
14 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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>
<!-- `content` `notes` -->
<th class="font-weight-medium">S.No.</th>
<th class="font-weight-medium">Type</th>
<th class="font-weight-medium">Content Section</th>
<th class="font-weight-medium">Heading</th>
<!-- <th class="font-weight-medium">Status</th> -->
<th class="font-weight-medium">Action</th>
</tr>
</thead>
<tbody>
<?php if(isset($test)) { $slno = 1; ?>
<?php foreach($test as $index => $row) { ?>
<tr>
<td class="text-center"><?= $slno++; ?></td>
<td><?= $row['type']; ?></td>
<td><?= $row['content_section']; ?></td>
<td><?= $row['heading']; ?></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 modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="modalLabel">Add Front End Content</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body p-4">
<form id="frontEndContentForm" enctype="multipart/form-data">
<input type="hidden" name="pk" id="fe_id"/>
<div class="form-group">
<div class="form-row">
<div class="col-md-4">
<label for="type">Type<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="type" name="type" placeholder="Enter Type" required>
</div>
<div class="col-md-4">
<label for="content_section">Content Section<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="content_section" name="content_section" placeholder="Enter Content Section" required>
</div>
<div class="col-md-4">
<label for="branch_name">Heading<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="heading" name="heading" placeholder="Enter Heading" required>
</div>
</div>
</div>
<button type="button" class="btn app-btn-secondary waves-effect waves-light text-end" onclick="AddContentsAndNotes()">Add Contents And Notes</button>
<table>
</table>
<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: 'Front End Content',
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();
}
// old Version
// function handleSaveEditAndDelete(type = 'submit', pk = null){
// let url = '<?= base_url('util/nhanceBranchMaster') ?>';
// let method = "POST";
// let requestData = {};
// $('#modalLabel').text('Add Front End Content');
// requestData.pk = pk;
// if(type == 'submit'){
// $("#frontEndContentForm").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"
// }
// 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'){
// $('#modalLabel').text('Edit Front End Content');
// appendEditData(response.data);
// }else{
// toastr.success(response.message, 'SUCCESS');
// }
// } 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');
// });
// }
function handleSaveEditAndDelete(type = 'submit', el = null) {
let url = '<?= base_url('util/nhanceBranchMaster') ?>';
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'){
$("#frontEndContentForm").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 Front End Content');
$('#frontEndContentForm')[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();
$('#frontEndContentForm')[0].reset();
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');
});
}
function resetValues(){
$('#modalLabel').text('Add Front End Content');
$('#frontEndContentForm')[0].reset();
}
function appendEditData(data){
$('#fe_id').val(data[0]['id']);
$('#branch_name').val(data[0]['branch_name']);
openModal()
}
</script>