<commit_before>/**
 * Created by ruslan on 20.07.16.
 */
$(document).ready(function () {

    //enough default message
    $.validator.addMethod("selectMinOptions", function (value, element, param) {

            var counter = 0;
            $('#' + element.id + " option:visible").each(function (index, option) {
                if ($(option).is(':selected')) {
                    counter++;
                }
            });
            return counter >= param;

        },

        "Choose {0} or more options");

    //need write message manual
    $.validator.addMethod("checkboxesInspection", function (value, element, param) {
            var name = $(element).attr("name");
            var checkboxes = document.getElementsByName(name);
            var flag = true;
            $(checkboxes).each(function (index, checkbox) {
                var textOfCheckbox = $("label[for=" + checkbox.id + "]").text();
                if (param.indexOf(textOfCheckbox) != -1) {
                    if (!$(checkbox).is(":checked")) {

                        flag = false;
                        return flag;
                    }
                }
            });

            return flag;
        }
    );

    if ($('#clientUpdateForm').length) {

        $('#clientUpdateForm').validate({

                rules: {

                    name: {
                        required: true,
                        minlength: 4
                    },

                    resourceIds: {
                        required: true,
                        minlength: 4
                    },

                    clientSecret: {
                        required: true,
                        minlength: 4
                    },

                    scope: {
                        required: true,
                        checkboxesInspection: ["read", "write"]
                    },

                    authorizedGrantTypes: {
                        selectMinOptions: 1
                    },

                    registeredRedirectUri: {
                        required: true,
                        url: true
                    },

                    roles: {
                        required: true,
                        checkboxesInspection: ["ROLE_USER"]
                    },

                    accessTokenValiditySeconds: {
                        required: true,
                        number: true,
                        digits: true,
                        min: 90
                    },

                    refreshTokenValiditySeconds: {
                        required: true,
                        number: true,
                        digits: true,
                        min: 180
                    }

                },

                messages: {

                    name: {
                        required: "Name is required",
                        minlength: "Minimum must be {0} characters"
                    },

                    resourceIds: {
                        required: "Resources is required",
                        minlength: "Minimum must be {0} characters"
                    },

                    clientSecret: {
                        required: "Secret is required",
                        minlength: "Minimum must be {0} characters"
                    },

                    scope: {
                        required: "Scope is required",
                        checkboxesInspection: "Need choose read, write"
                    },

                    registeredRedirectUri: {
                        required: "Registered Redirect Uri is required",
                        url: "URL not valid"
                    },

                    roles: {
                        required: "Roles is required",
                        checkboxesInspection: "ROLE_USER need check"
                    },

                    accessTokenValiditySeconds: {
                        required: "Access Token Validity(sec) is required",
                        number: "Must be number",
                        digits: "Must be natural number",
                        min: "Minimum {0} seconds"
                    },

                    refreshTokenValiditySeconds: {
                        required: "Refresh Token Validity(sec) is required",
                        number: "Must be number",
                        digits: "Must be natural number",
                        min: "Minimum {0} seconds"
                    }

                },

                errorPlacement: function (error, element) {
                    if ($(element).is(":checkbox")) {
                        error.insertAfter(element.parent().parent())
                    } else {
                        error.insertAfter(element);
                    }
                }


            }
        );

        selectAndHideOptions("authorizedGrantTypes", ["refresh_token"]);
    }

    if ($('#userUpdateForm').length) {

        $('#userUpdateForm').validate({
            rules: {

                username: {
                    required: true,
                    minlength: 4
                },

                password: {
                    required: true,
                    minlength: 8<commit_msg>update user password input -> empty<commit_after>/**
 * Created by ruslan on 20.07.16.
 */
$(document).ready(function () {

    //enough default message
    $.validator.addMethod("selectMinOptions", function (value, element, param) {

            var counter = 0;
            $('#' + element.id + " option:visible").each(function (index, option) {
                if ($(option).is(':selected')) {
                    counter++;
                }
            });
            return counter >= param;

        },

        "Choose {0} or more options");

    //need write message manual
    $.validator.addMethod("checkboxesInspection", function (value, element, param) {
            var name = $(element).attr("name");
            var checkboxes = document.getElementsByName(name);
            var flag = true;
            $(checkboxes).each(function (index, checkbox) {
                var textOfCheckbox = $("label[for=" + checkbox.id + "]").text();
                if (param.indexOf(textOfCheckbox) != -1) {
                    if (!$(checkbox).is(":checked")) {

                        flag = false;
                        return flag;
                    }
                }
            });

            return flag;
        }
    );

    if ($('#clientUpdateForm').length) {

        $('#clientUpdateForm').validate({

                rules: {

                    name: {
                        required: true,
                        minlength: 4
                    },

                    resourceIds: {
                        required: true,
                        minlength: 4
                    },

                    clientSecret: {
                        required: true,
                        minlength: 4
                    },

                    scope: {
                        required: true,
                        checkboxesInspection: ["read", "write"]
                    },

                    authorizedGrantTypes: {
                        selectMinOptions: 1
                    },

                    registeredRedirectUri: {
                        required: true,
                        url: true
                    },

                    roles: {
                        required: true,
                        checkboxesInspection: ["ROLE_USER"]
                    },

                    accessTokenValiditySeconds: {
                        required: true,
                        number: true,
                        digits: true,
                        min: 90
                    },

                    refreshTokenValiditySeconds: {
                        required: true,
                        number: true,
                        digits: true,
                        min: 180
                    }

                },

                messages: {

                    name: {
                        required: "Name is required",
                        minlength: "Minimum must be {0} characters"
                    },

                    resourceIds: {
                        required: "Resources is required",
                        minlength: "Minimum must be {0} characters"
                    },

                    clientSecret: {
                        required: "Secret is required",
                        minlength: "Minimum must be {0} characters"
                    },

                    scope: {
                        required: "Scope is required",
                        checkboxesInspection: "Need choose read, write"
                    },

                    registeredRedirectUri: {
                        required: "Registered Redirect Uri is required",
                        url: "URL not valid"
                    },

                    roles: {
                        required: "Roles is required",
                        checkboxesInspection: "ROLE_USER need check"
                    },

                    accessTokenValiditySeconds: {
                        required: "Access Token Validity(sec) is required",
                        number: "Must be number",
                        digits: "Must be natural number",
                        min: "Minimum {0} seconds"
                    },

                    refreshTokenValiditySeconds: {
                        required: "Refresh Token Validity(sec) is required",
                        number: "Must be number",
                        digits: "Must be natural number",
                        min: "Minimum {0} seconds"
                    }

                },

                errorPlacement: function (error, element) {
                    if ($(element).is(":checkbox")) {
                        error.insertAfter(element.parent().parent())
                    } else {
                        error.insertAfter(element);
                    }
                }


            }
        );

        selectAndHideOptions("authorizedGrantTypes", ["refresh_token"]);
    }

    if ($('#userUpdateForm').length) {

        $("#password").val("");

        $('#userUpdateForm').validate({
            rules: {

                username: {
                    required: true,
                    minlength: 4
                },

                password: {
                    required: true,
                    minlength: 8
{'fraction_non_alphanumeric': 0.09257327136488666, 'fraction_numerical': 0.004742483164184767, 'mean_word_length': 0.8569918985558295, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 6, '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': '7660333', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2068, 'n_words': 514}