diff --git a/awx/ui/static/js/controllers/Jobs.js b/awx/ui/static/js/controllers/Jobs.js index a2bc6d7c11..6befd935e2 100644 --- a/awx/ui/static/js/controllers/Jobs.js +++ b/awx/ui/static/js/controllers/Jobs.js @@ -11,7 +11,7 @@ 'use strict'; function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBreadCrumbs, LoadScope, RunningJobsList, CompletedJobsList, QueuedJobsList, - ScheduledJobsList, GetChoices, GetBasePath, Wait, DeleteJob, ToggleScheduleEnabled, Find) { + ScheduledJobsList, GetChoices, GetBasePath, Wait, DeleteJob, Find, DeleteSchedule, ToggleSchedule) { ClearScope(); @@ -75,14 +75,12 @@ function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBrea url: GetBasePath('schedules') }); - if (scheduled_scope.removeScheduleToggled) { - scheduled_scope.removeScheduleToggled(); + if (scheduled_scope.removeSchedulesRefresh) { + scheduled_scope.removeSchedulesRefresh(); } - scheduled_scope.removeScheduleToggled = function(e, id) { - //scheduled_scope.search(ScheduledJobsList.iterator); - var schedule = Find({ list: scheduled_scope[ScheduledJobsList.name], key: 'id', val: id}); - schedule.enabled = (schedule.enabled) ? false : true; - }; + scheduled_scope.removeSchedulesRefresh = scheduled_scope.$on('SchedulesRefresh', function() { + scheduled_scope.search(ScheduledJobsList.iterator); + }); completed_scope.deleteJob = function(id) { DeleteJob({ scope: completed_scope, id: id }); @@ -97,9 +95,18 @@ function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBrea }; scheduled_scope.toggleSchedule = function(id) { - ToggleScheduleEnabled({ + ToggleSchedule({ scope: scheduled_scope, - id: id + id: id, + callback: 'SchedulesRefresh' + }); + }; + + scheduled_scope.deleteSchedule = function(id) { + DeleteSchedule({ + scope: scheduled_scope, + id: id, + callback: 'SchedulesRefresh' }); }; @@ -136,7 +143,7 @@ function JobsListController ($scope, $compile, ClearScope, Breadcrumbs, LoadBrea } JobsListController.$inject = ['$scope', '$compile', 'ClearScope', 'Breadcrumbs', 'LoadBreadCrumbs', 'LoadScope', 'RunningJobsList', 'CompletedJobsList', - 'QueuedJobsList', 'ScheduledJobsList', 'GetChoices', 'GetBasePath', 'Wait', 'DeleteJob', 'ToggleScheduleEnabled', 'Find']; + 'QueuedJobsList', 'ScheduledJobsList', 'GetChoices', 'GetBasePath', 'Wait', 'DeleteJob', 'Find', 'DeleteSchedule', 'ToggleSchedule']; function JobsEdit($scope, $rootScope, $compile, $location, $log, $routeParams, JobForm, JobTemplateForm, GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit, RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, diff --git a/awx/ui/static/js/controllers/Schedules.js b/awx/ui/static/js/controllers/Schedules.js index 4334dbc133..962b1d3f37 100644 --- a/awx/ui/static/js/controllers/Schedules.js +++ b/awx/ui/static/js/controllers/Schedules.js @@ -11,7 +11,7 @@ 'use strict'; function ScheduleEdit($scope, $compile, $location, $routeParams, SchedulesList, GenerateList, Rest, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope, -GetBasePath, LookUpInit, Wait, SchedulerInit, Breadcrumbs, SearchInit, PaginateInit, PageRangeSetup, EditSchedule, AddSchedule, Find, ToggleSchedule) { +GetBasePath, LookUpInit, Wait, SchedulerInit, Breadcrumbs, SearchInit, PaginateInit, PageRangeSetup, EditSchedule, AddSchedule, Find, ToggleSchedule, DeleteSchedule) { ClearScope(); @@ -125,12 +125,12 @@ GetBasePath, LookUpInit, Wait, SchedulerInit, Breadcrumbs, SearchInit, PaginateI AddSchedule({ scope: $scope, schedule: schedule, url: url }); }; - if ($scope.removeScheduleToggled) { - $scope.removeScheduleToggled(); + if ($scope.removeScheduleRefresh) { + $scope.removeScheduleRefresh(); } - $scope.removeScheduleToggled = function() { + $scope.removeScheduleToggled = $scope.$on('ScheduleRefresh', function() { $scope.search(SchedulesList.iterator); - }; + }); $scope.toggleSchedule = function(id) { ToggleSchedule({ @@ -140,6 +140,22 @@ GetBasePath, LookUpInit, Wait, SchedulerInit, Breadcrumbs, SearchInit, PaginateI }); }; + $scope.toggleSchedule = function(id) { + ToggleSchedule({ + scope: $scope, + id: id, + callback: 'SchedulesRefresh' + }); + }; + + $scope.deleteSchedule = function(id) { + DeleteSchedule({ + scope: $scope, + id: id, + callback: 'SchedulesRefresh' + }); + }; + // Load the parent object id = $routeParams.id; Rest.setUrl(GetBasePath(base) + id); @@ -156,5 +172,5 @@ GetBasePath, LookUpInit, Wait, SchedulerInit, Breadcrumbs, SearchInit, PaginateI ScheduleEdit.$inject = ['$scope', '$compile', '$location', '$routeParams', 'SchedulesList', 'GenerateList', 'Rest', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope', 'GetBasePath', 'LookUpInit', 'Wait', 'SchedulerInit', 'Breadcrumbs', 'SearchInit', 'PaginateInit', 'PageRangeSetup', 'EditSchedule', 'AddSchedule', -'Find', 'ToggleSchedule' +'Find', 'ToggleSchedule', 'DeleteSchedule' ]; \ No newline at end of file diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index b0b0fc90a8..833283b3cf 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -326,8 +326,9 @@ angular.module('GroupsHelper', ['RestServices', 'Utilities', 'ListGenerator', 'G * */ .factory('ScheduleList', ['ScheduleEdit', 'SchedulesList', 'GenerateList', 'SearchInit', 'PaginateInit', 'Rest', 'PageRangeSetup', -'Wait', 'ProcessErrors', 'Find', -function(ScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Rest, PageRangeSetup, Wait, ProcessErrors, Find) { +'Wait', 'ProcessErrors', 'Find', 'ToggleSchedule', 'DeleteSchedule', +function(ScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Rest, PageRangeSetup, Wait, ProcessErrors, Find, +ToggleSchedule, DeleteSchedule) { return function(params) { var parent_scope = params.scope, schedule_scope = parent_scope.$new(), @@ -406,6 +407,30 @@ function(ScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Re schedule_scope.addSchedule = function() { ScheduleEdit({ scope: parent_scope, schedule: {}, mode: 'add'}); }; + + if (schedule_scope.removeSchedulesRefresh) { + schedule_scope.removeSchedulesRefresh(); + } + schedule_scope.removeSchedulesRefresh = schedule_scope.$on('SchedulesRefresh', function() { + schedule_scope.search(SchedulesList.iterator); + }); + + schedule_scope.toggleSchedule = function(id) { + ToggleSchedule({ + scope: schedule_scope, + id: id, + callback: 'SchedulesRefresh' + }); + }; + + schedule_scope.deleteSchedule = function(id) { + DeleteSchedule({ + scope: schedule_scope, + id: id, + callback: 'SchedulesRefresh' + }); + }; + }; }]) diff --git a/awx/ui/static/js/helpers/Jobs.js b/awx/ui/static/js/helpers/Jobs.js index 50851813a5..693ef6e496 100644 --- a/awx/ui/static/js/helpers/Jobs.js +++ b/awx/ui/static/js/helpers/Jobs.js @@ -9,7 +9,7 @@ 'use strict'; -angular.module('JobsHelper', ['Utilities', 'FormGenerator', 'JobSummaryDefinition', 'InventoryHelper', 'GeneratorHelpers', 'SchedulesHelper']) +angular.module('JobsHelper', ['Utilities', 'FormGenerator', 'JobSummaryDefinition', 'InventoryHelper', 'GeneratorHelpers']) .factory('JobStatusToolTip', [ function () { @@ -326,17 +326,4 @@ function(Find, GetBasePath, Rest, Wait, ProcessErrors, Prompt){ }); }; -}]) - -.factory('ToggleScheduleEnabled', ['ToggleSchedule', function(ToggleSchedule) { - return function(params) { - var scope = params.scope, - id = params.id; - ToggleSchedule({ - scope: scope, - id: id, - callback: 'ScheduleToggled' - }); - }; }]); - diff --git a/awx/ui/static/js/helpers/Schedules.js b/awx/ui/static/js/helpers/Schedules.js index 38eea7f05a..aebdb14151 100644 --- a/awx/ui/static/js/helpers/Schedules.js +++ b/awx/ui/static/js/helpers/Schedules.js @@ -262,6 +262,60 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) msg: 'Failed to retrieve schedule ' + id + ' GET returned: ' + status }); }); }; + }]) + + /** + * Delete a schedule. Prompts user to confirm delete + * + * DeleteSchedule({ + * scope: $scope containing list of schedules + * id: id of schedule to delete + * callback: $scope.$emit label to call when delete is completed + * }) + * + */ + .factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find', + function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find) { + return function(params) { + + var scope = params.scope, + id = params.id, + callback = params.callback, + action, schedule, list, url, hdr; + + if (scope.schedules) { + list = scope.schedules; + } + else if (scope.scheduled_jobs) { + list = scope.scheduled_jobs; + } + + url = GetBasePath('schedules') + id + '/'; + schedule = Find({list: list, key: 'id', val: id }); + hdr = 'Delete Schedule'; + + action = function () { + Wait('start'); + Rest.setUrl(url); + Rest.destroy() + .success(function () { + $('#prompt-modal').modal('hide'); + scope.$emit(callback, id); + }) + .error(function (data, status) { + $('#prompt-modal').modal('hide'); + ProcessErrors(scope, data, status, null, { hdr: 'Error!', msg: 'Call to ' + url + + ' failed. DELETE returned: ' + status }); + }); + }; + + Prompt({ + hdr: hdr, + body: "
Are you sure you want to delete the " + schedule.name + " schedule?
", + action: action + }); + + }; }]); @@ -278,3 +332,54 @@ angular.module('SchedulesHelper', ['Utilities', 'SchedulesHelper']) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/awx/ui/static/js/lists/ScheduledJobs.js b/awx/ui/static/js/lists/ScheduledJobs.js index 077dac295b..c0663213c9 100644 --- a/awx/ui/static/js/lists/ScheduledJobs.js +++ b/awx/ui/static/js/lists/ScheduledJobs.js @@ -67,13 +67,13 @@ angular.module('ScheduledJobsDefinition', []) }, "edit": { mode: "all", - ngClick: "edit(scheduled_job.id)", + ngClick: "editSchedule(scheduled_job.id)", awToolTip: "Edit the schedule", dataPlacement: "top" }, "delete": { mode: 'all', - ngClick: 'deleteJob(completed_job.id)', + ngClick: 'deleteSchedule(scheduled_job.id)', awToolTip: 'Delete the schedule', dataPlacement: 'top' }