<commit_before>/*
 * Kuali Coeus, a comprehensive research administration system for higher education.
 * 
 * Copyright 2005-2015 Kuali, Inc.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var Kc = Kc || {};
Kc.Global = Kc.Global || {};
(function (namespace, $) {
    // set all modals to static behavior (clicking out does not close)
    $.fn.modal.Constructor.DEFAULTS.backdrop = "static";

    $(document).on("ready", function(){
        // date conversion for date fields to full leading 0 - for days and months and to full year dates
        $(document).on("blur", ".uif-dateControl", function(){
            var dateFormat = $.datepicker._defaults.dateFormat;
            var date = $(this).val();
            if (!date) {
                return;
            }

            date = date.replace(/-/g, "/");

            if (date && (date.match(/\//g) || []).length === 2) {

                // find the expected position and value of year in the string based on date format
                var year;
                if (dateFormat.indexOf("y") === 0) {
                    year = date.substr(0, date.indexOf("/"));
                }
                else {
                    year = date.substr(date.lastIndexOf("/") + 1, date.length - 1);
                }

                // when year is length of 2 append the first 2 numbers of the current full year (ie 14 -> 2014)
                if (year.length === 2) {
                    var currentDate = new Date();
                    year = currentDate.getFullYear().toString().substr(0,2) + year;
                }

                var dateObj = new Date(date);
                if (isNaN(dateObj.valueOf())) {
                    // not valid abandon conversion
                    return;
                }

                dateObj.setFullYear(year);

                var formattedDate = $.datepicker.formatDate(dateFormat, dateObj);
                $(this).val(formattedDate);
            }
        });
    });

    namespace.attachRedirectHandler = function() {
        $(window).unbind("message.redirect");
        $(window).on("message.redirect", function (event) {
            if (event.originalEvent.data && event.originalEvent.data.indexOf("redirect:") === 0) {
                var location = event.originalEvent.data.substr(9);
                window.location.replace(location);
                return false;
            }
        });
    }
    namespace.makeApplicationFooterSticky = function() {
        var docHeight = $(window).height();
        var footerHeight = $('#Uif-ApplicationFooter-Wrapper').height();
        var footerTop = $('#Uif-ApplicationFooter-Wrapper').position().top + footerHeight;

        if (footerTop < docHeight) {<commit_msg>KRACOEUS-8899:fixed client side date validation<commit_after>/*
 * Kuali Coeus, a comprehensive research administration system for higher education.
 * 
 * Copyright 2005-2015 Kuali, Inc.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var Kc = Kc || {};
Kc.Global = Kc.Global || {};
(function (namespace, $) {
    // set all modals to static behavior (clicking out does not close)
    $.fn.modal.Constructor.DEFAULTS.backdrop = "static";

    $(document).on("ready", function(){
        $.validator.addMethod("kcValidateDate", function(value,element){
            return this.optional(element) || namespace.validateDate(value);
        },"Invalid Date");
        $(".uif-dateControl").each(function() {
            //make sure all date inputs check for valid dates, in case they are never focused
            $(this).rules("add",{kcValidateDate: true});
        });
        $(document).on("focus", ".uif-dateControl", function(){
            //if a date input is added after document ready event.
                $(this).rules("add",{kcValidateDate: true});
        });
        // date conversion for date fields to full leading 0 - for days and months and to full year dates
        $(document).on("blur", ".uif-dateControl", function(){
            var dateFormat = $.datepicker._defaults.dateFormat;
            var date = $(this).val();
            if (!date) {
                return;
            }

            date = date.replace(/-/g, "/");

            if (date && (date.match(/\//g) || []).length === 2) {

                // find the expected position and value of year in the string based on date format
                var year;
                if (dateFormat.indexOf("y") === 0) {
                    year = date.substr(0, date.indexOf("/"));
                }
                else {
                    year = date.substr(date.lastIndexOf("/") + 1, date.length - 1);
                }

                // when year is length of 2 append the first 2 numbers of the current full year (ie 14 -> 2014)
                if (year.length === 2) {
                    var currentDate = new Date();
                    year = currentDate.getFullYear().toString().substr(0,2) + year;
                }

                if (!namespace.validateDate(date)) {
                    return;
                }

                var dateObj = new Date(date);
                dateObj.setFullYear(year);

                var formattedDate = $.datepicker.formatDate(dateFormat, dateObj);
                $(this).val(formattedDate);
            }
        });
    });
    namespace.validateDate = function(value) {
        var dateFormat = $.datepicker._defaults.dateFormat;
        var date = value.replace(/-/g, "/");

        if (date && (date.match(/\//g) || []).length === 2) {
            // find the expected position and value of year in the string based on date format
            var year;
            var month;
            var day;
            if (dateFormat.indexOf("y") === 0) {
                year = date.substr(0, date.indexOf("/"));
                month = "0" + date.substr(date.indexOf("/")+1,date.lastIndexOf("/") - date.indexOf("/")-1)
                day = "0" + date.substr(date.lastIndexOf("/") + 1, date.length - 1);
            }
            else {
                month = "0" +  date.substr(0, date.indexOf("/"));
                day ="0" +  date.substr(date.indexOf("/")+1,date.lastIndexOf("/") - date.indexOf("/")-1)
                year = date.substr(date.lastIndexOf("/") + 1, date.length - 1);
            }

            if (year.length === 2) {
                var currentDate = new Date();
                year = currentDate.getFullYear().toString().substr(0,2) + year;
            }

            var isoDate = year + "-" + month.substr(month.length-2,2) + "-" + day.substr(day.length-2,2);
            if (isNaN(new Date(isoDate))) {
                return false;
            }
            return true
        }
        return false
    }
    namespace.attachRedirectHandler = function() {
        $(window).unbind("message.redirect");
        $(window).on("message.redirect", function (event) {
            if (event.originalEvent.data && event.originalEvent.data.indexOf("redirect:") === 0) {
                var location = event.originalEvent.data.substr(9);
                window.location.replace(location);
                return false;
            }
        });
    }
    namespace.makeApplicationFooterSticky = function() {
        var docHeight = $(window).height();
        var footerHeight = $('#Uif-ApplicationFooter-Wrapper').height();
        var footerTop = $('#Uif-ApplicationFooter-Wrapper').position().top + footerHeight;

        if (footerTop < docHeight) {
{'fraction_non_alphanumeric': 0.12914746543778802, 'fraction_numerical': 0.00956221198156682, 'mean_word_length': 1.9101575595038551, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4550553', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2191, 'n_words': 692}