FEAT_REMOVE_API_LEVEL_CONTEACT : RV
This commit is contained in:
parent
d145e926e3
commit
6b3df8e8dc
@ -344,7 +344,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
|
|||||||
$routes->post('saveSIMapping','ClientController::saveSIMapping');
|
$routes->post('saveSIMapping','ClientController::saveSIMapping');
|
||||||
$routes->post('checkSIMapping','ClientController::checkSIMapping');
|
$routes->post('checkSIMapping','ClientController::checkSIMapping');
|
||||||
$routes->post('deleteMapping','ClientController::deleteMapping');
|
$routes->post('deleteMapping','ClientController::deleteMapping');
|
||||||
|
$routes->get('removeLevelContacts','ClientController::removeLevelContacts');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -138,7 +138,7 @@ class ClientController extends AdminController
|
|||||||
|
|
||||||
// Perform the query
|
// Perform the query
|
||||||
$builder = $db->table($table);
|
$builder = $db->table($table);
|
||||||
$isDuplicate = $builder->where($field, $value)->countAllResults() > 0;
|
$isDuplicate = $builder->where($field, $value)->where('is_active', 1)->countAllResults() > 0;
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return $this->response->setJSON(['isDuplicate' => $isDuplicate]);
|
return $this->response->setJSON(['isDuplicate' => $isDuplicate]);
|
||||||
@ -1034,6 +1034,39 @@ class ClientController extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeLevelContacts()
|
||||||
|
{
|
||||||
|
$id = $this->request->getGet('id');
|
||||||
|
try {
|
||||||
|
if (empty($id)) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Invalid ID provided. ID is empty',
|
||||||
|
'data' => $id
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$updated = $this->levelContactModel->update($id, ['is_active' => 0]);
|
||||||
|
|
||||||
|
if ($updated === false) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Failed to remove contact'
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->respond([
|
||||||
|
'status' => true,
|
||||||
|
'message' => 'Contact removed successfully'
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'An error occurred: ' . $e->getMessage()
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function createClientPolicy()
|
public function createClientPolicy()
|
||||||
|
|||||||
@ -509,6 +509,8 @@ $('body').on('click', '.btnBranchEdit', function() {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
|
|
||||||
|
console.log('client branch edit data response : ', res);
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
$('.loader').fadeOut();
|
$('.loader').fadeOut();
|
||||||
$('.loader-mask').delay(350).fadeOut('slow');
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
@ -582,12 +584,12 @@ $('body').on('click', '.btnBranchEdit', function() {
|
|||||||
console.log(branch_form_action);
|
console.log(branch_form_action);
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#remove_btn").click(function() {
|
// $("#remove_btn").click(function() {
|
||||||
$("#name").val('');
|
// $("#name").val('');
|
||||||
$("#email").val('');
|
// $("#email").val('');
|
||||||
$("#mobile").val('');
|
// $("#mobile").val('');
|
||||||
$("#designation").val('');
|
// $("#designation").val('');
|
||||||
})
|
// })
|
||||||
|
|
||||||
// Initialize the contact count
|
// Initialize the contact count
|
||||||
function appendContactHtml(contact = false, reset = false) {
|
function appendContactHtml(contact = false, reset = false) {
|
||||||
@ -647,20 +649,50 @@ function appendContactHtml(contact = false, reset = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function removeContact(button) {
|
function removeContact(button) {
|
||||||
|
|
||||||
var uniqueId = button.id.split("_")[0];
|
var uniqueId = button.id.split("_")[0];
|
||||||
|
console.log('uniqueId', uniqueId);
|
||||||
var contactSection = document.getElementById(uniqueId);
|
var contactSection = document.getElementById(uniqueId);
|
||||||
|
console.log('contactSection', contactSection);
|
||||||
|
|
||||||
if (contactSection) {
|
confirmActionSweertAlert("Do you want to remove this contact?", "Yes, Proceed!", "No, Cancel").then((confirmed) => {
|
||||||
contactSection.parentNode.removeChild(contactSection);
|
if(confirmed){
|
||||||
contactCount--;
|
if (contactSection) {
|
||||||
|
|
||||||
if (contactCount < 3) {
|
let unique_param = uniqueId + '_branch_table_pk';
|
||||||
var addButton = document.querySelector('.ac');
|
console.log('unique_param', unique_param);
|
||||||
if (addButton) {
|
let other_id = $('#' + unique_param).val();
|
||||||
addButton.style.display = 'block';
|
console.log('other_id', other_id);
|
||||||
|
|
||||||
|
contactSection.parentNode.removeChild(contactSection);
|
||||||
|
contactCount--;
|
||||||
|
|
||||||
|
if (contactCount < 3) {
|
||||||
|
var addButton = document.querySelector('.ac');
|
||||||
|
if (addButton) {
|
||||||
|
addButton.style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(other_id){
|
||||||
|
removeLevelContacts(other_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
$("#name").val('');
|
||||||
|
$("#email").val('');
|
||||||
|
$("#mobile").val('');
|
||||||
|
$("#designation").val('');
|
||||||
|
|
||||||
|
let first_id = $('#branch_table_pk').val();
|
||||||
|
console.log('first_id', first_id);
|
||||||
|
if(first_id){
|
||||||
|
removeLevelContacts(first_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeButtonId(id) {
|
function storeButtonId(id) {
|
||||||
@ -841,6 +873,30 @@ function getContactsData() {
|
|||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeLevelContacts(id){
|
||||||
|
|
||||||
|
let url = '<?= base_url('util/removeLevelContacts') ?>';
|
||||||
|
|
||||||
|
let requestData = {
|
||||||
|
id: id,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send AJAX request
|
||||||
|
sendAjaxRequestForGlobal(url, 'GET', requestData, function(response) {
|
||||||
|
|
||||||
|
console.log('Data fetched successfully:', response);
|
||||||
|
if (response.status == true) {
|
||||||
|
toastr.success(response.message, 'SUCCESS');
|
||||||
|
} else {
|
||||||
|
toastr.warning(response.message, 'WARNING');
|
||||||
|
}
|
||||||
|
|
||||||
|
}, function(xhr, status, error) {
|
||||||
|
console.error('Error fetching data:', error);
|
||||||
|
console.error(xhr.responseText);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user