Loading plugins/survey/survey.cpp +111 −8 Changes for plugins/survey/survey.cpp: 111 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -53,11 +53,12 @@ namespace blogi { std::string value; std::string label; std::string excludes; // comma-separated question IDs to skip when selected std::string icon; // media URL for icon type }; struct SurveyQuestion { std::string id; std::string type; // radio, checkbox, text, select, rating, image std::string type; // radio, checkbox, text, select, rating, image, icon std::string text; bool required = false; int ratingMin = 1; Loading Loading @@ -250,6 +251,8 @@ namespace blogi { opt.label = optEl->GetText() ? optEl->GetText() : ""; const char *exc = optEl->Attribute("excludes"); if (exc) opt.excludes = exc; const char *ico = optEl->Attribute("icon"); if (ico) opt.icon = ico; q.options.push_back(std::move(opt)); } tpl.questions.push_back(std::move(q)); Loading Loading @@ -380,7 +383,7 @@ namespace blogi { } }; if ((qq.type == "radio" || qq.type == "select") && json_object_is_type(f, json_type_string)) { if ((qq.type == "radio" || qq.type == "select" || qq.type == "icon") && json_object_is_type(f, json_type_string)) { collectExcludes(json_object_get_string(f)); } else if (qq.type == "checkbox" && json_object_is_type(f, json_type_array)) { size_t len = json_object_array_length(f); Loading Loading @@ -413,7 +416,7 @@ namespace blogi { if (!has || !field || json_object_is_type(field, json_type_null)) continue; if (q.type == "radio" || q.type == "select") { if (q.type == "radio" || q.type == "select" || q.type == "icon") { if (!json_object_is_type(field, json_type_string)) return "Field " + q.id + " must be a string"; std::string val = json_object_get_string(field); Loading Loading @@ -747,7 +750,7 @@ namespace blogi { if (json_object_is_type(field, json_type_string)) { std::string val = json_object_get_string(field); // Resolve label for radio/select if (q.type == "radio" || q.type == "select") { if (q.type == "radio" || q.type == "select" || q.type == "icon") { for (const auto &opt : q.options) if (opt.value == val) { val = opt.label; break; } } Loading Loading @@ -850,7 +853,7 @@ namespace blogi { if (json_object_is_type(field, json_type_string)) { std::string val = json_object_get_string(field); if (q.type == "radio" || q.type == "select") { if (q.type == "radio" || q.type == "select" || q.type == "icon") { for (const auto &opt : q.options) if (opt.value == val) { val = opt.label; break; } } Loading Loading @@ -1181,6 +1184,20 @@ namespace blogi { if (!opt.excludes.empty()) html << " data-excludes=\"" << opt.excludes << "\""; html << "/>" << opt.label << "</label></div>"; } } else if (q.type == "icon") { html << "<div class=\"icon-grid\">"; for (const auto &opt : q.options) { if (opt.value.empty() && opt.label.empty()) continue; html << "<label class=\"icon-option\">" << "<input type=\"radio\" name=\"" << q.id << "\" value=\"" << opt.value << "\""; if (!opt.excludes.empty()) html << " data-excludes=\"" << opt.excludes << "\""; html << "/>"; if (!opt.icon.empty()) html << "<img src=\"" << htmlEscape(opt.icon) << "\" alt=\"" << htmlEscape(opt.label) << "\"/>"; html << "<span>" << opt.label << "</span></label>"; } html << "</div>"; } else if (q.type == "checkbox") { for (const auto &opt : q.options) { if (opt.value.empty() && opt.label.empty()) continue; Loading Loading @@ -1291,6 +1308,13 @@ namespace blogi { << ".survey-page .survey-spinner{display:inline-block;width:36px;height:36px;border:4px solid var(--blogi-border,#eaeaea);border-top-color:var(--blogi-accent,#84CB3A);border-radius:50%;animation:survey-spin .8s linear infinite;}" << "@keyframes survey-spin{to{transform:rotate(360deg);}}" << ".survey-page .survey-loading-text{margin-top:12px;color:var(--blogi-text-muted,#6b6b6b);font-size:.95em;}" << ".survey-page .icon-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:12px;}" << ".survey-page .icon-option{display:flex;flex-direction:column;align-items:center;padding:12px;border:2px solid var(--blogi-border,#ddd);border-radius:10px;cursor:pointer;transition:.2s;text-align:center;background:var(--blogi-surface,#fff);}" << ".survey-page .icon-option:hover{border-color:var(--blogi-accent,#84CB3A);}" << ".survey-page .icon-option input{display:none;}" << ".survey-page .icon-option img{width:64px;height:64px;object-fit:contain;margin-bottom:6px;}" << ".survey-page .icon-option span{font-size:.85em;color:var(--blogi-text,#333);}" << ".survey-page .icon-option.selected{border-color:var(--blogi-accent,#84CB3A);background:var(--blogi-success-bg,#e8f5e9);box-shadow:0 0 0 3px rgba(132,203,58,.25);}" << "</style>"; // Inline JS — scoped per survey instance Loading Loading @@ -1437,6 +1461,12 @@ namespace blogi { << "if(t){if(t.classList.contains('btn-next'))wizardNext();" << "else if(t.classList.contains('btn-prev'))wizardPrev();" << "else if(t.classList.contains('btn-submit'))submitSurvey();return;}" << "var ico=e.target.closest?e.target.closest('.icon-option'):null;" << "if(ico){var inp=ico.querySelector('input[type=radio]');if(inp){inp.checked=true;" << "var grid=ico.closest('.icon-grid');if(grid){var all=grid.querySelectorAll('.icon-option');" << "for(var i=0;i<all.length;i++)all[i].classList.remove('selected');}ico.classList.add('selected');" << "inp.dispatchEvent(new Event('change',{bubbles:true}));" << "setTimeout(function(){var nxt=nextVisibleStep(currentStep);if(nxt!==-1)showStep(nxt);else submitSurvey();},350);}return;}" << "var rm=e.target.closest?e.target.closest('.file-remove'):null;" << "if(rm){var name=rm.getAttribute('data-name'),imgId=rm.getAttribute('data-imgid');" << "if(name&&imgId)removeImage(name,imgId);}});" Loading Loading @@ -2146,6 +2176,7 @@ namespace blogi { tinyxml2::XMLElement *optEl = doc.NewElement("option"); optEl->SetAttribute("value", opt.value.c_str()); if (!opt.excludes.empty()) optEl->SetAttribute("excludes", opt.excludes.c_str()); if (!opt.icon.empty()) optEl->SetAttribute("icon", opt.icon.c_str()); optEl->SetText(opt.label.c_str()); qEl->InsertEndChild(optEl); } Loading Loading @@ -2187,6 +2218,8 @@ namespace blogi { json_object_object_add(jo, "label", json_object_new_string(opt.label.c_str())); if (!opt.excludes.empty()) json_object_object_add(jo, "excludes", json_object_new_string(opt.excludes.c_str())); if (!opt.icon.empty()) json_object_object_add(jo, "icon", json_object_new_string(opt.icon.c_str())); json_object_array_add(jopts, jo); } json_object_object_add(jq, "options", jopts); Loading Loading @@ -2250,6 +2283,8 @@ namespace blogi { opt.label = json_object_get_string(ov); if (json_object_object_get_ex(jo, "excludes", &ov) && json_object_is_type(ov, json_type_string)) opt.excludes = json_object_get_string(ov); if (json_object_object_get_ex(jo, "icon", &ov) && json_object_is_type(ov, json_type_string)) opt.icon = json_object_get_string(ov); q.options.push_back(std::move(opt)); } } Loading Loading @@ -2487,6 +2522,7 @@ namespace blogi { if (qpos != std::string::npos) surveyName = curl.substr(qpos + 5); std::string saveUrl = Args->config->buildurl("survey/_api/save"); std::string apiUrl = Args->config->buildurl("api"); std::string backUrl = Args->config->buildurl("settings/survey"); // Load survey template data inline Loading @@ -2513,6 +2549,7 @@ namespace blogi { std::ostringstream html; html << "<div id=\"survey-editor\" data-name=\"" << htmlEscape(surveyName) << "\" " << "data-save-url=\"" << htmlEscape(saveUrl) << "\" " << "data-api-url=\"" << htmlEscape(apiUrl) << "\" " << "data-survey=\"" << htmlEscape(surveyJson) << "\">" << "</div>"; Loading Loading @@ -2553,6 +2590,10 @@ namespace blogi { << ".se-opt-row button{background:none;border:none;cursor:pointer;color:var(--blogi-error,#F36947);font-size:1em;}" << ".se-add-opt{background:none;border:1px dashed var(--blogi-border,#ccc);border-radius:4px;padding:4px 10px;cursor:pointer;font-size:.85em;color:var(--blogi-text-muted,#888);margin-top:4px;}" << ".se-add-opt:hover{border-color:var(--blogi-accent,#2da82d);color:var(--blogi-accent,#2da82d);}" << ".se-pick-icon{padding:4px 8px;background:var(--blogi-accent,#2da82d);color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:1em;}" << ".se-pick-icon:hover{opacity:.8;}" << ".se-opt-icon{font-size:.85em;}" << ".se-opt-preview{width:32px;height:32px;object-fit:contain;border-radius:4px;border:1px solid var(--blogi-border,#555);}" << ".se-rating-row{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:8px;}" << ".se-rating-row label{font-size:.85em;color:var(--blogi-text-muted,#666);}" << ".se-rating-row input{width:70px;padding:4px 6px;border:1px solid var(--blogi-border,#ddd);border-radius:4px;background:var(--blogi-surface,#fff);color:var(--blogi-text,#333);}" Loading @@ -2563,6 +2604,7 @@ namespace blogi { << "(function(){" << "var el=document.getElementById('survey-editor');" << "var saveUrl=el.getAttribute('data-save-url');" << "var apiUrl=el.getAttribute('data-api-url');" << "var surveyName=el.getAttribute('data-name');" << "var originalName=surveyName;" << "var survey=JSON.parse(el.getAttribute('data-survey'));" Loading Loading @@ -2608,6 +2650,8 @@ namespace blogi { << "if(inputs.length>=2){" << "var o={value:inputs[0].value,label:inputs[1].value};" << "if(inputs.length>=3&&inputs[2].value)o.excludes=inputs[2].value;" << "var iconI=optEls[j].querySelector('.se-opt-icon');" << "if(iconI&&iconI.value)o.icon=iconI.value;" << "q.options.push(o);}}" << "survey.questions.push(q);}}" << "" Loading Loading @@ -2645,7 +2689,7 @@ namespace blogi { << "h+='<div class=\"se-q-row\">';" << "h+='<div><label>Fragetext</label><input class=\"se-qtext\" value=\"'+esc(q.text||'')+'\"/></div>';" << "h+='<div><label>Typ</label><select class=\"se-qtype\">';" << "var types=['radio','checkbox','text','select','rating','image'];" << "var types=['radio','checkbox','text','select','rating','image','icon'];" << "for(var t=0;t<types.length;t++){h+='<option value=\"'+types[t]+'\"'+(q.type===types[t]?' selected':'')+'>'+types[t]+'</option>';}" << "h+='</select></div>';" << "h+='<div><label>Pflicht</label><br/><input type=\"checkbox\" class=\"se-qreq\"'+(q.required?' checked':'')+'/></div>';" Loading @@ -2654,7 +2698,7 @@ namespace blogi { << "if(q.type==='rating'){" << "h+='<div class=\"se-rating-row\"><div><label>Min</label><input type=\"number\" class=\"se-rmin\" value=\"'+(q.ratingMin||1)+'\"/></div>';" << "h+='<div><label>Max</label><input type=\"number\" class=\"se-rmax\" value=\"'+(q.ratingMax||5)+'\"/></div></div>';}" << "if(q.type==='radio'||q.type==='checkbox'||q.type==='select'){" << "if(q.type==='radio'||q.type==='checkbox'||q.type==='select'||q.type==='icon'){" << "h+='<div class=\"se-opts\"><h4>Optionen</h4>';" << "var opts=q.options||[];" << "for(var j=0;j<opts.length;j++){" Loading @@ -2662,6 +2706,11 @@ namespace blogi { << "h+='<input placeholder=\"value\" value=\"'+esc(opts[j].value||'')+'\"/>';" << "h+='<input placeholder=\"label\" value=\"'+esc(opts[j].label||'')+'\"/>';" << "h+='<input placeholder=\"excludes\" value=\"'+esc(opts[j].excludes||'')+'\"/>';" << "if(q.type==='icon'){" << "var icoUrl=opts[j].icon||'';" << "if(icoUrl)h+='<img src=\"'+esc(icoUrl)+'\" class=\"se-opt-preview\" alt=\"\"/>';" << "h+='<input class=\"se-opt-icon\" placeholder=\"icon URL\" value=\"'+esc(icoUrl)+'\" style=\"flex:2\"/>';" << "h+='<button class=\"se-pick-icon\" type=\"button\" title=\"Media\">📷</button>';}" << "h+='<button class=\"se-opt-del\">×</button></div>';}" << "h+='<button class=\"se-add-opt\">+ Option</button></div>';}" << "h+='</div>';return h;}" Loading @@ -2679,11 +2728,65 @@ namespace blogi { << "else if(t.classList.contains('se-q-up')){readForm();var qe=t.closest('.se-question');var idx=parseInt(qe.getAttribute('data-idx'));if(idx>0){var tmp=survey.questions[idx];survey.questions[idx]=survey.questions[idx-1];survey.questions[idx-1]=tmp;render();}}" << "else if(t.classList.contains('se-q-down')){readForm();var qe=t.closest('.se-question');var idx=parseInt(qe.getAttribute('data-idx'));if(idx<survey.questions.length-1){var tmp=survey.questions[idx];survey.questions[idx]=survey.questions[idx+1];survey.questions[idx+1]=tmp;render();}}" << "else if(t.classList.contains('se-opt-del')){readForm();var row=t.closest('.se-opt-row');var qe=t.closest('.se-question');var qi=parseInt(qe.getAttribute('data-idx'));var opts=qe.querySelectorAll('.se-opt-row');for(var i=0;i<opts.length;i++){if(opts[i]===row){survey.questions[qi].options.splice(i,1);break;}}render();}" << "else if(t.classList.contains('se-add-opt')){readForm();var qe=t.closest('.se-question');var qi=parseInt(qe.getAttribute('data-idx'));survey.questions[qi].options.push({value:'',label:'',excludes:''});render();}});" << "else if(t.classList.contains('se-add-opt')){readForm();var qe=t.closest('.se-question');var qi=parseInt(qe.getAttribute('data-idx'));survey.questions[qi].options.push({value:'',label:'',excludes:'',icon:''});render();}" << "else if(t.classList.contains('se-pick-icon')){var inp=t.previousElementSibling;if(inp)openMediaPicker(inp);}});" << "var typeSelects=el.querySelectorAll('.se-qtype');" << "for(var i=0;i<typeSelects.length;i++){" << "typeSelects[i].addEventListener('change',function(){readForm();render();});}}" << "" // media picker for icon type << "function getAuthId(){var m=document.cookie.match(/authid=([^;]+)/);return m?m[1]:null;}" << "function apiCall(cmds,cb){" << "var aid=getAuthId();if(aid)cmds.unshift({authid:aid});" << "var xhr=new XMLHttpRequest();xhr.open('POST',apiUrl,true);" << "xhr.setRequestHeader('Content-Type','application/json');" << "xhr.onreadystatechange=function(){" << "if(xhr.readyState===4){try{var r=JSON.parse(xhr.responseText);" << "if(aid&&Array.isArray(r))r=r.slice(1);cb(null,r);}catch(e){cb(e);}}};" << "xhr.send(JSON.stringify(cmds));}" << "" << "function openMediaPicker(targetInput){" << "var ov=document.createElement('div');ov.id='se-media-modal';" << "ov.style.cssText='position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.6);z-index:10000;display:flex;align-items:center;justify-content:center;';" << "ov.onclick=function(e){if(e.target===ov)ov.remove();};" << "var box=document.createElement('div');" << "box.style.cssText='background:#2a2e32;color:#e0e0e0;border-radius:10px;padding:20px;width:560px;max-height:70vh;display:flex;flex-direction:column;';" << "box.innerHTML='<h3 style=\"margin:0 0 12px\">Media auswählen</h3><div id=\"se-mb-nav\"></div><div id=\"se-mb-content\" style=\"flex:1;overflow-y:auto;min-height:150px;\">Laden...</div><div style=\"margin-top:12px;text-align:right;\"><button type=\"button\" id=\"se-mb-close\" style=\"padding:6px 16px;background:#555;color:#fff;border:none;border-radius:6px;cursor:pointer;\">Abbrechen</button></div>';" << "ov.appendChild(box);document.body.appendChild(ov);" << "document.getElementById('se-mb-close').onclick=function(){ov.remove();};" << "apiCall([{command:'media_list_albums'}],function(err,res){" << "if(err||!res){document.getElementById('se-mb-content').textContent='Fehler';return;}" << "var al=null;for(var i=0;i<res.length;i++){if(res[i]&&res[i].albums){al=res[i].albums;break;}}" << "if(!al){document.getElementById('se-mb-content').textContent='Keine Alben';return;}" << "var h='';for(var i=0;i<al.length;i++){h+='<div class=\"se-mb-album\" data-id=\"'+esc(al[i].id)+'\" data-name=\"'+esc(al[i].name)+'\" style=\"padding:10px;margin:4px 0;background:#3a3e42;border-radius:6px;cursor:pointer;\">'+esc(al[i].name)+' ('+al[i].media_count+')</div>';}" << "document.getElementById('se-mb-content').innerHTML=h;" << "document.getElementById('se-mb-content').onclick=function(ev){" << "var ab=ev.target.closest('.se-mb-album');if(!ab)return;" << "loadAlbumMedia(ab.getAttribute('data-id'),ab.getAttribute('data-name'),targetInput,ov);};});}" << "" << "function loadAlbumMedia(albumId,albumName,targetInput,ov){" << "var nav=document.getElementById('se-mb-nav');" << "nav.innerHTML='<button type=\"button\" id=\"se-mb-back\" style=\"padding:4px 10px;background:#555;color:#fff;border:none;border-radius:6px;cursor:pointer;\">← Zurück</button> <strong>'+esc(albumName)+'</strong>';" << "document.getElementById('se-mb-back').onclick=function(){openMediaPicker(targetInput);ov.remove();};" << "document.getElementById('se-mb-content').textContent='Laden...';" << "apiCall([{command:'media_list_media',album_id:albumId}],function(err,res){" << "if(err||!res){document.getElementById('se-mb-content').textContent='Fehler';return;}" << "var ml=null;for(var i=0;i<res.length;i++){if(res[i]&&res[i].media){ml=res[i].media;break;}}" << "if(!ml||ml.length===0){document.getElementById('se-mb-content').textContent='Leer';return;}" << "var h='<div style=\"display:grid;grid-template-columns:repeat(auto-fill,minmax(100px,1fr));gap:8px;\">';" << "for(var i=0;i<ml.length;i++){var m=ml[i],ext=m.filename.split('.').pop()||'webp';" << "h+='<div class=\"se-mb-item\" data-id=\"'+esc(m.id)+'\" data-ext=\"'+esc(ext)+'\" style=\"cursor:pointer;border:2px solid transparent;border-radius:8px;padding:4px;background:#3a3e42;text-align:center;\">';" << "if(m.kind==='image')h+='<img src=\"'+esc(m.url)+'\" style=\"width:100%;height:70px;object-fit:cover;border-radius:4px;\"/>';" << "else h+='<div style=\"height:70px;display:flex;align-items:center;justify-content:center;font-size:2em;\">📄</div>';" << "h+='<div style=\"font-size:.7em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;\">'+esc(m.filename)+'</div></div>';}" << "h+='</div>';document.getElementById('se-mb-content').innerHTML=h;" << "document.getElementById('se-mb-content').onclick=function(ev){" << "var it=ev.target.closest('.se-mb-item');if(!it)return;" << "var mid=it.getAttribute('data-id');" << "targetInput.value='/media/getimage/'+mid+'.webp?w=64';" << "apiCall([{command:'media_create_preview',media_id:mid,width:64,height:64}],function(){});" << "ov.remove();};});}" << "" << "render();" << "})();" << "</script>"; Loading Loading
plugins/survey/survey.cpp +111 −8 Changes for plugins/survey/survey.cpp: 111 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -53,11 +53,12 @@ namespace blogi { std::string value; std::string label; std::string excludes; // comma-separated question IDs to skip when selected std::string icon; // media URL for icon type }; struct SurveyQuestion { std::string id; std::string type; // radio, checkbox, text, select, rating, image std::string type; // radio, checkbox, text, select, rating, image, icon std::string text; bool required = false; int ratingMin = 1; Loading Loading @@ -250,6 +251,8 @@ namespace blogi { opt.label = optEl->GetText() ? optEl->GetText() : ""; const char *exc = optEl->Attribute("excludes"); if (exc) opt.excludes = exc; const char *ico = optEl->Attribute("icon"); if (ico) opt.icon = ico; q.options.push_back(std::move(opt)); } tpl.questions.push_back(std::move(q)); Loading Loading @@ -380,7 +383,7 @@ namespace blogi { } }; if ((qq.type == "radio" || qq.type == "select") && json_object_is_type(f, json_type_string)) { if ((qq.type == "radio" || qq.type == "select" || qq.type == "icon") && json_object_is_type(f, json_type_string)) { collectExcludes(json_object_get_string(f)); } else if (qq.type == "checkbox" && json_object_is_type(f, json_type_array)) { size_t len = json_object_array_length(f); Loading Loading @@ -413,7 +416,7 @@ namespace blogi { if (!has || !field || json_object_is_type(field, json_type_null)) continue; if (q.type == "radio" || q.type == "select") { if (q.type == "radio" || q.type == "select" || q.type == "icon") { if (!json_object_is_type(field, json_type_string)) return "Field " + q.id + " must be a string"; std::string val = json_object_get_string(field); Loading Loading @@ -747,7 +750,7 @@ namespace blogi { if (json_object_is_type(field, json_type_string)) { std::string val = json_object_get_string(field); // Resolve label for radio/select if (q.type == "radio" || q.type == "select") { if (q.type == "radio" || q.type == "select" || q.type == "icon") { for (const auto &opt : q.options) if (opt.value == val) { val = opt.label; break; } } Loading Loading @@ -850,7 +853,7 @@ namespace blogi { if (json_object_is_type(field, json_type_string)) { std::string val = json_object_get_string(field); if (q.type == "radio" || q.type == "select") { if (q.type == "radio" || q.type == "select" || q.type == "icon") { for (const auto &opt : q.options) if (opt.value == val) { val = opt.label; break; } } Loading Loading @@ -1181,6 +1184,20 @@ namespace blogi { if (!opt.excludes.empty()) html << " data-excludes=\"" << opt.excludes << "\""; html << "/>" << opt.label << "</label></div>"; } } else if (q.type == "icon") { html << "<div class=\"icon-grid\">"; for (const auto &opt : q.options) { if (opt.value.empty() && opt.label.empty()) continue; html << "<label class=\"icon-option\">" << "<input type=\"radio\" name=\"" << q.id << "\" value=\"" << opt.value << "\""; if (!opt.excludes.empty()) html << " data-excludes=\"" << opt.excludes << "\""; html << "/>"; if (!opt.icon.empty()) html << "<img src=\"" << htmlEscape(opt.icon) << "\" alt=\"" << htmlEscape(opt.label) << "\"/>"; html << "<span>" << opt.label << "</span></label>"; } html << "</div>"; } else if (q.type == "checkbox") { for (const auto &opt : q.options) { if (opt.value.empty() && opt.label.empty()) continue; Loading Loading @@ -1291,6 +1308,13 @@ namespace blogi { << ".survey-page .survey-spinner{display:inline-block;width:36px;height:36px;border:4px solid var(--blogi-border,#eaeaea);border-top-color:var(--blogi-accent,#84CB3A);border-radius:50%;animation:survey-spin .8s linear infinite;}" << "@keyframes survey-spin{to{transform:rotate(360deg);}}" << ".survey-page .survey-loading-text{margin-top:12px;color:var(--blogi-text-muted,#6b6b6b);font-size:.95em;}" << ".survey-page .icon-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:12px;}" << ".survey-page .icon-option{display:flex;flex-direction:column;align-items:center;padding:12px;border:2px solid var(--blogi-border,#ddd);border-radius:10px;cursor:pointer;transition:.2s;text-align:center;background:var(--blogi-surface,#fff);}" << ".survey-page .icon-option:hover{border-color:var(--blogi-accent,#84CB3A);}" << ".survey-page .icon-option input{display:none;}" << ".survey-page .icon-option img{width:64px;height:64px;object-fit:contain;margin-bottom:6px;}" << ".survey-page .icon-option span{font-size:.85em;color:var(--blogi-text,#333);}" << ".survey-page .icon-option.selected{border-color:var(--blogi-accent,#84CB3A);background:var(--blogi-success-bg,#e8f5e9);box-shadow:0 0 0 3px rgba(132,203,58,.25);}" << "</style>"; // Inline JS — scoped per survey instance Loading Loading @@ -1437,6 +1461,12 @@ namespace blogi { << "if(t){if(t.classList.contains('btn-next'))wizardNext();" << "else if(t.classList.contains('btn-prev'))wizardPrev();" << "else if(t.classList.contains('btn-submit'))submitSurvey();return;}" << "var ico=e.target.closest?e.target.closest('.icon-option'):null;" << "if(ico){var inp=ico.querySelector('input[type=radio]');if(inp){inp.checked=true;" << "var grid=ico.closest('.icon-grid');if(grid){var all=grid.querySelectorAll('.icon-option');" << "for(var i=0;i<all.length;i++)all[i].classList.remove('selected');}ico.classList.add('selected');" << "inp.dispatchEvent(new Event('change',{bubbles:true}));" << "setTimeout(function(){var nxt=nextVisibleStep(currentStep);if(nxt!==-1)showStep(nxt);else submitSurvey();},350);}return;}" << "var rm=e.target.closest?e.target.closest('.file-remove'):null;" << "if(rm){var name=rm.getAttribute('data-name'),imgId=rm.getAttribute('data-imgid');" << "if(name&&imgId)removeImage(name,imgId);}});" Loading Loading @@ -2146,6 +2176,7 @@ namespace blogi { tinyxml2::XMLElement *optEl = doc.NewElement("option"); optEl->SetAttribute("value", opt.value.c_str()); if (!opt.excludes.empty()) optEl->SetAttribute("excludes", opt.excludes.c_str()); if (!opt.icon.empty()) optEl->SetAttribute("icon", opt.icon.c_str()); optEl->SetText(opt.label.c_str()); qEl->InsertEndChild(optEl); } Loading Loading @@ -2187,6 +2218,8 @@ namespace blogi { json_object_object_add(jo, "label", json_object_new_string(opt.label.c_str())); if (!opt.excludes.empty()) json_object_object_add(jo, "excludes", json_object_new_string(opt.excludes.c_str())); if (!opt.icon.empty()) json_object_object_add(jo, "icon", json_object_new_string(opt.icon.c_str())); json_object_array_add(jopts, jo); } json_object_object_add(jq, "options", jopts); Loading Loading @@ -2250,6 +2283,8 @@ namespace blogi { opt.label = json_object_get_string(ov); if (json_object_object_get_ex(jo, "excludes", &ov) && json_object_is_type(ov, json_type_string)) opt.excludes = json_object_get_string(ov); if (json_object_object_get_ex(jo, "icon", &ov) && json_object_is_type(ov, json_type_string)) opt.icon = json_object_get_string(ov); q.options.push_back(std::move(opt)); } } Loading Loading @@ -2487,6 +2522,7 @@ namespace blogi { if (qpos != std::string::npos) surveyName = curl.substr(qpos + 5); std::string saveUrl = Args->config->buildurl("survey/_api/save"); std::string apiUrl = Args->config->buildurl("api"); std::string backUrl = Args->config->buildurl("settings/survey"); // Load survey template data inline Loading @@ -2513,6 +2549,7 @@ namespace blogi { std::ostringstream html; html << "<div id=\"survey-editor\" data-name=\"" << htmlEscape(surveyName) << "\" " << "data-save-url=\"" << htmlEscape(saveUrl) << "\" " << "data-api-url=\"" << htmlEscape(apiUrl) << "\" " << "data-survey=\"" << htmlEscape(surveyJson) << "\">" << "</div>"; Loading Loading @@ -2553,6 +2590,10 @@ namespace blogi { << ".se-opt-row button{background:none;border:none;cursor:pointer;color:var(--blogi-error,#F36947);font-size:1em;}" << ".se-add-opt{background:none;border:1px dashed var(--blogi-border,#ccc);border-radius:4px;padding:4px 10px;cursor:pointer;font-size:.85em;color:var(--blogi-text-muted,#888);margin-top:4px;}" << ".se-add-opt:hover{border-color:var(--blogi-accent,#2da82d);color:var(--blogi-accent,#2da82d);}" << ".se-pick-icon{padding:4px 8px;background:var(--blogi-accent,#2da82d);color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:1em;}" << ".se-pick-icon:hover{opacity:.8;}" << ".se-opt-icon{font-size:.85em;}" << ".se-opt-preview{width:32px;height:32px;object-fit:contain;border-radius:4px;border:1px solid var(--blogi-border,#555);}" << ".se-rating-row{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:8px;}" << ".se-rating-row label{font-size:.85em;color:var(--blogi-text-muted,#666);}" << ".se-rating-row input{width:70px;padding:4px 6px;border:1px solid var(--blogi-border,#ddd);border-radius:4px;background:var(--blogi-surface,#fff);color:var(--blogi-text,#333);}" Loading @@ -2563,6 +2604,7 @@ namespace blogi { << "(function(){" << "var el=document.getElementById('survey-editor');" << "var saveUrl=el.getAttribute('data-save-url');" << "var apiUrl=el.getAttribute('data-api-url');" << "var surveyName=el.getAttribute('data-name');" << "var originalName=surveyName;" << "var survey=JSON.parse(el.getAttribute('data-survey'));" Loading Loading @@ -2608,6 +2650,8 @@ namespace blogi { << "if(inputs.length>=2){" << "var o={value:inputs[0].value,label:inputs[1].value};" << "if(inputs.length>=3&&inputs[2].value)o.excludes=inputs[2].value;" << "var iconI=optEls[j].querySelector('.se-opt-icon');" << "if(iconI&&iconI.value)o.icon=iconI.value;" << "q.options.push(o);}}" << "survey.questions.push(q);}}" << "" Loading Loading @@ -2645,7 +2689,7 @@ namespace blogi { << "h+='<div class=\"se-q-row\">';" << "h+='<div><label>Fragetext</label><input class=\"se-qtext\" value=\"'+esc(q.text||'')+'\"/></div>';" << "h+='<div><label>Typ</label><select class=\"se-qtype\">';" << "var types=['radio','checkbox','text','select','rating','image'];" << "var types=['radio','checkbox','text','select','rating','image','icon'];" << "for(var t=0;t<types.length;t++){h+='<option value=\"'+types[t]+'\"'+(q.type===types[t]?' selected':'')+'>'+types[t]+'</option>';}" << "h+='</select></div>';" << "h+='<div><label>Pflicht</label><br/><input type=\"checkbox\" class=\"se-qreq\"'+(q.required?' checked':'')+'/></div>';" Loading @@ -2654,7 +2698,7 @@ namespace blogi { << "if(q.type==='rating'){" << "h+='<div class=\"se-rating-row\"><div><label>Min</label><input type=\"number\" class=\"se-rmin\" value=\"'+(q.ratingMin||1)+'\"/></div>';" << "h+='<div><label>Max</label><input type=\"number\" class=\"se-rmax\" value=\"'+(q.ratingMax||5)+'\"/></div></div>';}" << "if(q.type==='radio'||q.type==='checkbox'||q.type==='select'){" << "if(q.type==='radio'||q.type==='checkbox'||q.type==='select'||q.type==='icon'){" << "h+='<div class=\"se-opts\"><h4>Optionen</h4>';" << "var opts=q.options||[];" << "for(var j=0;j<opts.length;j++){" Loading @@ -2662,6 +2706,11 @@ namespace blogi { << "h+='<input placeholder=\"value\" value=\"'+esc(opts[j].value||'')+'\"/>';" << "h+='<input placeholder=\"label\" value=\"'+esc(opts[j].label||'')+'\"/>';" << "h+='<input placeholder=\"excludes\" value=\"'+esc(opts[j].excludes||'')+'\"/>';" << "if(q.type==='icon'){" << "var icoUrl=opts[j].icon||'';" << "if(icoUrl)h+='<img src=\"'+esc(icoUrl)+'\" class=\"se-opt-preview\" alt=\"\"/>';" << "h+='<input class=\"se-opt-icon\" placeholder=\"icon URL\" value=\"'+esc(icoUrl)+'\" style=\"flex:2\"/>';" << "h+='<button class=\"se-pick-icon\" type=\"button\" title=\"Media\">📷</button>';}" << "h+='<button class=\"se-opt-del\">×</button></div>';}" << "h+='<button class=\"se-add-opt\">+ Option</button></div>';}" << "h+='</div>';return h;}" Loading @@ -2679,11 +2728,65 @@ namespace blogi { << "else if(t.classList.contains('se-q-up')){readForm();var qe=t.closest('.se-question');var idx=parseInt(qe.getAttribute('data-idx'));if(idx>0){var tmp=survey.questions[idx];survey.questions[idx]=survey.questions[idx-1];survey.questions[idx-1]=tmp;render();}}" << "else if(t.classList.contains('se-q-down')){readForm();var qe=t.closest('.se-question');var idx=parseInt(qe.getAttribute('data-idx'));if(idx<survey.questions.length-1){var tmp=survey.questions[idx];survey.questions[idx]=survey.questions[idx+1];survey.questions[idx+1]=tmp;render();}}" << "else if(t.classList.contains('se-opt-del')){readForm();var row=t.closest('.se-opt-row');var qe=t.closest('.se-question');var qi=parseInt(qe.getAttribute('data-idx'));var opts=qe.querySelectorAll('.se-opt-row');for(var i=0;i<opts.length;i++){if(opts[i]===row){survey.questions[qi].options.splice(i,1);break;}}render();}" << "else if(t.classList.contains('se-add-opt')){readForm();var qe=t.closest('.se-question');var qi=parseInt(qe.getAttribute('data-idx'));survey.questions[qi].options.push({value:'',label:'',excludes:''});render();}});" << "else if(t.classList.contains('se-add-opt')){readForm();var qe=t.closest('.se-question');var qi=parseInt(qe.getAttribute('data-idx'));survey.questions[qi].options.push({value:'',label:'',excludes:'',icon:''});render();}" << "else if(t.classList.contains('se-pick-icon')){var inp=t.previousElementSibling;if(inp)openMediaPicker(inp);}});" << "var typeSelects=el.querySelectorAll('.se-qtype');" << "for(var i=0;i<typeSelects.length;i++){" << "typeSelects[i].addEventListener('change',function(){readForm();render();});}}" << "" // media picker for icon type << "function getAuthId(){var m=document.cookie.match(/authid=([^;]+)/);return m?m[1]:null;}" << "function apiCall(cmds,cb){" << "var aid=getAuthId();if(aid)cmds.unshift({authid:aid});" << "var xhr=new XMLHttpRequest();xhr.open('POST',apiUrl,true);" << "xhr.setRequestHeader('Content-Type','application/json');" << "xhr.onreadystatechange=function(){" << "if(xhr.readyState===4){try{var r=JSON.parse(xhr.responseText);" << "if(aid&&Array.isArray(r))r=r.slice(1);cb(null,r);}catch(e){cb(e);}}};" << "xhr.send(JSON.stringify(cmds));}" << "" << "function openMediaPicker(targetInput){" << "var ov=document.createElement('div');ov.id='se-media-modal';" << "ov.style.cssText='position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.6);z-index:10000;display:flex;align-items:center;justify-content:center;';" << "ov.onclick=function(e){if(e.target===ov)ov.remove();};" << "var box=document.createElement('div');" << "box.style.cssText='background:#2a2e32;color:#e0e0e0;border-radius:10px;padding:20px;width:560px;max-height:70vh;display:flex;flex-direction:column;';" << "box.innerHTML='<h3 style=\"margin:0 0 12px\">Media auswählen</h3><div id=\"se-mb-nav\"></div><div id=\"se-mb-content\" style=\"flex:1;overflow-y:auto;min-height:150px;\">Laden...</div><div style=\"margin-top:12px;text-align:right;\"><button type=\"button\" id=\"se-mb-close\" style=\"padding:6px 16px;background:#555;color:#fff;border:none;border-radius:6px;cursor:pointer;\">Abbrechen</button></div>';" << "ov.appendChild(box);document.body.appendChild(ov);" << "document.getElementById('se-mb-close').onclick=function(){ov.remove();};" << "apiCall([{command:'media_list_albums'}],function(err,res){" << "if(err||!res){document.getElementById('se-mb-content').textContent='Fehler';return;}" << "var al=null;for(var i=0;i<res.length;i++){if(res[i]&&res[i].albums){al=res[i].albums;break;}}" << "if(!al){document.getElementById('se-mb-content').textContent='Keine Alben';return;}" << "var h='';for(var i=0;i<al.length;i++){h+='<div class=\"se-mb-album\" data-id=\"'+esc(al[i].id)+'\" data-name=\"'+esc(al[i].name)+'\" style=\"padding:10px;margin:4px 0;background:#3a3e42;border-radius:6px;cursor:pointer;\">'+esc(al[i].name)+' ('+al[i].media_count+')</div>';}" << "document.getElementById('se-mb-content').innerHTML=h;" << "document.getElementById('se-mb-content').onclick=function(ev){" << "var ab=ev.target.closest('.se-mb-album');if(!ab)return;" << "loadAlbumMedia(ab.getAttribute('data-id'),ab.getAttribute('data-name'),targetInput,ov);};});}" << "" << "function loadAlbumMedia(albumId,albumName,targetInput,ov){" << "var nav=document.getElementById('se-mb-nav');" << "nav.innerHTML='<button type=\"button\" id=\"se-mb-back\" style=\"padding:4px 10px;background:#555;color:#fff;border:none;border-radius:6px;cursor:pointer;\">← Zurück</button> <strong>'+esc(albumName)+'</strong>';" << "document.getElementById('se-mb-back').onclick=function(){openMediaPicker(targetInput);ov.remove();};" << "document.getElementById('se-mb-content').textContent='Laden...';" << "apiCall([{command:'media_list_media',album_id:albumId}],function(err,res){" << "if(err||!res){document.getElementById('se-mb-content').textContent='Fehler';return;}" << "var ml=null;for(var i=0;i<res.length;i++){if(res[i]&&res[i].media){ml=res[i].media;break;}}" << "if(!ml||ml.length===0){document.getElementById('se-mb-content').textContent='Leer';return;}" << "var h='<div style=\"display:grid;grid-template-columns:repeat(auto-fill,minmax(100px,1fr));gap:8px;\">';" << "for(var i=0;i<ml.length;i++){var m=ml[i],ext=m.filename.split('.').pop()||'webp';" << "h+='<div class=\"se-mb-item\" data-id=\"'+esc(m.id)+'\" data-ext=\"'+esc(ext)+'\" style=\"cursor:pointer;border:2px solid transparent;border-radius:8px;padding:4px;background:#3a3e42;text-align:center;\">';" << "if(m.kind==='image')h+='<img src=\"'+esc(m.url)+'\" style=\"width:100%;height:70px;object-fit:cover;border-radius:4px;\"/>';" << "else h+='<div style=\"height:70px;display:flex;align-items:center;justify-content:center;font-size:2em;\">📄</div>';" << "h+='<div style=\"font-size:.7em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;\">'+esc(m.filename)+'</div></div>';}" << "h+='</div>';document.getElementById('se-mb-content').innerHTML=h;" << "document.getElementById('se-mb-content').onclick=function(ev){" << "var it=ev.target.closest('.se-mb-item');if(!it)return;" << "var mid=it.getAttribute('data-id');" << "targetInput.value='/media/getimage/'+mid+'.webp?w=64';" << "apiCall([{command:'media_create_preview',media_id:mid,width:64,height:64}],function(){});" << "ov.remove();};});}" << "" << "render();" << "})();" << "</script>"; Loading