<commit_before>function init() {
    var form = document.getElementById("question");
    form.onsubmit = function (e) {
        // stop the regular form submission
        e.preventDefault();
    };
}

function handleSubmit(submitButtonName) {
    var form = document.getElementById("question");
    // collect the form data while iterating over the inputs
    var data = {};
    for (var i = 0, ii = form.length; i < ii; ++i) {
        var input = form[i];
        if (input.name) {
            if (input.type !== "radio" || input.checked) {
                data[input.name] = input.value;
            }
        }
    }
    console.log(JSON.stringify(data));
    var request = new Object();
    if (data["id"] !== undefined) {
        request.id = data["id"];
        if (submitButtonName == "Vorige") {
            request.back = true;
        } else {
            request.name = data["name"];
            request.type = data["type"];
            request.value = data["value"];
        }
    }
    console.log("Request: " + JSON.stringify(request));
    // construct an HTTP request
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === XMLHttpRequest.DONE) {
            console.log(xhr.responseText);
            clearNode();
            if (xhr.responseText == "<html><body><h2>500 Internal Error</h2></body></html>") {
                document.getElementById("question").appendChild(document.createTextNode("An error occured on the server side"));
                return;
            }
            var response = JSON.parse(xhr.responseText);
            if (response.type === "inquiry") {
                setQuestion(response);
            } else {
                setResult(response);
            }
        }
    };
    xhr.open(form.method, form.action, true);
    xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

    // send the collected data as JSON
    xhr.send(JSON.stringify(request));

    xhr.onloadend = function () {
        //Done
    };
}

function setQuestion(response) {
    console.log(response.knowledge.origin);
    document.getElementById("question").appendChild(document.createTextNode(response.knowledge.question));
    document.getElementById("question").appendChild(document.createElement("br"));
    setInput("hidden", "id", response.id);
    setInput("hidden", "type", response.knowledge.type);
    setInput("hidden", "name", response.knowledge.name);
    if (response.knowledge.origin === "CHOICESELECTION") {
        for (var i = 0; i < response.knowledge.options.length; i++) {
            node = setInput("radio", "value", response.knowledge.options[i]);
            node.setAttribute("id", response.knowledge.options[i]);
            if (i == 0) {
                node.setAttribute("checked", "checked");
            }
            var label = document.createElement("label");
            label.appendChild(document.createTextNode(response.knowledge.options[i]));
            label.setAttribute("for", response.knowledge.options[i]);
            document.getElementById("question").appendChild(label);
            document.getElementById("question").appendChild(document.createElement("br"));
        }
        //setChoiceSelection(response.knowledge.options);
    }
    document.getElementById("question").appendChild(document.createElement("br"));
    node = setInput("submit", "Submit1", "Vorige");
    node.setAttribute("onclick", "handleSubmit(\"Vorige\");");
    node = setInput("submit", "Submit2", "Volgende");
    node.setAttribute("onclick", "handleSubmit(\"Volgende\");");
    if (response.knowledge.tip) {
        document.getElementById("tipContent").appendChild(document.createTextNode(response.knowledge.tip));<commit_msg>added multiplechoiceselection support on site side<commit_after>function init() {
    var form = document.getElementById("question");
    form.onsubmit = function (e) {
        // stop the regular form submission
        e.preventDefault();
    };
}

function handleSubmit(submitButtonName) {
    var form = document.getElementById("question");
    // collect the form data while iterating over the inputs
    var data = {};
    for (var i = 0, ii = form.length; i < ii; ++i) {
        var input = form[i];
        if (input.name) {
            if (input.type !== "radio" || input.checked) {
                data[input.name] = input.value;
            }
        }
    }
    console.log(JSON.stringify(data));
    var request = new Object();
    if (data["id"] !== undefined) {
        request.id = data["id"];
        if (submitButtonName == "Vorige") {
            request.back = true;
        } else {
            request.name = data["name"];
            request.type = data["type"];
            request.value = data["value"];
        }
    }
    console.log("Request: " + JSON.stringify(request));
    // construct an HTTP request
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function () {
        if (xhr.readyState === XMLHttpRequest.DONE) {
            console.log(xhr.responseText);
            clearNode();
            if (xhr.responseText == "<html><body><h2>500 Internal Error</h2></body></html>") {
                document.getElementById("question").appendChild(document.createTextNode("An error occured on the server side"));
                return;
            }
            var response = JSON.parse(xhr.responseText);
            if (response.type === "inquiry") {
                setQuestion(response);
            } else {
                setResult(response);
            }
        }
    };
    xhr.open(form.method, form.action, true);
    xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

    // send the collected data as JSON
    xhr.send(JSON.stringify(request));

    xhr.onloadend = function () {
        //Done
    };
}

function setQuestion(response) {
    console.log(response.knowledge.origin);
    document.getElementById("question").appendChild(document.createTextNode(response.knowledge.question));
    document.getElementById("question").appendChild(document.createElement("br"));
    setInput("hidden", "id", response.id);
    setInput("hidden", "type", response.knowledge.type);
    setInput("hidden", "name", response.knowledge.name);
    if (response.knowledge.origin === "CHOICESELECTION") {
        for (var i = 0; i < response.knowledge.options.length; i++) {
            node = setInput("radio", "value", response.knowledge.options[i]);
            node.setAttribute("id", response.knowledge.options[i]);
            if (i == 0) {
                node.setAttribute("checked", "checked");
            }
            var label = document.createElement("label");
            label.appendChild(document.createTextNode(response.knowledge.options[i]));
            label.setAttribute("for", response.knowledge.options[i]);
            document.getElementById("question").appendChild(label);
            document.getElementById("question").appendChild(document.createElement("br"));
        }
        //setChoiceSelection(response.knowledge.options);
    }
    if (response.knowledge.origin === "MULTIPLECHOICESELECTION") {
        for (var i = 0; i < response.knowledge.options.length; i++) {
            node = setInput("checkbox", "value", response.knowledge.options[i]);
            node.setAttribute("id", response.knowledge.options[i]);
            if (i == 0) {
                node.setAttribute("checked", "checked");
            }
            var label = document.createElement("label");
            label.appendChild(document.createTextNode(response.knowledge.options[i]));
            label.setAttribute("for", response.knowledge.options[i]);
            document.getElementById("question").appendChild(label);
            document.getElementById("question").appendChild(document.createElement("br"));
        }
        //setChoiceSelection(response.knowledge.options);
    }
    document.getElementById("question").appendChild(document.createElement("br"));
    node = setInput("submit", "Submit1", "Vorige");
    node.setAttribute("onclick", "handleSubmit(\"Vorige\");");
    node = setInput("submit", "Submit2", "Volgende");
    node.setAttribute("onclick", "handleSubmit(\"Volgende\");");
    if (response.knowledge.tip) {
        document.getElementById("tipContent").appendChild(document.createTextNode(response.knowledge.tip));
{'fraction_non_alphanumeric': 0.1514862122478214, 'fraction_numerical': 0.002864987465679838, 'mean_word_length': 2.645778938207137, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6391580', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2196, 'n_words': 408}