<commit_before><script type="text/javascript" src="/portality/static/vendor/parsley-2.9.2/parsley.min.js?v={{config.get('DOAJ_VERSION')}}"></script>
<script type="text/javascript" src="/portality/static/vendor/edges/src/edges.js?v={{config.get('DOAJ_VERSION')}}"></script>
<!-- get select2 -->
<script type="text/javascript" src="/portality/static/vendor/select2-3.5.4/select2.min.js?v={{config.get('DOAJ_VERSION')}}"></script>
<link rel="stylesheet" type="text/css" href="/portality/static/vendor/select2-3.5.4/select2.css">
<link href='/portality/static/doaj/css/application_form.css' media='screen' rel='stylesheet' type='text/css' />
<script type="text/javascript" src="/portality/static/js/formulaic.js?v={{config.get('DOAJ_VERSION')}}"></script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
        formulaic.active = formulaic.newFormulaic({
            formSelector: "#{{ form_id }}",
            functions : {{ formulaic_context.javascript_functions|tojson }},
            doValidation : {% if js_validation %}true{% else %}false{% endif %},
            autoSave: {{ auto_save }},
            fieldsets : {{ formulaic_context.ui_settings|tojson }}
        });

    });

    window.Parsley.addValidator("requiredIf", {
        validateString : function(value, requirement, parsleyInstance) {
            let field = parsleyInstance.$element.attr("data-parsley-required-if-field");
            if ($('[name="' + field + '"]').filter(':checked').val() === requirement){
                return !!value;
            }
            return true;
        },
        messages: {
            en: 'This field is required, because you answered "%s" to the previous question.'
        },
        priority: 33
    })

    let showTab = (n) => {
        // This function will display the specified tab of the form ...
        //hide all other tabs
        if (n < sections.length-1){
            let hiddenField = $("#validated-" + n)
            if (hiddenField.val() === "") {
                hiddenField.val("False");
            }
        }

        tabs.each((idx, tab) => {
            $(tab).hide();
        });

        let submitButton = $("#submitBtn");
        let draftButton = $("#draftBtn");
        $(tabs[n]).show();
        $("#cannot_save_draft").hide();
        submitButton.hide();
        draftButton.show();
        // ... and fix the Previous/Next buttons:
        if (n === 0) {
            $("#prevBtn").hide();
        } else {
            $("#prevBtn").show();
        }

        if (n === (tabs.length - 1)) {
            //show submit button only if all tabs are validated
            $("#nextBtn").hide();
            submitButton.show();
            draftButton.show();
            let validated = form_validated();
            if (!validated) {
                $("#cannot-submit-invalid-fields").show();
            } else {
                $("#cannot-submit-invalid-fields").hide();
            }

        } else {
            let nextBtn = $("#nextBtn")
            nextBtn.show();
            nextBtn.html("Next");
            submitButton.hide();
            draftButton.show();
            submitButton.prop("disabled",false);
        }
        currentTab = n;
        previousTab = n-1;
        // ... and run a function that displays the correct step indicator:
        if(n === 6) {
            prepareReview()
        }
        fixStepIndicator(n)
        window.scrollTo(0,0);

    }

    let prepareReview = () => {
        let review_values = $("td[id$='__review_value']")
        review_values.each((idx, question) => {
            let id = $(question).attr('id')
            if (id === "apc_charges__review_value") {
                    let currency = $("select[id='apc_currency']").find('option:selected').val();
                    let max = $("input[name='apc_max']").val();
                    if (currency === undefined) {
                        currency = "";
                    }
                    if (max === undefined) {
                        max = "";
                    }

                    $(question).html(max + " " + currency);
            }
            else {
                let name = id.substring(0, id.indexOf("__review_value"));
                let input = $("input[name='" + name + "']");
                if (input.length === 0) {  //it's not input but select
                    input = $("[name^='" + name + "']");
                    let result = "";
                    input.each((idx, inp) => {
                        let val = $(inp).find('option:selected').text();
                        if (val !== "") {
                            result += val + ", ";
                        }

                    })
                    $(question).html(result);
                } else {
                    if (id === "keywords__review_value") {
                        let result = "";
                        input.each((idx, inp) => {
                            let val = $(inp).val();
                            if (val !== "") {
                                result += $(inp).val() + ", ";
                                if (idx < input.length - 1) {
                                    result += ", ";
                                }
                            }
                        });
                        $(question).html(result);
                    } else {
                        let type = input.attr("type");
                        if (type === "text" || type === "number") {
                            $(question).html(input.val())
                        } else if (type === "url") {
                            $(question).html('<a href=' + input.val() + '>' + input.val() + '</a>')
                        } else if (type === "radio") {
                            if (input.is(":checked")) {
                                let val = input.filter(':checked').val()
                                if (val === "y") {
                                    $(question).html("Yes");
                                } else if (val === "n") {
                                    $(question).html("No");
                                } else if (val === "") {
                                } else {
                                    $(question).html("Oops, something went wrong! You shouldn't see that, please contact support");
                                }

                            }
                        } else if (type === "checkbox") {
                            let result = ''
                            input.each((idx, i) => {
                                if ($(i).is(":checked")) {
                                    result += $(i).val() + ", ";
                                }
                            })
                            $(question).html(result)
                        }
                    }
                }
            }

        })
    }

    let form_validated = () => {
        let result = true;
        let inputs = $("[name^='validated']");
        $(inputs).each((idx, input) => {
            if (idx === inputs.length-1) {
                return result;
            }
            if ($(input).val() !== "True") {
                result = false;
                return;
            }
        });
        return result;
    }

    let next = () => {
        navigate(currentTab + 1);
    }

    let prev = () => {
        navigate(currentTab - 1);
    }

    let submitaplication = () => {
        let form = $("form");
        $(form).parsley().validate()
        form.submit()
    }

    let savedraft = () => {
        let form = $(".application_form");
        $(form).attr('novalidate', 'novalidate');
        let input = $("<input>")
               .attr("type", "hidden")
               .attr("name", "draft").val(true);
        let input2 = $("<input>")
               .attr("type", "hidden")
               .attr("name", "draft_id").val($(form).attr("id"));
        form.append($(input));
        form.append($(input2));
        let parsleyForm = $(form).parsley()
        parsleyForm.validate()
        let result = true;

        for (let i = 0; i < parsleyForm.fields.length; i++){
            let validationResult = parsleyForm.fields[i].validationResult;
            if (validationResult !== true){
                if (validationResult[0].assert.name !== 'required'){
                    $("#cannot_save_draft").show();
                    result = false;
                    break;

                }
            }
        }
        if (result) {
            $(form).off('form:validate');
            $("#cannot_save_draft").hide();
            parsleyForm._submit();
        }
    }

    let validate_tab = (tab) => {
        var form = $('#' + '{{ form_id }}');
        form.parsley().whenValidate({
            group: 'block-' + tab
        }).done(function () {
            $("#validated-" + tab).val("True");
        }).fail(function () {
            $("#validated-" + tab).val("False");
        });
    }

    let navigate = (n) => {
        // Hide the current tab:
        validate_tab(currentTab);
        $(tabs[currentTab]).hide();
        previousTab = n-1
        currentTab = n;
        // Otherwise, display the correct tab:
        showTab(currentTab);
    }


    let fixStepIndicator = (n) => {
        // This function removes the "active" class of all steps...
        $(".application-nav__list-item").each((idx, x) => {
            let hiddenField = $("#validated-" + idx);
            if (idx === n) {
                x.className = "application-nav__list-item application-nav__list-item--active";
            }
            else {
                if (hiddenField.val() === "True") {
                    x.className = "application-nav__list-item application-nav__list-item--done";
                } else if (hiddenField.val() === "False") {
                    x.className = "application-nav__list-item application-nav__list-item--invalid";
                }
                else {
                    x.className = "application-nav__list-item";
                }
            }
        });
        //... and adds the "active" class to the current step:

        $("#page_link-" + n).className = "page_link";
    }

    let usePaginationMenu = () => {
        $('[id^="page_link-"]').each((i, x) => {
            $(x).on("click", () => {
                if ($("#validated-" + i).val() === '') {
                    //dev only!
                    //navigate(i);
                    return false;
                } else {
                    navigate(i);
                }

            });
        });
    }

    let prepareSections = () => {
        sections.each((idx, section) => {

            $(section).find("input").each((i, input) => {
                $(input).attr('data-parsley-group', 'block-' + idx);
            });

            if (idx < sections.length){
                let hiddenInputs = $("[name='validated']");
                $(hiddenInputs[idx]).attr('id', 'validated-' + idx);
            }

        });

        $('[id^="page_link-"]').each((i, menu) =>  {
            $(menu).className = "page_link--disabled";
        });
    }

    let manage_review_checkboxes = () => {
        if ($("#understanding").prop("checked") && $("#reviewed").prop("checked")){
            $("#cannot-submit-checkboxes").hide();
            $("#submitBtn").prop("disabled", !form_validated());
        } else {
            $("#cannot-submit-checkboxes").show();
            $("#submitBtn").prop("disabled", true);
        }
    }

    $("#understanding").on("click", manage_review_checkboxes);
    $("#reviewed").on("click", manage_review_checkboxes);




    let currentTab = 0; // Current tab is set to be the first tab (0)
    let previousTab = 0;
    let tabs = $(".tab");
    let sections = $(".form-section");
    prepareSections();
    usePaginationMenu();
    navigate(currentTab); // Display the current tab
    {#$("#submitBtn").on("click",onSubmit);#}
    {#$("#draftBtn").on("click", saveDraft);#}

</script><commit_msg>add valueRequired validator<commit_after><script type="text/javascript" src="/portality/static/vendor/parsley-2.9.2/parsley.min.js?v={{config.get('DOAJ_VERSION')}}"></script>
<script type="text/javascript" src="/portality/static/vendor/edges/src/edges.js?v={{config.get('DOAJ_VERSION')}}"></script>
<!-- get select2 -->
<script type="text/javascript" src="/portality/static/vendor/select2-3.5.4/select2.min.js?v={{config.get('DOAJ_VERSION')}}"></script>
<link rel="stylesheet" type="text/css" href="/portality/static/vendor/select2-3.5.4/select2.css">
<link href='/portality/static/doaj/css/application_form.css' media='screen' rel='stylesheet' type='text/css' />
<script type="text/javascript" src="/portality/static/js/formulaic.js?v={{config.get('DOAJ_VERSION')}}"></script>
<script type="text/javascript">
    jQuery(document).ready(function($) {
        formulaic.active = formulaic.newFormulaic({
            formSelector: "#{{ form_id }}",
            functions : {{ formulaic_context.javascript_functions|tojson }},
            doValidation : {% if js_validation %}true{% else %}false{% endif %},
            autoSave: {{ auto_save }},
            fieldsets : {{ formulaic_context.ui_settings|tojson }}
        });

    });

    window.ParsleyConfig = {
        validators: {
            conditionalrequired: {
                fn: function (value, requirements) {
                    // if requirements[0] value does not meet requirements[1] expectation, field is required
                    if (requirements[1] === $(requirements[0]).val() && '' === value)
                        return false;

                    return true;
                },
                priority: 32
            },
            validateString : {
                fn: function(value, requirement, parsleyInstance) {
                    let field = parsleyInstance.$element.attr("data-parsley-required-if-field");
                    if ($('[name="' + field + '"]').filter(':checked').val() === requirement){
                        return !!value;
                    }
                    return true;
                },
                messages: {
                    en: 'This field is required, because you answered "%s" to the previous question.'
                },
                priority: 33}
        }
    };

    window.Parsley.addValidator("requiredIf", {

    })

    let showTab = (n) => {
        // This function will display the specified tab of the form ...
        //hide all other tabs
        if (n < sections.length-1){
            let hiddenField = $("#validated-" + n)
            if (hiddenField.val() === "") {
                hiddenField.val("False");
            }
        }

        tabs.each((idx, tab) => {
            $(tab).hide();
        });

        let submitButton = $("#submitBtn");
        let draftButton = $("#draftBtn");
        $(tabs[n]).show();
        $("#cannot_save_draft").hide();
        submitButton.hide();
        draftButton.show();
        // ... and fix the Previous/Next buttons:
        if (n === 0) {
            $("#prevBtn").hide();
        } else {
            $("#prevBtn").show();
        }

        if (n === (tabs.length - 1)) {
            //show submit button only if all tabs are validated
            $("#nextBtn").hide();
            submitButton.show();
            draftButton.show();
            let validated = form_validated();
            if (!validated) {
                $("#cannot-submit-invalid-fields").show();
            } else {
                $("#cannot-submit-invalid-fields").hide();
            }

        } else {
            let nextBtn = $("#nextBtn")
            nextBtn.show();
            nextBtn.html("Next");
            submitButton.hide();
            draftButton.show();
            submitButton.prop("disabled",false);
        }
        currentTab = n;
        previousTab = n-1;
        // ... and run a function that displays the correct step indicator:
        if(n === 6) {
            prepareReview()
        }
        fixStepIndicator(n)
        window.scrollTo(0,0);

    }

    let prepareReview = () => {
        let review_values = $("td[id$='__review_value']")
        review_values.each((idx, question) => {
            let id = $(question).attr('id')
            if (id === "apc_charges__review_value") {
                    let currency = $("select[id='apc_currency']").find('option:selected').val();
                    let max = $("input[name='apc_max']").val();
                    if (currency === undefined) {
                        currency = "";
                    }
                    if (max === undefined) {
                        max = "";
                    }

                    $(question).html(max + " " + currency);
            }
            else {
                let name = id.substring(0, id.indexOf("__review_value"));
                let input = $("input[name='" + name + "']");
                if (input.length === 0) {  //it's not input but select
                    input = $("[name^='" + name + "']");
                    let result = "";
                    input.each((idx, inp) => {
                        let val = $(inp).find('option:selected').text();
                        if (val !== "") {
                            result += val + ", ";
                        }

                    })
                    $(question).html(result);
                } else {
                    if (id === "keywords__review_value") {
                        let result = "";
                        input.each((idx, inp) => {
                            let val = $(inp).val();
                            if (val !== "") {
                                result += $(inp).val() + ", ";
                                if (idx < input.length - 1) {
                                    result += ", ";
                                }
                            }
                        });
                        $(question).html(result);
                    } else {
                        let type = input.attr("type");
                        if (type === "text" || type === "number") {
                            $(question).html(input.val())
                        } else if (type === "url") {
                            $(question).html('<a href=' + input.val() + '>' + input.val() + '</a>')
                        } else if (type === "radio") {
                            if (input.is(":checked")) {
                                let val = input.filter(':checked').val()
                                if (val === "y") {
                                    $(question).html("Yes");
                                } else if (val === "n") {
                                    $(question).html("No");
                                } else if (val === "") {
                                } else {
                                    $(question).html("Oops, something went wrong! You shouldn't see that, please contact support");
                                }

                            }
                        } else if (type === "checkbox") {
                            let result = ''
                            input.each((idx, i) => {
                                if ($(i).is(":checked")) {
                                    result += $(i).val() + ", ";
                                }
                            })
                            $(question).html(result)
                        }
                    }
                }
            }

        })
    }

    let form_validated = () => {
        let result = true;
        let inputs = $("[name^='validated']");
        $(inputs).each((idx, input) => {
            if (idx === inputs.length-1) {
                return result;
            }
            if ($(input).val() !== "True") {
                result = false;
                return;
            }
        });
        return result;
    }

    let next = () => {
        navigate(currentTab + 1);
    }

    let prev = () => {
        navigate(currentTab - 1);
    }

    let submitaplication = () => {
        let form = $("form");
        $(form).parsley().validate()
        form.submit()
    }

    let savedraft = () => {
        let form = $(".application_form");
        $(form).attr('novalidate', 'novalidate');
        let input = $("<input>")
               .attr("type", "hidden")
               .attr("name", "draft").val(true);
        let input2 = $("<input>")
               .attr("type", "hidden")
               .attr("name", "draft_id").val($(form).attr("id"));
        form.append($(input));
        form.append($(input2));
        let parsleyForm = $(form).parsley()
        parsleyForm.validate()
        let result = true;

        for (let i = 0; i < parsleyForm.fields.length; i++){
            let validationResult = parsleyForm.fields[i].validationResult;
            if (validationResult !== true){
                if (validationResult[0].assert.name !== 'required'){
                    $("#cannot_save_draft").show();
                    result = false;
                    break;

                }
            }
        }
        if (result) {
            $(form).off('form:validate');
            $("#cannot_save_draft").hide();
            parsleyForm._submit();
        }
    }

    let validate_tab = (tab) => {
        var form = $('#' + '{{ form_id }}');
        form.parsley().whenValidate({
            group: 'block-' + tab
        }).done(function () {
            $("#validated-" + tab).val("True");
        }).fail(function () {
            $("#validated-" + tab).val("False");
        });
    }

    let navigate = (n) => {
        // Hide the current tab:
        validate_tab(currentTab);
        $(tabs[currentTab]).hide();
        previousTab = n-1
        currentTab = n;
        // Otherwise, display the correct tab:
        showTab(currentTab);
    }


    let fixStepIndicator = (n) => {
        // This function removes the "active" class of all steps...
        $(".application-nav__list-item").each((idx, x) => {
            let hiddenField = $("#validated-" + idx);
            if (idx === n) {
                x.className = "application-nav__list-item application-nav__list-item--active";
            }
            else {
                if (hiddenField.val() === "True") {
                    x.className = "application-nav__list-item application-nav__list-item--done";
                } else if (hiddenField.val() === "False") {
                    x.className = "application-nav__list-item application-nav__list-item--invalid";
                }
                else {
                    x.className = "application-nav__list-item";
                }
            }
        });
        //... and adds the "active" class to the current step:

        $("#page_link-" + n).className = "page_link";
    }

    let usePaginationMenu = () => {
        $('[id^="page_link-"]').each((i, x) => {
            $(x).on("click", () => {
                if ($("#validated-" + i).val() === '') {
                    //dev only!
                    //navigate(i);
                    return false;
                } else {
                    navigate(i);
                }

            });
        });
    }

    let prepareSections = () => {
        sections.each((idx, section) => {

            $(section).find("input").each((i, input) => {
                $(input).attr('data-parsley-group', 'block-' + idx);
            });

            if (idx < sections.length){
                let hiddenInputs = $("[name='validated']");
                $(hiddenInputs[idx]).attr('id', 'validated-' + idx);
            }

        });

        $('[id^="page_link-"]').each((i, menu) =>  {
            $(menu).className = "page_link--disabled";
        });
    }

    let manage_review_checkboxes = () => {
        if ($("#understanding").prop("checked") && $("#reviewed").prop("checked")){
            $("#cannot-submit-checkboxes").hide();
            $("#submitBtn").prop("disabled", !form_validated());
        } else {
            $("#cannot-submit-checkboxes").show();
            $("#submitBtn").prop("disabled", true);
        }
    }

    $("#understanding").on("click", manage_review_checkboxes);
    $("#reviewed").on("click", manage_review_checkboxes);




    let currentTab = 0; // Current tab is set to be the first tab (0)
    let previousTab = 0;
    let tabs = $(".tab");
    let sections = $(".form-section");
    prepareSections();
    usePaginationMenu();
    navigate(currentTab); // Display the current tab
    {#$("#submitBtn").on("click",onSubmit);#}
    {#$("#draftBtn").on("click", saveDraft);#}

</script>
{'fraction_non_alphanumeric': 0.16879071084678562, 'fraction_numerical': 0.003236638750657442, 'mean_word_length': 1.3274952919020715, 'pattern_counts': {'":': 4, '<': 45, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '248991', 'n_tokens_mistral': 6662, 'n_tokens_neox': 6338, 'n_words': 1216}