implemented step 09 by Gemini
- added 3. step of wizard with smart questions
This commit is contained in:
@ -88,6 +88,16 @@ const App = {
|
||||
document.getElementById('contact-facebook').value = wd.contact.socials?.facebook || '';
|
||||
document.getElementById('contact-instagram').value = wd.contact.socials?.instagram || '';
|
||||
}
|
||||
|
||||
// Step 3
|
||||
if (wd.services && wd.services.items) {
|
||||
const list = document.getElementById('services-list');
|
||||
list.innerHTML = '';
|
||||
wd.services.items.forEach(item => this.addServiceItem(item));
|
||||
document.getElementById('pricing-note').value = wd.services.pricing_note || '';
|
||||
} else {
|
||||
this.addServiceItem();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -174,6 +184,9 @@ const App = {
|
||||
el.addEventListener('change', () => this.updateUI());
|
||||
}
|
||||
});
|
||||
|
||||
// Step 3 events
|
||||
document.getElementById('btn-add-service').addEventListener('click', () => this.addServiceItem());
|
||||
},
|
||||
|
||||
renderCategories() {
|
||||
@ -209,6 +222,7 @@ const App = {
|
||||
|
||||
this.renderCategories();
|
||||
this.renderSubcategories(categoryId);
|
||||
this.renderSmartQuestions(categoryId);
|
||||
|
||||
document.getElementById('subcategory-container').classList.remove('hidden');
|
||||
|
||||
@ -241,6 +255,92 @@ const App = {
|
||||
});
|
||||
},
|
||||
|
||||
addServiceItem(data = {}) {
|
||||
const container = document.getElementById('services-list');
|
||||
const itemDiv = document.createElement('div');
|
||||
itemDiv.className = 'service-item';
|
||||
|
||||
itemDiv.innerHTML = `
|
||||
<div class="service-item-header">
|
||||
<span class="service-number">Služba</span>
|
||||
<button class="btn-remove-service" title="Odstrániť">×</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Názov služby *</label>
|
||||
<input type="text" class="service-name" placeholder="Napr. Klasická masáž" value="${data.name || ''}" required>
|
||||
</div>
|
||||
<div class="form-grid">
|
||||
<div class="form-group">
|
||||
<label>Cena od (€)</label>
|
||||
<input type="text" class="service-price" placeholder="25" value="${data.price_from || ''}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Stručný popis</label>
|
||||
<input type="text" class="service-desc" placeholder="Trvanie 45 minút..." value="${data.description || ''}">
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
itemDiv.querySelector('.btn-remove-service').addEventListener('click', () => {
|
||||
if (container.querySelectorAll('.service-item').length > 1) {
|
||||
itemDiv.remove();
|
||||
} else {
|
||||
alert('Zadajte aspoň jednu službu.');
|
||||
}
|
||||
});
|
||||
|
||||
container.appendChild(itemDiv);
|
||||
},
|
||||
|
||||
renderSmartQuestions(categoryId) {
|
||||
const container = document.getElementById('smart-questions-list');
|
||||
container.innerHTML = '';
|
||||
|
||||
const category = this.state.categories.find(c => c.id === categoryId);
|
||||
if (!category || !category.smart_questions) {
|
||||
document.getElementById('smart-questions-container').classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('smart-questions-container').classList.remove('hidden');
|
||||
|
||||
category.smart_questions.forEach(q => {
|
||||
const qDiv = document.createElement('div');
|
||||
qDiv.className = 'smart-question-item';
|
||||
|
||||
if (q.type === 'boolean') {
|
||||
qDiv.innerHTML = `
|
||||
<div class="checkbox-group">
|
||||
<input type="checkbox" id="sq-${q.id}" data-id="${q.id}">
|
||||
<label for="sq-${q.id}">${q.name}</label>
|
||||
</div>
|
||||
`;
|
||||
} else {
|
||||
qDiv.innerHTML = `
|
||||
<div class="form-group">
|
||||
<label for="sq-${q.id}">${q.name}</label>
|
||||
<input type="text" id="sq-${q.id}" data-id="${q.id}" placeholder="Vaša odpoveď...">
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
container.appendChild(qDiv);
|
||||
|
||||
// Apply existing answer if available
|
||||
if (this.state.project && this.state.project.wizard_data.smart_answers) {
|
||||
const answer = this.state.project.wizard_data.smart_answers[q.id];
|
||||
if (answer !== undefined) {
|
||||
const input = qDiv.querySelector(`#sq-${q.id}`);
|
||||
if (q.type === 'boolean') {
|
||||
input.checked = !!answer;
|
||||
} else {
|
||||
input.value = answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
showStep(n) {
|
||||
const steps = document.querySelectorAll('.step');
|
||||
steps.forEach(step => step.classList.remove('active'));
|
||||
@ -324,6 +424,45 @@ const App = {
|
||||
alert('Nepodarilo sa uložiť dáta: ' + error.message);
|
||||
return;
|
||||
}
|
||||
} else if (this.state.currentStep === 3) {
|
||||
const serviceItems = [];
|
||||
document.querySelectorAll('.service-item').forEach(item => {
|
||||
const name = item.querySelector('.service-name').value;
|
||||
if (name) {
|
||||
serviceItems.push({
|
||||
name: name,
|
||||
price_from: item.querySelector('.service-price').value,
|
||||
description: item.querySelector('.service-desc').value
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const smartAnswers = {};
|
||||
document.querySelectorAll('.smart-question-item input').forEach(input => {
|
||||
const id = input.getAttribute('data-id');
|
||||
if (input.type === 'checkbox') {
|
||||
smartAnswers[id] = input.checked;
|
||||
} else {
|
||||
smartAnswers[id] = input.value;
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
await this.apiCall('saveStep', {
|
||||
step: 3,
|
||||
data: {
|
||||
services: {
|
||||
items: serviceItems,
|
||||
pricing_note: document.getElementById('pricing-note').value
|
||||
},
|
||||
smart_answers: smartAnswers
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Save step 3 failed:', error);
|
||||
alert('Nepodarilo sa uložiť dáta: ' + error.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.state.currentStep < this.state.totalSteps) {
|
||||
|
||||
Reference in New Issue
Block a user