<commit_before>(function(){
    "use strict";

    /**
     * 
     * @ngdoc service
     * @name openlmis-core.Alert
     * @description
     * Service allows to display alert modal with custom message.
     *
     */

    angular.module('openlmis-core')
        .service('Alert', Alert);

    Alert.$inject = ['$timeout', '$q', '$rootScope', '$compile', '$templateRequest', '$templateCache', 'bootbox', 'messageService'];

    function Alert($timeout, $q, $rootScope, $compile, $templateRequest, $templateCache, bootbox, messageService) {

        /**
         *
         * @ngdoc function
         * @name warning
         * @methodOf openlmis-core.Alert
         * @param {String} message Primary message to display at the top
         * @param {String} additionalMessage Additional message to display below
         * @return {Promise} alert promise
         * 
         * @description
         * Shows warning modal with custom message and returns promise.
         *
         */
        function warning(message, additionalMessage) {
            var deferred = $q.defer();
            showAlert('glyphicon-alert', deferred.resolve, message, additionalMessage);
            return deferred.promise;
        }

        /**
         *
         * @ngdoc function
         * @name error
         * @methodOf openlmis-core.Alert
         * @param {String} message Message to display
         * @param {String} callback Function called after closing alert
         * 
         * @description
         * Shows alert modal with custom message and calls callback after closing alert.
         *
         */
        function error(message, callback) {
            showAlert('glyphicon-remove-circle', callback, messageService.get(message));
        }

        function showAlert(alertClass, callback, message, additionalMessage) {

            var templateURL = 'common/alert.html',
                template = $templateCache.get(templateURL);

            if (template){
                makeAlert(template);
            } else {
                $templateRequest(templateURL).then(makeAlert);
            }

            function makeAlert(html) {

                var alert, 
                    scope = $rootScope.$new();

                scope.icon = alertClass;
                scope.message = messageService.get(message);
                if (additionalMessage) scope.additionalMessage = messageService.get(additionalMessage);

                alert = bootbox.dialog({
                    message: $compile(html)(scope),
                    callback: callback,
                    backdrop: true,
                    onEscape: callback,
                    closeButton: false,
                    className: 'alert-modal'
                });
                alert.on('click.bs.modal', function(){
                    callback();
                    alert.modal('hide');
                });
                alert.on('hidden.bs.modal', function(){
                    angular.element(document.querySelector('.alert-modal')).remove();
                });
            }
            
        }<commit_msg>OLMIS-1345: fixed alert call if callback is not defined<commit_after>(function(){
    "use strict";

    /**
     *
     * @ngdoc service
     * @name openlmis-core.Alert
     * @description
     * Service allows to display alert modal with custom message.
     *
     */

    angular.module('openlmis-core')
        .service('Alert', Alert);

    Alert.$inject = ['$timeout', '$q', '$rootScope', '$compile', '$templateRequest', '$templateCache', 'bootbox', 'messageService'];

    function Alert($timeout, $q, $rootScope, $compile, $templateRequest, $templateCache, bootbox, messageService) {

        /**
         *
         * @ngdoc function
         * @name warning
         * @methodOf openlmis-core.Alert
         * @param {String} message Primary message to display at the top
         * @param {String} additionalMessage Additional message to display below
         * @return {Promise} alert promise
         *
         * @description
         * Shows warning modal with custom message and returns promise.
         *
         */
        function warning(message, additionalMessage) {
            var deferred = $q.defer();
            showAlert('glyphicon-alert', deferred.resolve, message, additionalMessage);
            return deferred.promise;
        }

        /**
         *
         * @ngdoc function
         * @name error
         * @methodOf openlmis-core.Alert
         * @param {String} message Message to display
         * @param {String} callback Function called after closing alert
         *
         * @description
         * Shows alert modal with custom message and calls callback after closing alert.
         *
         */
        function error(message, callback) {
            showAlert('glyphicon-remove-circle', callback, messageService.get(message));
        }

        function showAlert(alertClass, callback, message, additionalMessage) {

            var templateURL = 'common/alert.html',
                template = $templateCache.get(templateURL);

            if (template){
                makeAlert(template);
            } else {
                $templateRequest(templateURL).then(makeAlert);
            }

            function makeAlert(html) {

                var alert,
                    scope = $rootScope.$new();

                scope.icon = alertClass;
                scope.message = messageService.get(message);
                if (additionalMessage) scope.additionalMessage = messageService.get(additionalMessage);

                alert = bootbox.dialog({
                    message: $compile(html)(scope),
                    callback: callback,
                    backdrop: true,
                    onEscape: callback,
                    closeButton: false,
                    className: 'alert-modal'
                });
                alert.on('click.bs.modal', function(){
                    if(callback) callback();
                    alert.modal('hide');
                });
                alert.on('hidden.bs.modal', function(){
                    angular.element(document.querySelector('.alert-modal')).remove();
                });
            }

        }
{'fraction_non_alphanumeric': 0.10649558941459503, 'fraction_numerical': 0.0006415396952686447, 'mean_word_length': 1.659275053304904, 'pattern_counts': {'":': 0, '<': 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': '4884016', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1425, 'n_words': 363}