merged main to feature split
This commit is contained in:
Vendored
+2
@@ -1,4 +1,6 @@
|
||||
function loadingbtn(){
|
||||
const loader = document.getElementById('load-arrahn');
|
||||
loader.classList.remove('d-none');
|
||||
$.notifyClose();
|
||||
// $(this).unbind("click");
|
||||
$('#background').css('display', 'block');
|
||||
|
||||
Vendored
+92
@@ -0,0 +1,92 @@
|
||||
let checked_rad = () =>{
|
||||
const radios = document.querySelectorAll('input[name="radpembayaran"]');
|
||||
// let rad_payment = document.getElementById('radpembayaran');
|
||||
let btn_payment = document.getElementById('bayarsbmt');
|
||||
let btn_payment_phone = document.getElementById('bayarsbmt-phone');
|
||||
|
||||
|
||||
if(radios.checked){
|
||||
btn_payment.disabled = false;
|
||||
btn_payment_phone.disabled = false;
|
||||
}else{
|
||||
btn_payment.disabled = true;
|
||||
btn_payment_phone.disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
const radios = document.querySelectorAll('input[name="radpembayaran"]');
|
||||
|
||||
radios.forEach((radio) => {
|
||||
radio.addEventListener('change', function () {
|
||||
let btn_payment = document.getElementById('bayarsbmt');
|
||||
let btn_payment_phone = document.getElementById('bayarsbmt-phone');
|
||||
let content1 = document.getElementById('divpkb');
|
||||
let content2 = document.getElementById('divkopkb');
|
||||
let whole_total = document.getElementById('spanjumlah');
|
||||
let whole_total_phone = document.getElementById('spanjumlah-phone');
|
||||
let inputs = document.querySelectorAll(`#div${this.value} input[type="number"]`);
|
||||
let values = Array.from(inputs).map(input => parseFloat(input.value) || 0).reduce((sum,value) => sum + value, 0);
|
||||
|
||||
if (this.checked) {
|
||||
if(this.value == 'kopkb'){
|
||||
let inputsdisabled = document.querySelectorAll(`#divpkb input:not([type="radio"])`);
|
||||
let inputenabled = document.querySelectorAll(`#divkopkb input`);
|
||||
inputsdisabled.forEach(input => {
|
||||
input.disabled = true;
|
||||
});
|
||||
inputenabled.forEach(input =>{
|
||||
input.disabled = false;
|
||||
});
|
||||
content1?.classList.add('blurred');
|
||||
content2?.classList.remove('blurred');
|
||||
btn_payment.disabled = false;
|
||||
btn_payment_phone.disabled = false;
|
||||
whole_total.innerHTML = formatter.format(values + 1);
|
||||
whole_total_phone.innerHTML = formatter.format(values + 1);
|
||||
|
||||
}else{
|
||||
let inputsdisabled = document.querySelectorAll(`#divkopkb input:not([type="radio"])`);
|
||||
let inputenabled = document.querySelectorAll(`#divpkb input`);
|
||||
|
||||
inputsdisabled.forEach(input => {
|
||||
input.disabled = true;
|
||||
});
|
||||
inputenabled.forEach(input =>{
|
||||
input.disabled = false;
|
||||
});
|
||||
content2?.classList.add('blurred');
|
||||
content1?.classList.remove('blurred');
|
||||
btn_payment.disabled = false;
|
||||
btn_payment_phone.disabled = false;
|
||||
whole_total.innerHTML = formatter.format(values + 1);
|
||||
whole_total_phone.innerHTML = formatter.format(values + 1);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
let deleteCarts = () => {
|
||||
const loader = document.getElementById('load-arrahn');
|
||||
if(loader)
|
||||
loader.classList.remove('d-none');
|
||||
|
||||
fetch('/deletecarts')
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('HTTP error ' + response.status);
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data) {
|
||||
redirect_home();
|
||||
}
|
||||
})
|
||||
.catch(error => console.error(error));
|
||||
}
|
||||
|
||||
let redirect_home = () => {
|
||||
window.location.href = redirect_home_var;
|
||||
}
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
async function fetchCartCount() {
|
||||
try {
|
||||
const response = await fetch('/showcarts-available');
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch cart count');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
let totalcount = 0;
|
||||
totalcount += (data.status_koop === 'PENDING') ? 1 : 0;
|
||||
totalcount += (data.status_pkb === 'PENDING') ? 1 : 0;
|
||||
const cartCount = totalcount || 0;
|
||||
|
||||
updateCartCount(cartCount);
|
||||
} catch (error) {
|
||||
console.error('Error fetching cart count:', error);
|
||||
updateCartCount(0);
|
||||
}
|
||||
}
|
||||
|
||||
function updateCartCount(itemCount) {
|
||||
const cartCountElement = document.getElementById('cart-count');
|
||||
const ahrefRedirect = document.getElementById('a-redirect');
|
||||
|
||||
if (itemCount > 0) {
|
||||
cartCountElement.textContent = itemCount;
|
||||
cartCountElement.classList.remove('d-none');
|
||||
} else {
|
||||
cartCountElement.textContent = '';
|
||||
cartCountElement.classList.add('d-none');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function redirectTrolley() {
|
||||
const cartCountElement = document.getElementById('cart-count');
|
||||
if(cartCountElement.textContent == 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
let form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = routetrolley;
|
||||
|
||||
let csrfInput = document.createElement('input');
|
||||
csrfInput.type = 'hidden';
|
||||
csrfInput.name = '_token';
|
||||
csrfInput.value = csrftoken;
|
||||
form.appendChild(csrfInput);
|
||||
|
||||
let redirectInput = document.createElement('input');
|
||||
redirectInput.type = 'hidden';
|
||||
redirectInput.name = 'redirect_trolley';
|
||||
redirectInput.value = 'trolley';
|
||||
form.appendChild(redirectInput);
|
||||
document.body.appendChild(form);
|
||||
|
||||
|
||||
const loader = document.getElementById('load-arrahn');
|
||||
loader.classList.remove('d-none');
|
||||
|
||||
form.submit();
|
||||
}
|
||||
|
||||
fetchCartCount();
|
||||
Reference in New Issue
Block a user