|
@@ -24,12 +24,13 @@ function addQuestion(type) {
|
|
|
|
|
|
|
|
let typeLabel = '';
|
|
let typeLabel = '';
|
|
|
const needsOptions = ['single_choice', 'multiple_choice', 'dropdown'].includes(type);
|
|
const needsOptions = ['single_choice', 'multiple_choice', 'dropdown'].includes(type);
|
|
|
|
|
+ const supportsFreeText = ['single_choice', 'multiple_choice'].includes(type);
|
|
|
|
|
|
|
|
switch(type) {
|
|
switch(type) {
|
|
|
- case 'text': typeLabel = 'Text Input'; break;
|
|
|
|
|
- case 'textarea': typeLabel = 'Text Area'; break;
|
|
|
|
|
- case 'single_choice': typeLabel = 'Single Choice'; break;
|
|
|
|
|
- case 'multiple_choice': typeLabel = 'Multiple Choice'; break;
|
|
|
|
|
|
|
+ case 'text': typeLabel = 'Textfeld'; break;
|
|
|
|
|
+ case 'textarea': typeLabel = 'Textbereich'; break;
|
|
|
|
|
+ case 'single_choice': typeLabel = 'Einzelauswahl'; break;
|
|
|
|
|
+ case 'multiple_choice': typeLabel = 'Mehrfachauswahl'; break;
|
|
|
case 'dropdown': typeLabel = 'Dropdown'; break;
|
|
case 'dropdown': typeLabel = 'Dropdown'; break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -44,18 +45,26 @@ function addQuestion(type) {
|
|
|
<button type="button" class="modal-close" style="position:relative; top:0; right:0;" onclick="removeQuestion(this)">×</button>
|
|
<button type="button" class="modal-close" style="position:relative; top:0; right:0;" onclick="removeQuestion(this)">×</button>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
<div class="form-group" style="margin-bottom:0;">
|
|
|
- <label>Question Label</label>
|
|
|
|
|
- <input type="text" class="question-label" required placeholder="Enter your question here">
|
|
|
|
|
|
|
+ <label>Fragetext</label>
|
|
|
|
|
+ <input type="text" class="question-label" required placeholder="Geben Sie hier Ihre Frage ein">
|
|
|
</div>
|
|
</div>
|
|
|
`;
|
|
`;
|
|
|
|
|
|
|
|
if (needsOptions) {
|
|
if (needsOptions) {
|
|
|
html += `
|
|
html += `
|
|
|
<div class="form-group mt-2 mb-0">
|
|
<div class="form-group mt-2 mb-0">
|
|
|
- <label>Options (one per line)</label>
|
|
|
|
|
|
|
+ <label>Optionen (eine pro Zeile)</label>
|
|
|
<textarea class="question-options" rows="3" required placeholder="Option 1\nOption 2\nOption 3"></textarea>
|
|
<textarea class="question-options" rows="3" required placeholder="Option 1\nOption 2\nOption 3"></textarea>
|
|
|
</div>
|
|
</div>
|
|
|
`;
|
|
`;
|
|
|
|
|
+ if (supportsFreeText) {
|
|
|
|
|
+ html += `
|
|
|
|
|
+ <div class="form-group mt-1 mb-0" style="flex-direction:row; align-items:center;">
|
|
|
|
|
+ <input type="checkbox" class="question-freetext" id="freetext_${id}" style="width:auto; margin-right:8px;">
|
|
|
|
|
+ <label for="freetext_${id}" style="margin:0; font-weight:normal;">Freitext erlauben ("Sonstiges")</label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ `;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
div.innerHTML = html;
|
|
div.innerHTML = html;
|
|
@@ -66,7 +75,7 @@ function removeQuestion(btn) {
|
|
|
btn.closest('.builder-item').remove();
|
|
btn.closest('.builder-item').remove();
|
|
|
const canvas = document.getElementById('builder-canvas');
|
|
const canvas = document.getElementById('builder-canvas');
|
|
|
if (canvas.children.length === 0) {
|
|
if (canvas.children.length === 0) {
|
|
|
- canvas.innerHTML = '<div class="alert alert-info" id="empty-state">No questions added yet. Use the buttons above to add one.</div>';
|
|
|
|
|
|
|
+ canvas.innerHTML = '<div class="alert alert-info" id="empty-state">Noch keine Fragen hinzugefügt. Verwenden Sie die Schaltflächen oben.</div>';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -76,7 +85,7 @@ function prepareSubmission(e) {
|
|
|
|
|
|
|
|
if (items.length === 0) {
|
|
if (items.length === 0) {
|
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
|
- alert("Please add at least one question.");
|
|
|
|
|
|
|
+ alert("Bitte fügen Sie mindestens eine Frage hinzu.");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -86,6 +95,7 @@ function prepareSubmission(e) {
|
|
|
items.forEach((item) => {
|
|
items.forEach((item) => {
|
|
|
let labelInput = item.querySelector('.question-label');
|
|
let labelInput = item.querySelector('.question-label');
|
|
|
let optionsInput = item.querySelector('.question-options');
|
|
let optionsInput = item.querySelector('.question-options');
|
|
|
|
|
+ let freetextInput = item.querySelector('.question-freetext');
|
|
|
|
|
|
|
|
let label = labelInput ? labelInput.value.trim() : '';
|
|
let label = labelInput ? labelInput.value.trim() : '';
|
|
|
if (!label) {
|
|
if (!label) {
|
|
@@ -94,29 +104,35 @@ function prepareSubmission(e) {
|
|
|
|
|
|
|
|
let options = [];
|
|
let options = [];
|
|
|
if (optionsInput) {
|
|
if (optionsInput) {
|
|
|
- options = optionsInput.value.split('\\n').map(o => o.trim()).filter(o => o);
|
|
|
|
|
|
|
+ options = optionsInput.value.split('\n').map(o => o.trim()).filter(o => o);
|
|
|
if (options.length === 0) {
|
|
if (options.length === 0) {
|
|
|
hasEmptyOptions = true;
|
|
hasEmptyOptions = true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ let allowFreeText = false;
|
|
|
|
|
+ if (freetextInput && freetextInput.checked) {
|
|
|
|
|
+ allowFreeText = true;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
questions.push({
|
|
questions.push({
|
|
|
id: item.dataset.id,
|
|
id: item.dataset.id,
|
|
|
type: item.dataset.type,
|
|
type: item.dataset.type,
|
|
|
label: label,
|
|
label: label,
|
|
|
- options: options
|
|
|
|
|
|
|
+ options: options,
|
|
|
|
|
+ allow_free_text: allowFreeText
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
if (hasEmptyLabel) {
|
|
if (hasEmptyLabel) {
|
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
|
- alert("Please fill out all question labels.");
|
|
|
|
|
|
|
+ alert("Bitte füllen Sie alle Fragetexte aus.");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (hasEmptyOptions) {
|
|
if (hasEmptyOptions) {
|
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
|
- alert("Please provide at least one option for your choice/dropdown questions.");
|
|
|
|
|
|
|
+ alert("Bitte geben Sie mindestens eine Option für Ihre Auswahlfragen an.");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|