remove button and logo issue

This commit is contained in:
heama 2024-03-19 10:56:34 +05:30
parent acf0069305
commit 7cdda4a7ef
2 changed files with 101 additions and 37 deletions

View File

@ -76,7 +76,7 @@ class Business extends BaseController
}
else{
$details = $smodel->where(['business_id' => $session_bid, 'isactive' => 1])->first();
// print_r($session_bid);die;
}
// echo json_decode($details);die;
$data['details'] = $details;
@ -168,9 +168,9 @@ class Business extends BaseController
} else {
// It's an update operation
if ($session_role === 'sadmin') {
$isactive = $this->request->getPost('bcheckbox');
$data['isactive'] = ($isactive == 'on') ? 1 : 0;
}
$data['isactive'] = 1;
$data['updated_by'] = $session_uid;
$BusinessModel->update($business_id, $data);
$businessId = $business_id;
@ -178,6 +178,7 @@ class Business extends BaseController
$BusinessModel->updateDonationData($businessId, $selectedDonations);
}
}
// ... existing code ...
@ -318,11 +319,13 @@ if (empty($setting_id)) {
// Redirect based on user role
if ($session_role === 'sadmin') {
if (empty($business_id)) {
// Redirect to the organization list after inserting a new organization
return redirect()->route('org_list');
}
} else {
return redirect()->route('org_list');
}
// Redirect based on user role
if ($session_role !== 'sadmin') {
session()->setFlashdata('success', 'User has been updated successfully.');
// Assuming 'index' is the route name for your index page
return redirect()->to(base_url("new_org/{$business_id}"));

View File

@ -227,6 +227,7 @@
<span class="toggle-icon" onclick="toggleSettings('branch-settings')"></span>
</h4>
<br>
<div id="branchesContainer">
<div class="after-shipping-addr-add-more" id="branch-settings" style="display: none;">
<?php if (empty($branches)) : ?>
@ -262,7 +263,9 @@
<?php else : ?>
<!-- Display branch fields for each branch in the $branches array -->
<?php foreach ($branches as $branch) : ?>
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-6">
@ -296,8 +299,8 @@
<?php endif; ?>
<!-- Add more branches when clicking the "Add More Branches" button -->
<div class="form-group col-md-12 text-right m-b-0">
<a class="btn btn-success waves-effect waves-light mr-1 add-brnach-details">+ Add More Branches </a>
<a class="btn btn-danger waves-effect waves-light mr-1 remove-brnach-details">- Remove </a>
<a class="btn btn-success waves-effect waves-light mr-1 add-brnach-details"id="addBranchButton">+ Add More Branches </a>
<!-- <a class="btn btn-danger waves-effect waves-light mr-1 remove-brnach-details">- Remove </a> -->
</div>
</div>
@ -490,35 +493,93 @@ function validateImage(input) {
}
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
function addBranch(container) {
const branchSection = document.querySelector('.after-shipping-addr-add-more');
const clonedBranch = branchSection.cloneNode(true);
// Clear values in the cloned branch
clonedBranch.querySelectorAll('input, textarea').forEach(input => input.value = '');
container.parentNode.insertBefore(clonedBranch, container.nextSibling);
}
// Add more branches when clicking the "Add More Branches" button
document.addEventListener('click', function (event) {
if (event.target.classList.contains('add-brnach-details')) {
event.preventDefault();
const container = event.target.closest('.after-shipping-addr-add-more');
addBranch(container);
}
});
// Remove a branch when clicking the "Remove" button
document.addEventListener('click', function (event) {
if (event.target.classList.contains('remove-brnach-details')) {
event.preventDefault();
event.target.closest('.after-shipping-addr-add-more').remove();
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('addBranchButton').addEventListener('click', function () {
addBranch();
});
});
function addBranch(branchData) {
var html = '';
var i = document.querySelectorAll('.after-shipping-addr-add-more').length + 1; // Get the count of existing branches and increment
html += '<div class="after-shipping-addr-add-more" id="branch-settings-' + i + '">';
html += '<div class="form-group">';
html += '<div class="form-row">';
html += '<div class="form-group col-md-6">';
html += '<label for="branchname' + i + '" class="col-form-label">Branch Name<span class="text-danger"> </span></label>';
html += '<input type="text" class="form-control" id="branchname' + i + '" name="branchname[]" placeholder="Branch Name" required value="' + (branchData && branchData.branch_name ? branchData.branch_name : '') + '" />';
html += '<div class="invalid-feedback"> Please provide. </div>';
html += '</div>';
html += '<div class="form-group col-md-6">';
html += '<label for="branchaddress' + i + '" class="col-form-label">Branch Address<span class="text-danger"></span></label>';
html += '<input type="text" class="form-control" id="branchaddress' + i + '" name="branchaddress[]" placeholder="Address (eg: 1234 Main St)" required value="' + (branchData && branchData.address ? branchData.address : '') + '" />';
html += '<div class="invalid-feedback"> Please provide. </div>';
html += '</div>';
html += '</div>';
html += '<div class="form-row">';
html += '<div class="form-group col-md-6">';
html += '<label for="mobile_no' + i + '" class="col-form-label">Contact Person<span class="text-danger"></span></label>';
html += '<input type="number" class="form-control" id="mobile_no' + i + '" name="mobile_no[]" placeholder="Contact Person" required data-parsley-type="number" maxlength="10" value="' + (branchData && branchData.mobile_no ? branchData.mobile_no : '') + '" />';
html += '<div class="invalid-feedback"> Please provide. </div>';
html += '</div>';
html += '<div class="form-group col-md-6">';
html += '<label for="email' + i + '" class="col-form-label">Email<span class="text-danger"></span></label>';
html += '<input type="email" class="form-control" id="email' + i + '" name="email[]" placeholder="Email" required value="' + (branchData && branchData.email ? branchData.email : '') + '" />';
html += '<div class="invalid-feedback"> Please provide. </div>';
html += '</div>';
html += '</div>';
html += '<input type="hidden" name="id[]" />';
html += '<div class="form-group col-md-12 text-right m-b-0">'
html += '<button class="btn btn-success waves-effect waves-light mr-1 add-branch-button">+ Add More Branches </button>';
html += '<button class="btn btn-danger waves-effect waves-light mr-1 remove-branch-button" data-branch-id="' + i + '">Remove Branch</button>';
html += '</div>';
html += '</div>';
// Append the generated HTML to the container
document.getElementById('branchesContainer').insertAdjacentHTML('beforeend', html);
// Attach event handler to the newly added remove button
var removeButton = document.querySelector('#branch-settings-' + i + ' .remove-branch-button[data-branch-id="' + i + '"]');
removeButton.addEventListener('click', function() {
var branchId = this.getAttribute('data-branch-id');
var branchElement = document.getElementById('branch-settings-' + branchId);
if (branchElement) {
branchElement.remove();
}
});
// Attach event handler to the newly added add button
var addButton = document.querySelector('#branch-settings-' + i + ' .add-branch-button');
addButton.addEventListener('click', function() {
addBranch();
});
}
// Usage example:
<?php foreach ($branches as $branch) : ?>
addBranch(<?php echo json_encode($branch); ?>);
<?php endforeach; ?>
// Event delegation to handle removing branches
// Event delegation to handle adding and removing branches
// Event delegation to handle removing branches
// document.getElementById('branchesContainer').addEventListener('click', function (event) {
// if (event.target.classList.contains('remove-branch-button')) {
// var branchId = event.target.getAttribute('data-branch-id');
// var branchElement = document.getElementById('branch-settings-' + branchId);
// if (branchElement) {
// branchElement.remove();
// }
// }
// });
function toggleSettings(id) {
var settingsDiv = document.getElementById(id);
var titleIcon = document.querySelector("#"+id+"-title .toggle-icon");