Task 10121 | fix: поправили прайсы цен для карт, которые некорректно выводятся при заполнении из админки

This commit is contained in:
Боевой сайт - fakel
2025-11-21 21:11:51 +03:00
parent 21562852ca
commit 2ac2340779
57 changed files with 7935 additions and 14019 deletions

View File

@@ -91,6 +91,7 @@ document.addEventListener('DOMContentLoaded', function() {
});
}
},
getLocalizedUrl(path) {
const htmlLang = document.documentElement.lang;
const currentLang = window.pll_current_language || this.getCurrentLangFromUrl();
@@ -110,6 +111,11 @@ document.addEventListener('DOMContentLoaded', function() {
return pathParts.length > 0 && languageCodes.includes(pathParts[0]) ? pathParts[0] : null;
},
getCurrentBranch() {
const isGymPage = window.location.pathname.includes('/gym/');
return isGymPage ? 'gym' : 'main';
},
open(modalName, params = {}) {
const template = document.getElementById(`modal-template-${modalName}`);
if (!template) return;
@@ -156,6 +162,22 @@ document.addEventListener('DOMContentLoaded', function() {
});
}
const attrElements = this.content.querySelectorAll('[data-inject="card-attr"]');
attrElements.forEach(el => {
const parentDiv = el.closest('div');
if (params.cardAttr && params.cardAttr.trim() !== '') {
el.textContent = params.cardAttr;
if (parentDiv) {
parentDiv.style.display = 'flex';
}
} else {
if (parentDiv) {
parentDiv.style.display = 'none';
}
}
});
if (params.cardTime) {
this.fillTimeInfo(JSON.parse(params.cardTime));
}
@@ -182,30 +204,46 @@ document.addEventListener('DOMContentLoaded', function() {
},
fillPrices(prices, cardTitle, cardId) {
Object.keys(prices).forEach(period => {
const price = prices[period];
if (!price.full || !price.day) return;
const priceOptions = this.content.querySelectorAll('.price-option');
let firstAvailableOption = null;
let firstAvailablePeriod = null;
let firstAvailablePrice = null;
const fullElements = this.content.querySelectorAll(`[data-inject="price-${period.replace('_', '-')}-full"]`);
const dayElements = this.content.querySelectorAll(`[data-inject="price-${period.replace('_', '-')}-day"]`);
priceOptions.forEach(option => {
const period = option.dataset.period;
const price = prices[period];
if (!price || !price.full || !price.day) {
option.classList.add('hidden');
return;
}
option.classList.remove('hidden');
const fullElements = option.querySelectorAll(`[data-inject="price-${period.replace('_', '-')}-full"]`);
const dayElements = option.querySelectorAll(`[data-inject="price-${period.replace('_', '-')}-day"]`);
fullElements.forEach(el => el.textContent = price.full);
dayElements.forEach(el => el.textContent = price.day);
});
this.content.querySelectorAll('.price-option').forEach(option => {
if (!firstAvailableOption) {
firstAvailableOption = option;
firstAvailablePeriod = period;
firstAvailablePrice = price;
}
option.addEventListener('click', () => {
const period = option.dataset.period;
const price = prices[period];
if (price) {
this.selectPrice(option, period, price, cardTitle, cardId);
}
this.selectPrice(option, period, price, cardTitle, cardId);
});
});
const firstOption = this.content.querySelector('.price-option');
if (firstOption && prices['1_month']) {
this.selectPrice(firstOption, '1_month', prices['1_month'], cardTitle, cardId);
if (firstAvailableOption) {
this.selectPrice(firstAvailableOption, firstAvailablePeriod, firstAvailablePrice, cardTitle, cardId);
} else {
const priceContainer = this.content.querySelector('#price-options');
if (priceContainer) {
priceContainer.innerHTML = '<p class="text-center text-gray-500">Цены временно недоступны</p>';
}
}
},
@@ -259,13 +297,6 @@ document.addEventListener('DOMContentLoaded', function() {
this.overlay.classList.remove('opacity-0', 'invisible');
this.overlay.classList.add('opacity-100', 'visible');
setTimeout(() => {
if (this.container) {
this.container.classList.remove('scale-90');
this.container.classList.add('scale-100');
}
}, 10);
setTimeout(() => {
if (this.closeBtn) this.closeBtn.focus();
}, 350);
@@ -274,6 +305,13 @@ document.addEventListener('DOMContentLoaded', function() {
close() {
if (this.modalStack.length === 0) return;
const currentModal = this.modalStack[this.modalStack.length - 1];
if (currentModal.name === 'welcome-branch') {
const currentBranch = this.getCurrentBranch();
localStorage.setItem('branch_choice_made', currentBranch);
}
this.modalStack.pop();
if (this.modalStack.length > 0) {
@@ -288,9 +326,6 @@ document.addEventListener('DOMContentLoaded', function() {
hide() {
if (!this.container || !this.overlay) return;
this.container.classList.remove('scale-100');
this.container.classList.add('scale-90');
this.overlay.classList.remove('opacity-100', 'visible');
this.overlay.classList.add('opacity-0', 'invisible');
@@ -303,4 +338,71 @@ document.addEventListener('DOMContentLoaded', function() {
};
ModalSystem.init();
function checkWelcomeModal() {
const isHomePage = window.location.pathname === '/' || window.location.pathname === '';
const isGymPage = window.location.pathname.includes('/gym/');
const hasChoiceMade = localStorage.getItem('branch_choice_made');
if ((isHomePage || isGymPage) && !hasChoiceMade) {
setTimeout(function() {
ModalSystem.open('welcome-branch');
}, 1000);
}
}
document.addEventListener('click', function(e) {
if (e.target.closest('.branch-card')) {
e.preventDefault();
const branchCard = e.target.closest('.branch-card');
const branch = branchCard.dataset.branch;
if (!branch) return;
localStorage.setItem('branch_choice_made', branch);
branchCard.classList.add('selecting');
const button = branchCard.querySelector('button');
if (button) {
button.querySelector('span').textContent = 'Переходим...';
}
setTimeout(function() {
const isHomePage = window.location.pathname === '/' || window.location.pathname === '';
const isGymPage = window.location.pathname.includes('/gym/');
if (branch === 'gym') {
if (isGymPage) {
ModalSystem.close();
} else {
window.location.href = '/gym/';
}
} else {
if (isHomePage) {
ModalSystem.close();
} else {
window.location.href = '/';
}
}
}, 500);
}
});
document.addEventListener('click', function(e) {
const branchCard = e.target.closest('.branch-card');
if (branchCard && !e.target.closest('.select-branch-btn')) {
document.querySelectorAll('.branch-card').forEach(function(card) {
card.classList.remove('selected');
});
branchCard.classList.add('selected');
}
});
checkWelcomeModal();
window.resetBranchChoice = function() {
localStorage.removeItem('branch_choice_made');
};
});