<commit_before>/*********************************************
 *  Copyright (c) 2014 AnsibleWorks, Inc.
 */
    /**
 * @ngdoc function
 * @name helpers.function:Schedules
 * @description
 *  Schedules Helper
 *
 *  Display the scheduler widget in a dialog
 *
 */

'use strict';

angular.module('ConfigureTowerHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', 'SearchHelper', 'PaginationHelpers', 'ListGenerator', 'ModalDialog',
    'GeneratorHelpers'])

    .factory('ConfigureTower', ['Wait', 'CreateDialog', 'ConfigureTowerJobsList', 'GenerateList', 'GetBasePath' , 'SearchInit' , 'PaginateInit', 'PlaybookRun', 'LoadSchedulesScope',
        'SchedulesList', 'SchedulesControllerInit' , 'ConfigureTowerSchedule', 'Rest' , 'ProcessErrors',
        function(Wait, CreateDialog, ConfigureTowerJobsList, GenerateList, GetBasePath, SearchInit, PaginateInit, PlaybookRun, LoadSchedulesScope,
            SchedulesList, SchedulesControllerInit, ConfigureTowerSchedule, Rest, ProcessErrors) {
        return function(params) {
            // Set modal dimensions based on viewport width

            var scope = params.scope.$new(),
                parent_scope = params.scope,
                callback = 'OpenConfig',
                defaultUrl = GetBasePath('system_job_templates'),
                list = ConfigureTowerJobsList,
                view = GenerateList,
                scheduleUrl = GetBasePath('system_job_templates'),
                buttons = [
                {
                    "label": "Close",
                    "onClick": function() {
                        // $(this).dialog('close');
                        scope.cancelConfigure();
                    },
                    "icon": "fa-times",
                    "class": "btn btn-default",
                    "id": "configure-close-button"
                }
            ];

            scope.cleanupJob = true;

            if(scope.removeOpenConfig) {
                scope.removeOpenConfig();
            }
            scope.removeOpenConfig = scope.$on('OpenConfig', function() {
                $('#configure-tower-dialog').dialog('open');
                $('#configure-close-button').focus();
                $('#configure-close-button').blur();
            });

            view.inject( list, {
                id : 'configure-jobs',
                mode: 'edit',
                scope: scope,
                breadCrumbs: false,
                showSearch: false
            });

            SearchInit({
                scope: scope,
                set: 'configure_jobs',
                list: list,
                url: defaultUrl
            });
            PaginateInit({
                scope: scope,
                list: list,
                url: defaultUrl
            });

            scope.search(list.iterator);

            SchedulesControllerInit({
                scope: scope,
                parent_scope: parent_scope,
                // list: list
            });


            CreateDialog({
                id: 'configure-tower-dialog',
                title: 'Management Jobs',
                target: 'configure-tower-dialog',
                scope: scope,
                buttons: buttons,
                width: 670,
                height: 800,
                minWidth: 400,
                callback: callback,
                onClose: function () {
                    // Destroy on close
                    $('.tooltip').each(function () {
                        // Remove any lingering tooltip <div> elements
                        $(this).remove();
                    });
                    $('.popover').each(function () {
                        // remove lingering popover <div> elements
                        $(this).remove();
                    });
                    $("#configure-jobs").show();
                    $("#configure-schedules-form-container").hide();
                    $('#configure-schedules-list').empty();
                    $('#configure-schedules-form').empty();
                    $('#configure-schedules-detail').empty();
                    $('#configure-tower-dialog').hide();
                    $(this).dialog('destroy');
                    scope.cancelConfigure();
                },
            });



             // Cancel
            scope.cancelConfigure = function () {
                try {
                    $('#configure-tower-dialog').dialog('close');
                }
                catch(e) {
                    //ignore
                }
                if (scope.searchCleanup) {
                    scope.searchCleanup();
                }
                // if (!Empty(parent_scope) && parent_scope.restoreSearch) {
                //     parent_scope.restoreSearch();
                // }
                else {
                    Wait('stop');
                }
            };

            scope.submitJob = function (id) {
                Wait('start');
                defaultUrl = GetBasePath('system_job_templates')+id+'/launch/';
                CreateDialog({
                    id: 'prompt-for-days'    ,
                    title: "Cleanup Job",
                    scope: scope,
                    width: 500,
                    height: 300,
                    minWidth: 200,
                    callback: 'PromptForDays',
                    onOpen: function(){
                        $("#days_to_keep").val(30);
                    },
                    buttons: [{
                        "label": "Cancel",
                        "onClick": function() {
                            $(this).dialog('close');

                        },
                        "icon": "fa-times",
                        "class": "btn btn-default",
                        "id": "prompt-for-days-button"
                    },{
                        "label": "Launch",
                        "onClick": function() {
                            var extra_vars = {"days": $("#days_to_keep").val() },
                            data = {};
                            data.extra_vars = JSON.stringify(extra_vars);

                            Rest.setUrl(defaultUrl);
                            Rest.post(data)
                                .success(function() {
                                    Wait('stop');
                                    $("#prompt-for-days").dialog("close");
                                    $("#configure-tower-dialog").dialog('close');
                                })
                                .error(function(data, status) {
                                    ProcessErrors(scope, data, status, null, { hdr: 'Error!',
                                        msg: 'Failed updating job ' + scope.job_template_id + ' with variables. PUT returned: ' + status });
                                });
                        },
                        "icon":  "fa-rocket",
                        "class": "btn btn-primary",
                        "id": "prompt-for-days-button"
                    }]
                });

                if (scope.removePromptForDays) {
                    scope.removePromptForDays();
                }
                scope.removePromptForDays = scope.$on('PromptForDays', function() {
                    // $('#configure-tower-dialog').dialog('close');
                    $('#prompt-for-days').show();
                    $('#prompt-for-days').dialog('open');
                    Wait('stop');
                });



            };

            scope.configureSchedule = function(id, name) {
                Rest.setUrl(scheduleUrl+id+'/schedules/');
                Rest.get()
                    .success(function(data) {<commit_msg>Cleanup jobs redirect to jobs page<commit_after>/*********************************************
 *  Copyright (c) 2014 AnsibleWorks, Inc.
 */
    /**
 * @ngdoc function
 * @name helpers.function:Schedules
 * @description
 *  Schedules Helper
 *
 *  Display the scheduler widget in a dialog
 *
 */

'use strict';

angular.module('ConfigureTowerHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', 'SearchHelper', 'PaginationHelpers', 'ListGenerator', 'ModalDialog',
    'GeneratorHelpers'])

    .factory('ConfigureTower', ['Wait', '$location' , 'CreateDialog', 'ConfigureTowerJobsList', 'GenerateList', 'GetBasePath' , 'SearchInit' , 'PaginateInit', 'PlaybookRun', 'LoadSchedulesScope',
        'SchedulesList', 'SchedulesControllerInit' , 'ConfigureTowerSchedule', 'Rest' , 'ProcessErrors',
        function(Wait, $location, CreateDialog, ConfigureTowerJobsList, GenerateList, GetBasePath, SearchInit, PaginateInit, PlaybookRun, LoadSchedulesScope,
            SchedulesList, SchedulesControllerInit, ConfigureTowerSchedule, Rest, ProcessErrors) {
        return function(params) {
            // Set modal dimensions based on viewport width

            var scope = params.scope.$new(),
                parent_scope = params.scope,
                callback = 'OpenConfig',
                defaultUrl = GetBasePath('system_job_templates'),
                list = ConfigureTowerJobsList,
                view = GenerateList,
                scheduleUrl = GetBasePath('system_job_templates'),
                buttons = [
                {
                    "label": "Close",
                    "onClick": function() {
                        // $(this).dialog('close');
                        scope.cancelConfigure();
                    },
                    "icon": "fa-times",
                    "class": "btn btn-default",
                    "id": "configure-close-button"
                }
            ];

            scope.cleanupJob = true;

            if(scope.removeOpenConfig) {
                scope.removeOpenConfig();
            }
            scope.removeOpenConfig = scope.$on('OpenConfig', function() {
                $('#configure-tower-dialog').dialog('open');
                $('#configure-close-button').focus();
                $('#configure-close-button').blur();
            });

            view.inject( list, {
                id : 'configure-jobs',
                mode: 'edit',
                scope: scope,
                breadCrumbs: false,
                showSearch: false
            });

            SearchInit({
                scope: scope,
                set: 'configure_jobs',
                list: list,
                url: defaultUrl
            });
            PaginateInit({
                scope: scope,
                list: list,
                url: defaultUrl
            });

            scope.search(list.iterator);

            SchedulesControllerInit({
                scope: scope,
                parent_scope: parent_scope,
                // list: list
            });


            CreateDialog({
                id: 'configure-tower-dialog',
                title: 'Management Jobs',
                target: 'configure-tower-dialog',
                scope: scope,
                buttons: buttons,
                width: 670,
                height: 800,
                minWidth: 400,
                callback: callback,
                onClose: function () {
                    // Destroy on close
                    $('.tooltip').each(function () {
                        // Remove any lingering tooltip <div> elements
                        $(this).remove();
                    });
                    $('.popover').each(function () {
                        // remove lingering popover <div> elements
                        $(this).remove();
                    });
                    $("#configure-jobs").show();
                    $("#configure-schedules-form-container").hide();
                    $('#configure-schedules-list').empty();
                    $('#configure-schedules-form').empty();
                    $('#configure-schedules-detail').empty();
                    $('#configure-tower-dialog').hide();
                    $(this).dialog('destroy');
                    scope.cancelConfigure();
                },
            });



             // Cancel
            scope.cancelConfigure = function () {
                try {
                    $('#configure-tower-dialog').dialog('close');
                }
                catch(e) {
                    //ignore
                }
                if (scope.searchCleanup) {
                    scope.searchCleanup();
                }
                // if (!Empty(parent_scope) && parent_scope.restoreSearch) {
                //     parent_scope.restoreSearch();
                // }
                else {
                    Wait('stop');
                }
            };

            scope.submitJob = function (id) {
                Wait('start');
                defaultUrl = GetBasePath('system_job_templates')+id+'/launch/';
                CreateDialog({
                    id: 'prompt-for-days'    ,
                    title: "Cleanup Job",
                    scope: scope,
                    width: 500,
                    height: 300,
                    minWidth: 200,
                    callback: 'PromptForDays',
                    onOpen: function(){
                        $("#days_to_keep").val(30);
                    },
                    buttons: [{
                        "label": "Cancel",
                        "onClick": function() {
                            $(this).dialog('close');

                        },
                        "icon": "fa-times",
                        "class": "btn btn-default",
                        "id": "prompt-for-days-button"
                    },{
                        "label": "Launch",
                        "onClick": function() {
                            var extra_vars = {"days": $("#days_to_keep").val() },
                            data = {};
                            data.extra_vars = JSON.stringify(extra_vars);

                            Rest.setUrl(defaultUrl);
                            Rest.post(data)
                                .success(function() {
                                    Wait('stop');
                                    $("#prompt-for-days").dialog("close");
                                    $("#configure-tower-dialog").dialog('close');
                                    $location.path('/jobs/');
                                })
                                .error(function(data, status) {
                                    ProcessErrors(scope, data, status, null, { hdr: 'Error!',
                                        msg: 'Failed updating job ' + scope.job_template_id + ' with variables. PUT returned: ' + status });
                                });
                        },
                        "icon":  "fa-rocket",
                        "class": "btn btn-primary",
                        "id": "prompt-for-days-button"
                    }]
                });

                if (scope.removePromptForDays) {
                    scope.removePromptForDays();
                }
                scope.removePromptForDays = scope.$on('PromptForDays', function() {
                    // $('#configure-tower-dialog').dialog('close');
                    $('#prompt-for-days').show();
                    $('#prompt-for-days').dialog('open');
                    Wait('stop');
                });



            };

            scope.configureSchedule = function(id, name) {
                Rest.setUrl(scheduleUrl+id+'/schedules/');
                Rest.get()
                    .success(function(data) {
{'fraction_non_alphanumeric': 0.1280550553125804, 'fraction_numerical': 0.0030872137895549268, 'mean_word_length': 1.0992304576751721, 'pattern_counts': {'":': 32, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1776906', 'n_tokens_mistral': 3767, 'n_tokens_neox': 3392, 'n_words': 616}