<commit_before>/************************************
 *
 *  Copyright (c) 2014 AnsibleWorks, Inc.
 *
 *  Utility functions
 *
 */

/* jshint devel:true */

'use strict';

angular.module('Utilities', ['RestServices', 'Utilities'])

/*
 *  Place to remove things that might be lingering from a prior tab or view.
 *  This used to destroy the scope, but that causes issues in angular 1.2.x
 */
.factory('ClearScope', [ '$rootScope', function ($rootScope) {
    return function () {

        $rootScope.flashMessage = null;

        $('#form-modal .modal-body').empty();
        $('#form-modal2 .modal-body').empty();

        $('.tooltip').each(function () {
            $(this).remove();
        });

        $('.popover').each(function () {
            $(this).remove();
        });

        try {
            $('#help-modal').dialog('close');
        } catch (e) {
            // ignore
        }
        $(window).unbind('resize');
    };
}])


/* Empty()
 *
 * Test if a value is 'empty'. Returns true if val is null | '' | undefined.
 * Only works on non-Ojbect types.
 *
 */
.factory('Empty', [
    function () {
        return function (val) {
            return (val === null || val === undefined || val === '') ? true : false;
        };
    }
])


.factory('ToggleClass', function () {
    return function (selector, cssClass) {
        // Toggles the existance of a css class on a given element
        if ($(selector) && $(selector).hasClass(cssClass)) {
            $(selector).removeClass(cssClass);
        } else if ($(selector)) {
            $(selector).addClass(cssClass);
        }
    };
})


/*
 * Pass in the header and message you want displayed on TB modal dialog found in index.html.
 * Assumes an #id of 'alert-modal'. Pass in an optional TB alert class (i.e. alert-danger, alert-success,
 * alert-info...). Pass an optional function(){}, if you want a specific action to occur when user
 * clicks 'OK' button. Set secondAlert to true, when a second dialog is needed.
 */
.factory('Alert', ['$rootScope', '$compile', '$sce', function ($rootScope) {
    return function (hdr, msg, cls, action, secondAlert, disableButtons) {
        var scope = $rootScope.$new(), alertClass, e;
        if (secondAlert) {
            e = angular.element(document.getElementById('alert-modal2'));

            $('#alertHeader2').text(hdr);
            $('#alert2-modal-msg').text(msg);
            $("#alertHeader").text(msg);
            alertClass = (cls) ? cls : 'alert-danger'; //default alert class is alert-danger

            $('#alert2-modal-msg').attr({ "class": "alert " + alertClass });
            $('#alert-modal2').modal({
                show: true,
                keyboard: true,
                backdrop: 'static'
            });
            scope.disableButtons2 = (disableButtons) ? true : false;

            $('#alert-modal2').on('hidden.bs.modal', function () {
                if (action) {
                    action();
                }
            });
            $(document).bind('keydown', function (e) {
                if (e.keyCode === 27) {
                    $('#alert-modal2').modal('hide');
                }
            });
        } else {
            e = angular.element(document.getElementById('alert-modal'));

            $('#alertHeader').text(hdr);
            $('#alert-modal-msg').text(msg);
            alertClass = (cls) ? cls : 'alert-danger'; //default alert class is alert-danger
            $('#alert-modal-msg').attr({ "class": "alert " + alertClass });<commit_msg>fixed alert dialog box<commit_after>/************************************
 *
 *  Copyright (c) 2014 AnsibleWorks, Inc.
 *
 *  Utility functions
 *
 */

/* jshint devel:true */

'use strict';

angular.module('Utilities', ['RestServices', 'Utilities'])

/*
 *  Place to remove things that might be lingering from a prior tab or view.
 *  This used to destroy the scope, but that causes issues in angular 1.2.x
 */
.factory('ClearScope', [ '$rootScope', function ($rootScope) {
    return function () {

        $rootScope.flashMessage = null;

        $('#form-modal .modal-body').empty();
        $('#form-modal2 .modal-body').empty();

        $('.tooltip').each(function () {
            $(this).remove();
        });

        $('.popover').each(function () {
            $(this).remove();
        });

        try {
            $('#help-modal').dialog('close');
        } catch (e) {
            // ignore
        }
        $(window).unbind('resize');
    };
}])


/* Empty()
 *
 * Test if a value is 'empty'. Returns true if val is null | '' | undefined.
 * Only works on non-Ojbect types.
 *
 */
.factory('Empty', [
    function () {
        return function (val) {
            return (val === null || val === undefined || val === '') ? true : false;
        };
    }
])


.factory('ToggleClass', function () {
    return function (selector, cssClass) {
        // Toggles the existance of a css class on a given element
        if ($(selector) && $(selector).hasClass(cssClass)) {
            $(selector).removeClass(cssClass);
        } else if ($(selector)) {
            $(selector).addClass(cssClass);
        }
    };
})


/*
 * Pass in the header and message you want displayed on TB modal dialog found in index.html.
 * Assumes an #id of 'alert-modal'. Pass in an optional TB alert class (i.e. alert-danger, alert-success,
 * alert-info...). Pass an optional function(){}, if you want a specific action to occur when user
 * clicks 'OK' button. Set secondAlert to true, when a second dialog is needed.
 */
.factory('Alert', ['$rootScope', '$compile', '$sce', function ($rootScope) {
    return function (hdr, msg, cls, action, secondAlert, disableButtons) {
        var scope = $rootScope.$new(), alertClass, e;
        if (secondAlert) {
            e = angular.element(document.getElementById('alert-modal2'));

            $('#alertHeader2').html(hdr);
            $('#alert2-modal-msg').html(msg);

            alertClass = (cls) ? cls : 'alert-danger'; //default alert class is alert-danger

            $('#alert2-modal-msg').attr({ "class": "alert " + alertClass });
            $('#alert-modal2').modal({
                show: true,
                keyboard: true,
                backdrop: 'static'
            });
            scope.disableButtons2 = (disableButtons) ? true : false;

            $('#alert-modal2').on('hidden.bs.modal', function () {
                if (action) {
                    action();
                }
            });
            $(document).bind('keydown', function (e) {
                if (e.keyCode === 27) {
                    $('#alert-modal2').modal('hide');
                }
            });
        } else {
            e = angular.element(document.getElementById('alert-modal'));

            $('#alertHeader').html(hdr);
            $('#alert-modal-msg').html(msg);
            alertClass = (cls) ? cls : 'alert-danger'; //default alert class is alert-danger
            $('#alert-modal-msg').attr({ "class": "alert " + alertClass });
{'fraction_non_alphanumeric': 0.17746759720837488, 'fraction_numerical': 0.004842615012106538, 'mean_word_length': 2.0650371017023135, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '4425349', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1916, 'n_words': 522}