Commit b45a4c70 authored by jan.koester's avatar jan.koester
Browse files

test

parent 8af29626
Loading
Loading
Loading
Loading
+25 −14
Changes for plugins/survey/survey.cpp: 25 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ namespace blogi {
        std::string type;     // radio, checkbox, text, select, rating, image, icon
        std::string text;
        bool        required = false;
        bool        multiSelect = false;
        int         ratingMin = 1;
        int         ratingMax = 5;
        std::string acceptTypes;
@@ -232,6 +233,8 @@ namespace blogi {
                q.id   = qid   ? qid   : "";
                q.type = qtype ? qtype : "text";
                q.required = qreq && std::string(qreq) == "true";
                const char *qmulti = qEl->Attribute("multiselect");
                q.multiSelect = qmulti && std::string(qmulti) == "true";
                qEl->QueryIntAttribute("min", &q.ratingMin);
                qEl->QueryIntAttribute("max", &q.ratingMax);

@@ -383,9 +386,9 @@ namespace blogi {
                    }
                };

                if ((qq.type == "radio" || qq.type == "select" || qq.type == "icon") && json_object_is_type(f, json_type_string)) {
                if ((qq.type == "radio" || qq.type == "select" || (qq.type == "icon" && !qq.multiSelect)) && 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)) {
                } else if ((qq.type == "checkbox" || (qq.type == "icon" && qq.multiSelect)) && json_object_is_type(f, json_type_array)) {
                    size_t len = json_object_array_length(f);
                    for (size_t i = 0; i < len; ++i) {
                        json_object *item = json_object_array_get_idx(f, i);
@@ -416,7 +419,7 @@ namespace blogi {
                if (!has || !field || json_object_is_type(field, json_type_null))
                    continue;

                if (q.type == "radio" || q.type == "select" || q.type == "icon") {
                if (q.type == "radio" || q.type == "select" || (q.type == "icon" && !q.multiSelect)) {
                    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);
@@ -426,7 +429,7 @@ namespace blogi {
                            if (opt.value == val) { found = true; break; }
                        if (!found) return "Invalid value for " + q.id;
                    }
                } else if (q.type == "checkbox") {
                } else if (q.type == "checkbox" || (q.type == "icon" && q.multiSelect)) {
                    if (!json_object_is_type(field, json_type_array))
                        return "Field " + q.id + " must be an array";
                    size_t len = json_object_array_length(field);
@@ -750,7 +753,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" || q.type == "icon") {
                    if (q.type == "radio" || q.type == "select" || (q.type == "icon" && !q.multiSelect)) {
                        for (const auto &opt : q.options)
                            if (opt.value == val) { val = opt.label; break; }
                    }
@@ -762,7 +765,7 @@ namespace blogi {
                        json_object *item = json_object_array_get_idx(field, i);
                        if (!json_object_is_type(item, json_type_string)) continue;
                        std::string val = json_object_get_string(item);
                        if (q.type == "checkbox") {
                        if (q.type == "checkbox" || (q.type == "icon" && q.multiSelect)) {
                            for (const auto &opt : q.options)
                                if (opt.value == val) { val = opt.label; break; }
                        }
@@ -853,7 +856,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" || q.type == "icon") {
                    if (q.type == "radio" || q.type == "select" || (q.type == "icon" && !q.multiSelect)) {
                        for (const auto &opt : q.options)
                            if (opt.value == val) { val = opt.label; break; }
                    }
@@ -871,7 +874,7 @@ namespace blogi {
                        json_object *item = json_object_array_get_idx(field, i);
                        if (!json_object_is_type(item, json_type_string)) continue;
                        std::string val = json_object_get_string(item);
                        if (q.type == "checkbox") {
                        if (q.type == "checkbox" || (q.type == "icon" && q.multiSelect)) {
                            for (const auto &opt : q.options)
                                if (opt.value == val) { val = opt.label; break; }
                            if (i > 0) answersHtml << ", ";
@@ -1185,11 +1188,11 @@ namespace blogi {
                        html << "/>" << opt.label << "</label></div>";
                    }
                } else if (q.type == "icon") {
                    html << "<div class=\"icon-grid\">";
                    html << "<div class=\"icon-grid\"" << (q.multiSelect ? " data-multi=\"true\"" : "") << ">";
                    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
                             << "<input type=\"" << (q.multiSelect ? "checkbox" : "radio") << "\" name=\"" << q.id
                             << "\" value=\"" << opt.value << "\"";
                        if (!opt.excludes.empty()) html << " data-excludes=\"" << opt.excludes << "\"";
                        html << "/>";
@@ -1462,11 +1465,13 @@ namespace blogi {
                 << "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');"
                 << "if(ico){var grid=ico.closest('.icon-grid');var multi=grid&&grid.getAttribute('data-multi')==='true';"
                 << "var inp=ico.querySelector('input');if(inp){"
                 << "if(multi){inp.checked=!inp.checked;ico.classList.toggle('selected',inp.checked);}"
                 << "else{inp.checked=true;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;}"
                 << "if(!multi){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);}});"
@@ -2159,6 +2164,7 @@ namespace blogi {
                qEl->SetAttribute("id", q.id.c_str());
                qEl->SetAttribute("type", q.type.c_str());
                qEl->SetAttribute("required", q.required ? "true" : "false");
                if (q.multiSelect) qEl->SetAttribute("multiselect", "true");
                if (q.type == "rating") {
                    qEl->SetAttribute("min", q.ratingMin);
                    qEl->SetAttribute("max", q.ratingMax);
@@ -2202,6 +2208,8 @@ namespace blogi {
                json_object_object_add(jq, "type", json_object_new_string(q.type.c_str()));
                json_object_object_add(jq, "text", json_object_new_string(q.text.c_str()));
                json_object_object_add(jq, "required", json_object_new_boolean(q.required));
                if (q.multiSelect)
                    json_object_object_add(jq, "multiSelect", json_object_new_boolean(true));
                if (q.type == "rating") {
                    json_object_object_add(jq, "ratingMin", json_object_new_int(q.ratingMin));
                    json_object_object_add(jq, "ratingMax", json_object_new_int(q.ratingMax));
@@ -2258,6 +2266,8 @@ namespace blogi {
                    q.text = json_object_get_string(v);
                if (json_object_object_get_ex(jq, "required", &v))
                    q.required = json_object_get_boolean(v);
                if (json_object_object_get_ex(jq, "multiSelect", &v))
                    q.multiSelect = json_object_get_boolean(v);
                if (json_object_object_get_ex(jq, "ratingMin", &v))
                    q.ratingMin = json_object_get_int(v);
                if (json_object_object_get_ex(jq, "ratingMax", &v))
@@ -2639,6 +2649,7 @@ namespace blogi {
                 << "type:qe.querySelector('.se-qtype').value,"
                 << "text:qe.querySelector('.se-qtext').value,"
                 << "required:qe.querySelector('.se-qreq').checked,"
                 << "multiSelect:qe.querySelector('.se-qmulti')?qe.querySelector('.se-qmulti').checked:false,"
                 << "options:[]};"
                 << "if(q.type==='rating'){"
                 << "var minI=qe.querySelector('.se-rmin');var maxI=qe.querySelector('.se-rmax');"