diff --git a/awx/ui/static/js/helpers/Survey.js b/awx/ui/static/js/helpers/Survey.js index eab1b11e0a..f1be6ad953 100644 --- a/awx/ui/static/js/helpers/Survey.js +++ b/awx/ui/static/js/helpers/Survey.js @@ -72,7 +72,9 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', }]) .factory('EditSurvey', ['$routeParams','SchedulerInit', 'ShowSurveyModal', 'Wait', 'Rest', 'ProcessErrors', 'GetBasePath', 'GenerateForm', 'SurveyMakerForm', - function($routeParams, SchedulerInit, ShowSurveyModal, Wait, Rest, ProcessErrors, GetBasePath, GenerateForm,SurveyMakerForm) { + 'Empty', 'AddSurvey', + function($routeParams, SchedulerInit, ShowSurveyModal, Wait, Rest, ProcessErrors, GetBasePath, GenerateForm,SurveyMakerForm, + Empty, AddSurvey) { return function(params) { var scope = params.scope, id = params.id, @@ -150,19 +152,24 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', Rest.setUrl(url); Rest.get() .success(function (data) { - // var i; - generator.inject(form, { id: 'survey-modal-dialog' , mode: 'edit', related: false, scope: scope, breadCrumbs: false }); - ShowSurveyModal({ title: "Edit Survey", scope: scope, callback: 'DialogReady' }); + if(!Empty(data)){ + generator.inject(form, { id: 'survey-modal-dialog' , mode: 'edit', related: false, scope: scope, breadCrumbs: false }); + ShowSurveyModal({ title: "Edit Survey", scope: scope, callback: 'DialogReady' }); - scope.survey_name = data.name; - scope.survey_description = data.description; - scope.survey_questions = data.spec; - for(i=0; iAre you sure you want to delete the " + schedule.name + " schedule?", - action: action, - backdrop: false + scope.$on('SurveyDeleted', function(){ + Wait('stop'); + $('#job_templates_delete_survey_btn').hide(); + $('#job_templates_edit_survey_btn').hide(); + $('#job_templates_create_survey_btn').show(); }); + + Wait('start'); + // scope.deleteSurvey = function() { + // $location.path($location.path() + '/survey/add'); + if(scope.mode==="add"){ + scope.survey_name = ""; + scope.survey_description = ""; + scope.survey_questions = []; + scope.$emit("SurveyDeleted"); + + } else { + url = GetBasePath('job_templates')+ id + '/survey_spec/'; + + Rest.setUrl(url); + Rest.post({}) + .success(function () { + scope.$emit("SurveyDeleted"); + + }) + .error(function (data, status) { + ProcessErrors(scope, data, status, { hdr: 'Error!', + msg: 'Failed to add new survey. Post returned status: ' + status }); + }); + } }; }]) @@ -455,11 +459,11 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', ]; scope.deleteSurvey = function() { - // DeleteSchedule({ - // scope: scope, - // id: id, - // callback: 'SchedulesRefresh' - // }); + DeleteSurvey({ + scope: scope, + id: id, + // callback: 'SchedulesRefresh' + }); }; scope.editSurvey = function() {