added categoryKey to questionnaire schema and updated related functions for questionnaire handling; enhanced API to fetch client answers

This commit is contained in:
2026-05-27 19:38:49 +02:00
parent 9c887537e8
commit 36b6d63266
9 changed files with 424 additions and 17 deletions

View File

@ -279,7 +279,8 @@ function configFormHTML(layout, config, prefix) {
<div class="form-group">
<label>Min selections</label>
<input type="number" id="${prefix}_minSelection" value="${config.minSelection || 0}" min="0">
</div>`;
</div>
${stringSpinnerOtherSectionHTML(config, prefix)}`;
break;
case 'glass_scale_question': {
const scaleType = config.scaleType || 'glass';
@ -426,6 +427,13 @@ function readConfigFromForm(layout, prefix) {
case 'multi_check_box_question': {
const ms = parseInt(val('minSelection') || '0', 10);
if (ms > 0) config.minSelection = ms;
const otherEnabled = document.getElementById(`${prefix}_otherEnabled`)?.checked;
if (otherEnabled) {
const ok = val('otherOptionKey') || 'other_option';
const on = val('otherNextQuestionId');
if (ok) config.otherOptionKey = ok;
if (on) config.otherNextQuestionId = on;
}
break;
}
case 'glass_scale_question': {
@ -534,6 +542,10 @@ function renderEditor() {
<input type="checkbox" id="metaShowPoints" ${questionnaire.showPoints ? 'checked' : ''} ${editable ? '' : 'disabled'}> Show points
</label>
</div>
<div class="form-group">
<label>Category key (app grouping)</label>
<input type="text" id="metaCategoryKey" value="${esc(questionnaire.categoryKey || '')}" placeholder="e.g. health_interview" ${editable ? '' : 'disabled'}>
</div>
</div>
${editable ? `
<details class="condition-details" style="margin-bottom:16px">
@ -617,6 +629,7 @@ async function saveMeta() {
const state = document.getElementById('metaState').value;
const orderIndex = parseInt(document.getElementById('metaOrder').value || '0', 10);
const showPoints = document.getElementById('metaShowPoints').checked ? 1 : 0;
const categoryKey = (document.getElementById('metaCategoryKey')?.value || '').trim();
let conditionJson = '{}';
const condEl = document.getElementById('metaCondition');
if (condEl) {
@ -632,7 +645,7 @@ async function saveMeta() {
try {
if (isNew) {
const data = await apiPost('questionnaires.php', { name, version, state, orderIndex, showPoints, conditionJson });
const data = await apiPost('questionnaires.php', { name, version, state, orderIndex, showPoints, conditionJson, categoryKey });
if (data.success) {
questionnaire = data.questionnaire;
isNew = false;
@ -642,10 +655,10 @@ async function saveMeta() {
} else {
const data = await apiPut('questionnaires.php', {
questionnaireID: questionnaire.questionnaireID,
name, version, state, orderIndex, showPoints, conditionJson
name, version, state, orderIndex, showPoints, conditionJson, categoryKey
});
if (data.success) {
questionnaire = { ...questionnaire, name, version, state, orderIndex, showPoints, conditionJson };
questionnaire = { ...questionnaire, name, version, state, orderIndex, showPoints, conditionJson, categoryKey };
document.getElementById('editorTitle').textContent = name;
showToast('Saved', 'success');
}