diff --git a/modules/reviews/index.js b/modules/reviews/index.js index 0e95cbb..8c767b7 100644 --- a/modules/reviews/index.js +++ b/modules/reviews/index.js @@ -49,7 +49,7 @@ function createReview(req, res) { const { author_name, country_code, country_name, city, stars, text, review_code } = req.body; const ip = req.ip || req.connection.remoteAddress || 'unknown'; - if (!author_name || !country_code || stars === undefined || !text || !review_code) { + if (!author_name || stars === undefined || !text || !review_code) { return res.status(400).json({ error: 'Missing required fields' }); } diff --git a/modules/translations/index.js b/modules/translations/index.js index 7f3adf5..7aca60d 100644 --- a/modules/translations/index.js +++ b/modules/translations/index.js @@ -28,6 +28,8 @@ const translations = { // Review Form 'form.select_country': 'Выберите страну', 'form.select_city': 'Город (необязательно)', + 'form.another_country': 'Другая страна', + 'form.country_placeholder': 'Введите название страны', 'form.another_city': 'Другой город', 'form.city_placeholder': 'Введите название города', 'form.rating': 'Оценка', @@ -355,6 +357,8 @@ const translations = { // Review Form 'form.select_country': 'Select country', 'form.select_city': 'City (optional)', + 'form.another_country': 'Other country', + 'form.country_placeholder': 'Enter country name', 'form.another_city': 'Other city', 'form.city_placeholder': 'Enter city name', 'form.rating': 'Rating', @@ -682,6 +686,8 @@ const translations = { // Review Form 'form.select_country': 'Атәыла алхразы', 'form.select_city': 'Ақалақь (иахәҭахым)', + 'form.another_country': 'Атәыла даҽаны', + 'form.country_placeholder': 'Атәыла ахьӡ аҭазыргыла', 'form.another_city': 'Ақалақь даҽаны', 'form.city_placeholder': 'Ақалақь ахьӡ аҭазыргыла', 'form.rating': 'Ахә', diff --git a/public/index.html b/public/index.html index ad675c7..700576f 100644 --- a/public/index.html +++ b/public/index.html @@ -941,6 +941,12 @@
Выберите страну
+ + +
@@ -984,12 +990,7 @@
-
- - -
+ Код сообщается гостям на ресепшене отеля
Неверный код гостиницы
diff --git a/public/js/reviews.js b/public/js/reviews.js index e076d68..d8caafa 100644 --- a/public/js/reviews.js +++ b/public/js/reviews.js @@ -181,6 +181,11 @@ function populateCountrySelect() { otherGroup.appendChild(opt); }); select.appendChild(otherGroup); + + const otherCountryOpt = document.createElement('option'); + otherCountryOpt.value = '__other__'; + otherCountryOpt.textContent = I18n.t('form.another_country'); + select.appendChild(otherCountryOpt); } let currentCountryCode = null; @@ -194,6 +199,19 @@ function setupCountryChangeHandler() { const citySelect = document.getElementById('reviewCity'); const cityWrapper = document.getElementById('citySelectWrapper'); const otherCityGroup = document.getElementById('otherCityGroup'); + const otherCountryGroup = document.getElementById('otherCountryGroup'); + + if (countryCode === '__other__') { + otherCountryGroup.style.display = 'block'; + document.getElementById('reviewOtherCountry').focus(); + citySelect.innerHTML = ''; + citySelect.disabled = true; + cityWrapper.style.display = 'block'; + otherCityGroup.style.display = 'none'; + return; + } + + otherCountryGroup.style.display = 'none'; if (!countryCode) { citySelect.innerHTML = ''; @@ -292,28 +310,14 @@ function initStarsSlider() { updateStars(slider.value); } -function toggleCodeVisibility() { - const input = document.getElementById('reviewCode'); - const btn = document.querySelector('.toggle-code i'); - - if (input.type === 'password') { - input.type = 'text'; - btn.className = 'fas fa-eye-slash'; - } else { - input.type = 'password'; - btn.className = 'fas fa-eye'; - } -} - function resetReviewForm() { const form = document.getElementById('reviewForm'); const countryEl = document.getElementById('reviewCountry'); const cityEl = document.getElementById('reviewCity'); const cityWrapper = document.getElementById('citySelectWrapper'); const otherCityGroup = document.getElementById('otherCityGroup'); + const otherCountryGroup = document.getElementById('otherCountryGroup'); const starsSlider = document.getElementById('starsSlider'); - const codeInput = document.getElementById('reviewCode'); - const toggleBtn = document.querySelector('.toggle-code i'); const modalBody = document.getElementById('reviewModalBody'); if (form) form.reset(); @@ -321,9 +325,8 @@ function resetReviewForm() { if (cityEl) cityEl.innerHTML = ''; if (cityWrapper) cityWrapper.style.display = 'block'; if (otherCityGroup) otherCityGroup.style.display = 'none'; + if (otherCountryGroup) otherCountryGroup.style.display = 'none'; if (starsSlider) starsSlider.value = 5; - if (codeInput) codeInput.type = 'password'; - if (toggleBtn) toggleBtn.className = 'fas fa-eye'; if (form) { form.querySelectorAll('.review-error').forEach(el => el.classList.remove('show')); @@ -340,6 +343,8 @@ function resetReviewForm() { initStarsSlider(); setupReviewFormSubmit(); + setupCountryChangeHandler(); + setupCityChangeHandler(); } function getReviewCity() { @@ -353,6 +358,9 @@ function getReviewCity() { function getReviewCountry() { const select = document.getElementById('reviewCountry'); if (!select) return ''; + if (select.value === '__other__') { + return document.getElementById('reviewOtherCountry').value.trim() || ''; + } const selectedOption = select.options[select.selectedIndex]; return selectedOption ? selectedOption.textContent : ''; } @@ -366,11 +374,14 @@ function validateReviewForm() { form.querySelectorAll('.review-error').forEach(el => el.classList.remove('show')); form.querySelectorAll('.review-form-control').forEach(el => el.classList.remove('error')); - const country = document.getElementById('reviewCountry').value; - if (!country) { - document.getElementById('reviewCountry').classList.add('error'); - document.getElementById('countryError').classList.add('show'); - isValid = false; + const countryVal = document.getElementById('reviewCountry').value; + if (countryVal === '__other__') { + const otherCountry = document.getElementById('reviewOtherCountry').value.trim(); + if (!otherCountry) { + document.getElementById('reviewOtherCountry').classList.add('error'); + document.getElementById('countryError').classList.add('show'); + isValid = false; + } } const city = getReviewCity();