diff --git a/awx/ui/static/js/helpers/Survey.js b/awx/ui/static/js/helpers/Survey.js index 37a4d77b99..c54c282656 100644 --- a/awx/ui/static/js/helpers/Survey.js +++ b/awx/ui/static/js/helpers/Survey.js @@ -321,12 +321,10 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', } html += '
'; - html += ' '; - html += ' '; - html += ' '; - html += ' '; + html += ' '; + html += ' '; + html += ' '; + html += ' '; html+='
'; $('#question_'+question.index).append(html); @@ -346,6 +344,12 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', $('#edit-question_'+question.index+'').on('click', function($event){ scope.editQuestion($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); }); + $('#question-up_'+question.index+'').on('click', function($event){ + scope.questionUp($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); + }); + $('#question-down_'+question.index+'').on('click', function($event){ + scope.questionDown($event.target.parentElement.parentElement.parentElement.id.split('_')[1]); + }); }; }]) @@ -458,6 +462,66 @@ angular.module('SurveyHelper', [ 'Utilities', 'RestServices', 'SchedulesHelper', }); }; + scope.questionUp = function(index){ + var animating = false, + clickedDiv = $('#question_'+index), + prevDiv = clickedDiv.prev(), + distance = clickedDiv.outerHeight(); + + if (animating) { + return; + } + + if (prevDiv.length) { + animating = true; + $.when(clickedDiv.animate({ + top: -distance + }, 600), + prevDiv.animate({ + top: distance + }, 600)).done(function () { + prevDiv.css('top', '0px'); + clickedDiv.css('top', '0px'); + clickedDiv.insertBefore(prevDiv); + animating = false; + i = scope.survey_questions[index]; + scope.survey_questions[index] = scope.survey_questions[index-1]; + scope.survey_questions[index-1] = i; + scope.reorder(); + }); + } + }; + + scope.questionDown = function(index){ + var clickedDiv = $('#question_'+index), + nextDiv = clickedDiv.next(), + distance = clickedDiv.outerHeight(), + animating = false; + + if (animating) { + return; + } + + if (nextDiv.length) { + animating = true; + $.when(clickedDiv.animate({ + top: distance + }, 600), + nextDiv.animate({ + top: -distance + }, 600)).done(function () { + nextDiv.css('top', '0px'); + clickedDiv.css('top', '0px'); + nextDiv.insertBefore(clickedDiv); + animating = false; + i = scope.survey_questions[index]; + scope.survey_questions[index] = scope.survey_questions[Number(index)+1]; + scope.survey_questions[Number(index)+1] = i; + scope.reorder(); + }); + } + }; + scope.reorder = function(){ for(i=0; i