diff --git a/awx/ui/static/js/helpers/Survey.js b/awx/ui/static/js/helpers/Survey.js index b3bebf0b8e..37a4d77b99 100644 --- a/awx/ui/static/js/helpers/Survey.js +++ b/awx/ui/static/js/helpers/Survey.js @@ -321,8 +321,10 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', } html += '
'; - html += ' '; - html += ' '; + html += ' '; + html += ' '; html += ' '; html += ' '; html+='
'; @@ -337,6 +339,13 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', $('#add_question_btn').show(); $('#add_question_btn').removeAttr('disabled'); $('#survey_maker_save_btn').removeAttr('disabled'); + + $('#delete-question_'+question.index+'').on('click', function($event){ + scope.deleteQuestion($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); + }); + $('#edit-question_'+question.index+'').on('click', function($event){ + scope.editQuestion($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); + }); }; }]) @@ -349,10 +358,10 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', index = params.index, element, fld, i, form = SurveyQuestionForm; - - + $('#add_question_btn').hide(); + $('#new_question .aw-form-well').remove(); element = $('.question_final:eq('+index+')'); - element.attr('id', 'question_'+index); + // element.attr('id', 'question_'+index); element.empty(); // $('#new_question .aw-form-well').remove(); GenerateForm.inject(form, { id: 'question_'+index, mode: 'edit' , scope:scope, breadCrumbs: false}); @@ -370,16 +379,31 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', }; }]) + .factory('DeleteQuestion' , + function() { + return function(params) { + + var scope = params.scope, + index = params.index, + element; + + element = $('.question_final:eq('+index+')'); + // element.attr('id', 'question_'+index); + element.remove(); + scope.survey_questions.splice(index, 1); + scope.reorder(); + }; + }) + .factory('SurveyControllerInit', ['$location', 'DeleteSurvey', 'EditSurvey', 'AddSurvey', 'GenerateForm', 'SurveyQuestionForm', 'Wait', 'Alert', - 'GetBasePath', 'Rest', 'ProcessErrors' , '$compile', 'FinalizeQuestion', 'EditQuestion', + 'GetBasePath', 'Rest', 'ProcessErrors' , '$compile', 'FinalizeQuestion', 'EditQuestion', 'DeleteQuestion', function($location, DeleteSurvey, EditSurvey, AddSurvey, GenerateForm, SurveyQuestionForm, Wait, Alert, - GetBasePath, Rest, ProcessErrors, $compile, FinalizeQuestion, EditQuestion) { + GetBasePath, Rest, ProcessErrors, $compile, FinalizeQuestion, EditQuestion, DeleteQuestion) { return function(params) { var scope = params.scope, // parent_scope = params.parent_scope, id = params.id, - // element, i, - url; + i, url; // iterator = (params.iterator) ? params.iterator : scope.iterator, // base = $location.path().replace(/^\//, '').split('/')[0]; @@ -419,6 +443,7 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', GenerateForm.inject(SurveyQuestionForm, { id:'new_question', mode: 'add' , scope:scope, breadCrumbs: false}); scope.required = true; //set the required checkbox to true via the ngmodel attached to scope.required. }; + scope.editQuestion = function(index){ EditQuestion({ index: index, @@ -426,6 +451,21 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', }); }; + scope.deleteQuestion = function(index){ + DeleteQuestion({ + index:index, + scope: scope + }); + }; + + scope.reorder = function(){ + for(i=0; i