Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f28a9e40c | ||
|
|
7762c9f308 |
+34
-7
@@ -921,9 +921,6 @@ n .btn-secondary {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we have question responses
|
|
||||||
const hasResponses = Object.keys(createSurveyResponses).length > 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/surveys', {
|
const response = await fetch('/api/surveys', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -932,23 +929,32 @@ n .btn-secondary {
|
|||||||
name,
|
name,
|
||||||
client_name: clientName,
|
client_name: clientName,
|
||||||
site_name: siteName,
|
site_name: siteName,
|
||||||
description,
|
description
|
||||||
responses: hasResponses ? createSurveyResponses : undefined
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json();
|
||||||
|
throw new Error(errorData.error || 'Failed to create survey');
|
||||||
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
// Clear form
|
||||||
document.getElementById('surveyName').value = '';
|
document.getElementById('surveyName').value = '';
|
||||||
document.getElementById('clientName').value = '';
|
document.getElementById('clientName').value = '';
|
||||||
document.getElementById('siteName').value = '';
|
document.getElementById('siteName').value = '';
|
||||||
document.getElementById('surveyDescription').value = '';
|
document.getElementById('surveyDescription').value = '';
|
||||||
|
|
||||||
await loadSurveys();
|
await loadSurveys();
|
||||||
loadSurvey(data.survey.id);
|
|
||||||
|
// Switch to surveys tab to show the new survey
|
||||||
|
switchTab('surveys');
|
||||||
|
alert('Survey created successfully! Click on it to take the survey.');
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert('Failed to create survey');
|
console.error('Error creating survey:', e);
|
||||||
|
alert('Failed to create survey: ' + e.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1561,7 +1567,28 @@ function confirmClearAll() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function clearAllSurveys() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/surveys', {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.success) {
|
||||||
|
showNotification('All surveys deleted successfully', 'success');
|
||||||
|
loadSurveys();
|
||||||
|
currentSurveyId = null;
|
||||||
|
currentSurvey = null;
|
||||||
|
document.getElementById('takeSurveyTab').style.display = 'none';
|
||||||
|
document.getElementById('analyzeTab').style.display = 'none';
|
||||||
|
} else {
|
||||||
|
showNotification(data.error || 'Failed to clear surveys', 'error');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error clearing surveys:', e);
|
||||||
|
showNotification('Failed to clear surveys', 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Notification helper
|
// Notification helper
|
||||||
function showNotification(message, type = 'info') {
|
function showNotification(message, type = 'info') {
|
||||||
|
|||||||
Reference in New Issue
Block a user