FIX_FE
This commit is contained in:
parent
2bd43c094f
commit
ed828e3e7a
@ -55,7 +55,6 @@ $routes->post("add_advertise_image", "AppContentManagementController::add_advert
|
|||||||
$routes->post('remove_advertise_image', 'AppContentManagementController::remove_advertise_image');
|
$routes->post('remove_advertise_image', 'AppContentManagementController::remove_advertise_image');
|
||||||
$routes->get("add_image_index", "AppContentManagementController::add_image_index");
|
$routes->get("add_image_index", "AppContentManagementController::add_image_index");
|
||||||
$routes->get("getAdvertiseImage/(:any)", "AppContentManagementController::getAdvertiseImage/$1");
|
$routes->get("getAdvertiseImage/(:any)", "AppContentManagementController::getAdvertiseImage/$1");
|
||||||
$routes->get("frontend_content", "AppContentManagementController::frontend_content");
|
|
||||||
$routes->get('showAdvertiseImage/(:any)', 'AppContentManagementController::showAdvertiseImage/$1');
|
$routes->get('showAdvertiseImage/(:any)', 'AppContentManagementController::showAdvertiseImage/$1');
|
||||||
|
|
||||||
|
|
||||||
@ -794,7 +793,8 @@ $routes->get("ticketHistoryList", "ThzController::ticketHistoryList");
|
|||||||
|
|
||||||
// General FAQ
|
// General FAQ
|
||||||
$routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ');
|
$routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ');
|
||||||
|
$routes->match(['get','post','delete'], 'frontend_content', 'AppContentManagementController::frontend_content');
|
||||||
|
$routes->get("getFEContent", "EmployeeRestController::getFEContent");
|
||||||
|
|
||||||
//for testing
|
//for testing
|
||||||
$routes->group('test', function($routes) {
|
$routes->group('test', function($routes) {
|
||||||
|
|||||||
@ -136,61 +136,90 @@ class AppContentManagementController extends AdminController
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// public function getAdvertiseImage($image_id){
|
public function frontend_content()
|
||||||
// $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first();
|
{
|
||||||
// if($image_data){
|
|
||||||
// return $image_data['name'];
|
$method = $this->request->getMethod();
|
||||||
// }else{
|
|
||||||
// return ;
|
if ($this->request->getMethod() === 'post') {
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
$id = $this->request->getPost('fe_id');
|
||||||
|
$data = $this->request->getPost();
|
||||||
|
|
||||||
|
unset($data['fe_id']);
|
||||||
|
|
||||||
// Front End Content Area
|
foreach ($data as $k => $v) {
|
||||||
public function frontend_content(){
|
if ($v === '' || $v === null) {unset($data[$k]);}
|
||||||
|
}
|
||||||
|
|
||||||
|
// INSERT / UPDATE
|
||||||
|
if (empty($id)) {
|
||||||
|
$status = $this->feContentModel->insert($data);
|
||||||
|
$text = "Created";
|
||||||
|
} else {
|
||||||
|
$status = $this->feContentModel->update($id, $data);
|
||||||
|
$text = "Updated";
|
||||||
|
}
|
||||||
|
|
||||||
$data['test'] = $this->feContentModel->findAll();
|
return $this->respond([
|
||||||
$headerData['tab_name'] = 'Front-End Content';
|
'status' => $status ? true : false,
|
||||||
$headerData['page_name'] = 'Front-End Content';
|
'message' => "Frontend Content $text " . ($status ? 'successfully' : 'failed'),
|
||||||
|
'code' => $status ? 200 : 400,
|
||||||
|
'data' => $data,
|
||||||
|
] , $status ? 200 : 400 );
|
||||||
|
}
|
||||||
|
elseif ($method === 'get') {
|
||||||
|
|
||||||
echo view('layout/header', $headerData);
|
$id = $this->request->getGet('fe_id') ?? null;
|
||||||
echo view('frontend_content_list', $data);
|
|
||||||
echo view('layout/footer');
|
if (!empty($id)) {
|
||||||
|
|
||||||
|
$data['fe_list'] = $this->feContentModel->where('id', $id)->orderBy('id', 'DESC')->findAll();
|
||||||
|
|
||||||
|
if (!empty($data)) {
|
||||||
|
return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200);
|
||||||
|
} else {
|
||||||
|
return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['fe_list'] = $this->feContentModel->orderBy('id', 'DESC')->findAll();
|
||||||
|
|
||||||
|
return $this->loadLayout('frontend_content_list', ['data' => $data,'tab_name' => 'Front-End Content','page_name' => 'Front-End Content']);
|
||||||
|
|
||||||
|
} elseif ($method === 'delete') {
|
||||||
|
|
||||||
|
// $input = $this->request->getRawInput();
|
||||||
|
$id = $this->request->getGet('fe_id'); // ✅ THIS
|
||||||
|
$id = $id ?? null;
|
||||||
|
|
||||||
|
if (empty($id)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'code' => 404,
|
||||||
|
'message' => 'No ID provided for deletion'
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
$update_status = $this->feContentModel->where('id', $id)->set(['is_active' => 0])->update();
|
||||||
|
|
||||||
|
if ($update_status) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => true,
|
||||||
|
'code' => 200,
|
||||||
|
'message' => 'Data removed successfully',
|
||||||
|
'fe_id' => $id
|
||||||
|
], 200);
|
||||||
|
} else {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'code' => 400,
|
||||||
|
'message' => 'Failed to remove data',
|
||||||
|
'fe_id' => $id
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// public function FAQ()
|
|
||||||
// {
|
|
||||||
|
|
||||||
// $data['tab_name'] = "FAQ's";
|
|
||||||
// $data['page_name'] = "FAQ's";
|
|
||||||
// return $this->loadLayout('faq_list', $data);
|
|
||||||
|
|
||||||
// $returnType = strtolower($this->request->getGet('return_type') ?? 'api');
|
|
||||||
|
|
||||||
// $data = $this->request->getGet();
|
|
||||||
|
|
||||||
// $faq_list = $this->faqModel->select('*')->where('is_active', 1)->orderBy('id', 'desc')->findAll();
|
|
||||||
|
|
||||||
// if ($returnType === 'api') {
|
|
||||||
// if (empty($faq_list)) {
|
|
||||||
// $this->myLogger->logme('error', 'empty tickets in ticket list: ' . json_encode($faq));
|
|
||||||
// return $this->response->setJSON([ 'status' => 'error','message' => 'No Details found'])->setStatusCode(404);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// $data['tab_name'] = "FAQ's";
|
|
||||||
// $data['page_name'] = "FAQ's";
|
|
||||||
// return $this->loadLayout('faq_list', $data);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return $this->response->setJSON([
|
|
||||||
// 'status' => 'success',
|
|
||||||
// 'data' => [],
|
|
||||||
// ])->setStatusCode(200);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function FAQ()
|
public function FAQ()
|
||||||
|
|||||||
@ -34,9 +34,7 @@ class FAQModel extends Model
|
|||||||
|
|
||||||
protected function checkAndADDCreatedByValue(array $data)
|
protected function checkAndADDCreatedByValue(array $data)
|
||||||
{
|
{
|
||||||
// Check if 'updated_by' value is null or empty
|
|
||||||
if (empty($data['data']['created_by'])) {
|
if (empty($data['data']['created_by'])) {
|
||||||
// Set 'updated_by' value to the current session user ID
|
|
||||||
$data['data']['created_by'] = get_session_userid();
|
$data['data']['created_by'] = get_session_userid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,12 +43,13 @@ class FAQModel extends Model
|
|||||||
|
|
||||||
protected function checkAndUpdateUpdatedByValue(array $data)
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
||||||
{
|
{
|
||||||
// Check if 'updated_by' value is null or empty
|
|
||||||
if (empty($data['data']['updated_by'])) {
|
if (empty($data['data']['updated_by'])) {
|
||||||
// Set 'updated_by' value to the current session user ID
|
|
||||||
$data['data']['updated_by'] = get_session_userid();
|
$data['data']['updated_by'] = get_session_userid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data['data']['updated_on'] = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -19,6 +19,25 @@ class FEContentModel extends Model
|
|||||||
"is_active",
|
"is_active",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||||
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||||
|
|
||||||
|
protected function checkAndADDCreatedByValue(array $data)
|
||||||
|
{
|
||||||
|
if (empty($data['data']['created_by'])) {
|
||||||
|
$data['data']['created_by'] = get_session_userid();
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
||||||
|
{
|
||||||
|
if (empty($data['data']['updated_by'])) {
|
||||||
|
$data['data']['updated_by'] = get_session_userid();
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,6 +66,7 @@ class PartnerPosModel extends Model
|
|||||||
'aadhar',
|
'aadhar',
|
||||||
'aadhar_file_name',
|
'aadhar_file_name',
|
||||||
'is_active',
|
'is_active',
|
||||||
|
'updated_on',
|
||||||
'created_by',
|
'created_by',
|
||||||
'updated_by',
|
'updated_by',
|
||||||
'manager_id',
|
'manager_id',
|
||||||
@ -111,11 +112,9 @@ class PartnerPosModel extends Model
|
|||||||
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
protected $beforeInsert = ["checkAndADDCreatedByValue"];
|
||||||
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
|
||||||
|
|
||||||
protected function checkAndADDCreatedByValue(array $data)
|
protected function checkAndADDCreatedByValue(array $data)
|
||||||
{
|
{
|
||||||
// Check if 'updated_by' value is null or empty
|
|
||||||
if (empty($data['data']['created_by'])) {
|
if (empty($data['data']['created_by'])) {
|
||||||
// Set 'updated_by' value to the current session user ID
|
|
||||||
$data['data']['created_by'] = get_session_userid();
|
$data['data']['created_by'] = get_session_userid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,12 +123,12 @@ class PartnerPosModel extends Model
|
|||||||
|
|
||||||
protected function checkAndUpdateUpdatedByValue(array $data)
|
protected function checkAndUpdateUpdatedByValue(array $data)
|
||||||
{
|
{
|
||||||
// Check if 'updated_by' value is null or empty
|
|
||||||
if (empty($data['data']['updated_by'])) {
|
if (empty($data['data']['updated_by'])) {
|
||||||
// Set 'updated_by' value to the current session user ID
|
|
||||||
$data['data']['updated_by'] = get_session_userid();
|
$data['data']['updated_by'] = get_session_userid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$data['data']['updated_on'] = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -249,9 +249,6 @@
|
|||||||
let formData;
|
let formData;
|
||||||
|
|
||||||
if (type === 'submit') {
|
if (type === 'submit') {
|
||||||
if (editor) {
|
|
||||||
$('#answer').val(editor.value);
|
|
||||||
}
|
|
||||||
// CREATE FORMDATA FROM FORM
|
// CREATE FORMDATA FROM FORM
|
||||||
formData = new FormData(form);
|
formData = new FormData(form);
|
||||||
formData.set('return_type', 'web');
|
formData.set('return_type', 'web');
|
||||||
|
|||||||
@ -18,28 +18,28 @@
|
|||||||
<th class="font-weight-medium">Type</th>
|
<th class="font-weight-medium">Type</th>
|
||||||
<th class="font-weight-medium">Content Section</th>
|
<th class="font-weight-medium">Content Section</th>
|
||||||
<th class="font-weight-medium">Heading</th>
|
<th class="font-weight-medium">Heading</th>
|
||||||
<!-- <th class="font-weight-medium">Status</th> -->
|
<th class="font-weight-medium">Status</th>
|
||||||
<th class="font-weight-medium">Action</th>
|
<th class="font-weight-medium">Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php if(isset($test)) { $slno = 1; ?>
|
<?php if(isset($data['fe_list'])) { $slno = 1; ?>
|
||||||
<?php foreach($test as $index => $row) { ?>
|
<?php foreach($data['fe_list'] as $index => $row) { ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-center"><?= $slno++; ?></td>
|
<td class="text-center"><?= $slno++; ?></td>
|
||||||
<td><?= $row['type']; ?></td>
|
<td><?= $row['type']; ?></td>
|
||||||
<td><?= $row['content_section']; ?></td>
|
<td><?= $row['content_section']; ?></td>
|
||||||
<td><?= $row['heading']; ?></td>
|
<td><?= $row['heading']; ?></td>
|
||||||
<!-- <td>
|
<td>
|
||||||
<span class="<?php if($row['is_active'] == 1){ echo 'badge badge-primary'; }else{ echo 'badge badge-danger'; } ?>">
|
<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'; } ?>
|
<?php if($row['is_active'] == 1){ echo 'Active'; }else{ echo 'In-Active'; } ?>
|
||||||
</span>
|
</span>
|
||||||
</td> -->
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group dropdown" style="position: relative !important;left:0px !important;top:0px !important;">
|
<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>
|
<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;">
|
<div class="dropdown-menu dropdown-menu-right" style="cursor: pointer;">
|
||||||
<a class="dropdown-item" data-id="<?= $row['id']; ?>" onclick="handleSaveEditAndDelete('edit', this)">
|
<a class="dropdown-item" data-status="<?= $row['is_active']; ?>" data-id="<?= $row['id']; ?>" onclick="handleSaveEditAndDelete('edit', this)">
|
||||||
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
|
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
|
||||||
</a>
|
</a>
|
||||||
<?php if ($row['is_active'] == 1): ?>
|
<?php if ($row['is_active'] == 1): ?>
|
||||||
@ -53,9 +53,9 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<tr>
|
<!-- <tr>
|
||||||
<td colspan="3" class="text-center">No data available</td>
|
<td colspan="6" class="text-center">No data available</td>
|
||||||
</tr>
|
</tr> -->
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
@ -74,8 +74,8 @@
|
|||||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body p-4">
|
<div class="modal-body p-4">
|
||||||
<form id="frontEndContentForm" enctype="multipart/form-data">
|
<form class="parsley-examples" id="frontEndContentForm" enctype="multipart/form-data">
|
||||||
<input type="hidden" name="pk" id="fe_id"/>
|
<input type="hidden" name="fe_id" id="fe_id"/>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
@ -91,16 +91,32 @@
|
|||||||
<input type="text" class="form-control" id="heading" name="heading" placeholder="Enter Heading" required>
|
<input type="text" class="form-control" id="heading" name="heading" placeholder="Enter Heading" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-md-12">
|
||||||
|
<label for="content">Content<span class="text-danger">*</span></label>
|
||||||
|
<textarea id="content" name="content" class="form-control content" rows="5">
|
||||||
|
<!-- <h5>Hello {USER_NAME}, </h5>
|
||||||
|
<p>We create simple, flat & responsive custom mail template.</p>
|
||||||
|
<p>Please, write text here!</p> -->
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<div class="form-group col-md-12">
|
||||||
|
<label for="notes">Notes<span class="text-danger">*</span></label>
|
||||||
|
<textarea id="notes" name="notes" class="form-control notes" rows="5">
|
||||||
|
<!-- <h5>Hello {USER_NAME}, </h5>
|
||||||
|
<p>We create simple, flat & responsive custom mail template.</p>
|
||||||
|
<p>Please, write text here!</p> -->
|
||||||
|
</textarea>
|
||||||
|
</div>
|
||||||
|
</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">
|
<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>
|
<button type="submit" class="btn app-btn-secondary" id="btnSubmit">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -110,7 +126,46 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
var table;
|
var table;
|
||||||
|
let content_editor;
|
||||||
|
let notes_editor;
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
|
const editorConfig = {
|
||||||
|
buttons: [
|
||||||
|
"undo", "redo", "|",
|
||||||
|
"paragraph",
|
||||||
|
"bold", "italic", "strikethrough", "|",
|
||||||
|
"superscript", "subscript", "|",
|
||||||
|
"ul", "ol", "|",
|
||||||
|
"outdent", "indent", "|",
|
||||||
|
"blockquote", "table", "|",
|
||||||
|
"align", "fontsize", "|",
|
||||||
|
"source"
|
||||||
|
],
|
||||||
|
controls: {
|
||||||
|
paragraph: {
|
||||||
|
list: {
|
||||||
|
p: "Normal",
|
||||||
|
h1: "Heading 1",
|
||||||
|
h2: "Heading 2",
|
||||||
|
h3: "Heading 3",
|
||||||
|
h4: "Heading 4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fontsize: ["8px", "10px", "12px", "14px", "16px", "18px", "20px", "22px", "24px"], // Font sizes in pixels
|
||||||
|
showPlaceholder: false,
|
||||||
|
toolbarButtonSize: "small",
|
||||||
|
toolbarAdaptive: false,
|
||||||
|
saveHeightInStorage: true,
|
||||||
|
minHeight: 400,
|
||||||
|
height: 400, // Optional fixed height
|
||||||
|
defaultMode: "1", // Start in WYSIWYG mode
|
||||||
|
enableDragAndDropFileToEditor: true, // Allow file uploads via drag and drop
|
||||||
|
placeholder: "Start typing here...", // Optional placeholder text
|
||||||
|
};
|
||||||
|
content_editor = Jodit.make("#content", editorConfig);
|
||||||
|
notes_editor = Jodit.make("#notes", editorConfig);
|
||||||
|
|
||||||
var ticketsTable = $('#user-table');
|
var ticketsTable = $('#user-table');
|
||||||
ticketsTable.DataTable({
|
ticketsTable.DataTable({
|
||||||
scrollX: true,
|
scrollX: true,
|
||||||
@ -126,7 +181,7 @@
|
|||||||
text: 'Add',
|
text: 'Add',
|
||||||
className: 'btn app-btn-primary mr-2',
|
className: 'btn app-btn-primary mr-2',
|
||||||
action: function(e, dt, node, config) {
|
action: function(e, dt, node, config) {
|
||||||
openModal()
|
resetValues();openModal();// $('#btnSubmit').removeClass('d-none');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -164,9 +219,7 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.close').click(function(){
|
$('.close').click(function(){ resetValues(); })
|
||||||
resetValues()
|
|
||||||
})
|
|
||||||
|
|
||||||
function openModal(){
|
function openModal(){
|
||||||
var myModal = new bootstrap.Modal(document.getElementById('con-close-modal'));
|
var myModal = new bootstrap.Modal(document.getElementById('con-close-modal'));
|
||||||
@ -233,87 +286,147 @@
|
|||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
function handleSaveEditAndDelete(type = 'submit', el = null) {
|
function handleSaveEditAndDelete(type = 'submit', el = null) {
|
||||||
|
|
||||||
let url = '<?= base_url('util/nhanceBranchMaster') ?>';
|
let form = document.getElementById('frontEndContentForm');
|
||||||
|
let url = '<?= base_url('frontend_content') ?>';
|
||||||
let method = "POST";
|
let method = "POST";
|
||||||
let requestData = {};
|
let fe_id = el ? $(el).data('id') : null;
|
||||||
|
let fe_status = 1;
|
||||||
|
let formData;
|
||||||
|
|
||||||
let pk = null;
|
|
||||||
|
|
||||||
// If element is passed (from edit/remove button), get its data-id
|
if (type === 'submit') {
|
||||||
if (el) { pk = $(el).data('id'); }
|
// CREATE FORMDATA FROM FORM
|
||||||
|
formData = new FormData(form);
|
||||||
requestData.pk = pk;
|
} else if (type == 'edit') {
|
||||||
|
|
||||||
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";
|
method = "GET";
|
||||||
|
if (fe_id) url += '?fe_id=' + fe_id ;
|
||||||
|
fe_status = el ? $(el).data('status') : 1;
|
||||||
|
// $('#btnSubmit').addClass('d-none');
|
||||||
|
// let name_text = fe_status ? "Edit" : "View";
|
||||||
$('#modalLabel').text('Edit Front End Content');
|
$('#modalLabel').text('Edit Front End Content');
|
||||||
$('#frontEndContentForm')[0].reset();
|
$('#frontEndContentForm')[0].reset();
|
||||||
|
|
||||||
|
} else if (type == 'remove') {
|
||||||
|
method = "DELETE";
|
||||||
|
if (fe_id) url += '?fe_id=' + fe_id ;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("type", type)
|
// if (typeof fe_status !== 'undefined' && fe_status == 1) {
|
||||||
console.log("url", url)
|
// // $('#btnSubmit').addClass('d-none');
|
||||||
console.log("method", method)
|
// return; // optional: stop further actions
|
||||||
console.log("requestData", requestData)
|
// }else{
|
||||||
|
// // $('#btnSubmit').removeClass('d-none');
|
||||||
|
// }
|
||||||
|
|
||||||
$('.loader').fadeIn();
|
$('.loader, .loader-mask').fadeIn();
|
||||||
$('.loader-mask').fadeIn();
|
|
||||||
|
|
||||||
// Send AJAX request
|
$.ajax({
|
||||||
sendAjaxRequestForGlobal(url, method, requestData, function(response) {
|
url: url,
|
||||||
|
type: method,
|
||||||
console.log('Data fetched successfully:', response);
|
data: (type === 'submit') ? formData : null,
|
||||||
|
processData: false,
|
||||||
if (response.status) {
|
contentType: false,
|
||||||
if(type == 'edit'){
|
dataType: 'json',
|
||||||
appendEditData(response.data);
|
success: function (response) {
|
||||||
} else if(type == 'remove'){
|
console.log('Response:', response);
|
||||||
toastr.success(response.message, 'Success');
|
if (response.status === 'success' || response.status === true) {
|
||||||
if(el) $(el).closest('tr').remove();
|
if (type == 'edit') {
|
||||||
window.location.reload();
|
let record = response.data.fe_list[0]; // single record
|
||||||
} else if(type == 'submit'){
|
appendEditData(record);
|
||||||
toastr.success(response.message, 'Success');
|
} else if(type == 'remove'){
|
||||||
var myModal = new bootstrap.Modal(document.getElementById('con-close-modal'));
|
toastr.success(response.message, 'Success');
|
||||||
myModal.hide();
|
// if(el) $(el).closest('tr').remove();
|
||||||
$('#frontEndContentForm')[0].reset();
|
window.location.reload();
|
||||||
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');
|
||||||
}
|
}
|
||||||
} else {
|
$('.loader, .loader-mask').fadeOut();
|
||||||
toastr.warning(response.message, 'Warning');
|
},
|
||||||
|
error: function () {
|
||||||
|
$('.loader, .loader-mask').fadeOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
$('.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(){
|
function resetValues(){
|
||||||
$('#modalLabel').text('Add Front End Content');
|
$('#modalLabel').text('Add Front End Content');
|
||||||
$('#frontEndContentForm')[0].reset();
|
$('#frontEndContentForm')[0].reset();
|
||||||
|
if (typeof content_editor !== 'undefined') {
|
||||||
|
content_editor.value = '';
|
||||||
|
}
|
||||||
|
if (typeof notes_editor !== 'undefined') {
|
||||||
|
notes_editor.value = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendEditData(data){
|
function appendEditData(data) {
|
||||||
$('#fe_id').val(data[0]['id']);
|
$('#frontEndContentForm')[0].reset();
|
||||||
$('#branch_name').val(data[0]['branch_name']);
|
$('#fe_id').val(data.id);
|
||||||
openModal()
|
$('#type').val(data.type);
|
||||||
|
$('#content_section').val(data.content_section);
|
||||||
|
$('#heading').val(data.heading);
|
||||||
|
// $('#content').val(data.content);
|
||||||
|
// $('#notes').val(data.notes);
|
||||||
|
if (content_editor) {
|
||||||
|
content_editor.value = data.content || '';
|
||||||
|
}
|
||||||
|
if (notes_editor) {
|
||||||
|
notes_editor.value = data.notes || '';
|
||||||
|
}
|
||||||
|
openModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#frontEndContentForm').on('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const form = this;
|
||||||
|
|
||||||
|
// HTML5 built-in validation
|
||||||
|
if (!form.checkValidity()) {
|
||||||
|
form.reportValidity(); // shows required/pattern tooltips
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Content validation
|
||||||
|
if (typeof content_editor !== 'undefined') {
|
||||||
|
if (isEditorEmpty(content_editor.value)) {
|
||||||
|
toastr.warning("Content is required", 'Warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notes validation
|
||||||
|
if (typeof notes_editor !== 'undefined') {
|
||||||
|
if (isEditorEmpty(notes_editor.value)) {
|
||||||
|
toastr.warning("Notes is required", 'Warning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If valid, submit via AJAX
|
||||||
|
handleSaveEditAndDelete('submit');
|
||||||
|
});
|
||||||
|
|
||||||
|
function isEditorEmpty(html) {
|
||||||
|
if (!html) return true;
|
||||||
|
|
||||||
|
// Remove tags, , and trim
|
||||||
|
const text = html
|
||||||
|
.replace(/<[^>]*>/g, '')
|
||||||
|
.replace(/ /g, '')
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
return text.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -386,7 +386,7 @@
|
|||||||
$('#con-close-modal').one('shown.bs.modal', function () {
|
$('#con-close-modal').one('shown.bs.modal', function () {
|
||||||
$('#manager_id').val(data.manager_id).trigger('change');
|
$('#manager_id').val(data.manager_id).trigger('change');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$('#aadhar').on('input', function () {
|
$('#aadhar').on('input', function () {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user