From 1a9b60a1998145b0bba4d5943b66a1f7cf9526fa Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 14 May 2018 14:55:32 -0400 Subject: [PATCH 1/2] Delete the survey if the user removes all the survey questions --- .../src/partials/survey-maker-modal.html | 2 +- .../survey-maker/surveys/add.factory.js | 2 ++ .../survey-maker/surveys/edit.factory.js | 1 + .../survey-maker/surveys/init.factory.js | 21 +++++++++++-------- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/awx/ui/client/src/partials/survey-maker-modal.html b/awx/ui/client/src/partials/survey-maker-modal.html index 5385a14b28..c73a9dec77 100644 --- a/awx/ui/client/src/partials/survey-maker-modal.html +++ b/awx/ui/client/src/partials/survey-maker-modal.html @@ -84,7 +84,7 @@ - + diff --git a/awx/ui/client/src/templates/survey-maker/surveys/add.factory.js b/awx/ui/client/src/templates/survey-maker/surveys/add.factory.js index 3773e1ede9..51ac98c3fc 100644 --- a/awx/ui/client/src/templates/survey-maker/surveys/add.factory.js +++ b/awx/ui/client/src/templates/survey-maker/surveys/add.factory.js @@ -7,6 +7,8 @@ export default // modal title. We want this toggle to be on by default scope.survey_enabled = true; + scope.initiallyHadQuestions = false; + if (scope.removeDialogReady) { scope.removeDialogReady(); } diff --git a/awx/ui/client/src/templates/survey-maker/surveys/edit.factory.js b/awx/ui/client/src/templates/survey-maker/surveys/edit.factory.js index 790822e628..c40f4751d3 100644 --- a/awx/ui/client/src/templates/survey-maker/surveys/edit.factory.js +++ b/awx/ui/client/src/templates/survey-maker/surveys/edit.factory.js @@ -37,6 +37,7 @@ export default scope.survey_name = data.name; scope.survey_description = data.description; scope.survey_questions = data.spec; + scope.initiallyHadQuestions = true; Wait('stop'); } else { AddSurvey({ diff --git a/awx/ui/client/src/templates/survey-maker/surveys/init.factory.js b/awx/ui/client/src/templates/survey-maker/surveys/init.factory.js index 3a13f4f70c..f3f7d09e84 100644 --- a/awx/ui/client/src/templates/survey-maker/surveys/init.factory.js +++ b/awx/ui/client/src/templates/survey-maker/surveys/init.factory.js @@ -109,15 +109,18 @@ export default }); }; - updateSurveyQuestions() - .then(function() { - return updateSurveyEnabled(); - }) - .then(function() { - scope.closeSurvey('survey-modal-dialog'); - scope.$emit('SurveySaved'); - }); - + if (!scope.survey_questions || scope.survey_questions.length === 0) { + scope.deleteSurvey(); + } else { + updateSurveyQuestions() + .then(function() { + return updateSurveyEnabled(); + }) + .then(function() { + scope.closeSurvey('survey-modal-dialog'); + scope.$emit('SurveySaved'); + }); + } }; // Gets called when the user clicks the on/off toggle beside the survey modal title. From bfc602ae106cd62e8cbe5a03f8b5ee77bf68d95f Mon Sep 17 00:00:00 2001 From: mabashian Date: Mon, 14 May 2018 14:58:29 -0400 Subject: [PATCH 2/2] Changed variable names --- awx/ui/client/src/partials/survey-maker-modal.html | 2 +- awx/ui/client/src/templates/survey-maker/surveys/add.factory.js | 2 +- .../client/src/templates/survey-maker/surveys/edit.factory.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/partials/survey-maker-modal.html b/awx/ui/client/src/partials/survey-maker-modal.html index c73a9dec77..b6acbe2ab3 100644 --- a/awx/ui/client/src/partials/survey-maker-modal.html +++ b/awx/ui/client/src/partials/survey-maker-modal.html @@ -84,7 +84,7 @@ - + diff --git a/awx/ui/client/src/templates/survey-maker/surveys/add.factory.js b/awx/ui/client/src/templates/survey-maker/surveys/add.factory.js index 51ac98c3fc..eef26fa5d6 100644 --- a/awx/ui/client/src/templates/survey-maker/surveys/add.factory.js +++ b/awx/ui/client/src/templates/survey-maker/surveys/add.factory.js @@ -7,7 +7,7 @@ export default // modal title. We want this toggle to be on by default scope.survey_enabled = true; - scope.initiallyHadQuestions = false; + scope.isEditSurvey = false; if (scope.removeDialogReady) { scope.removeDialogReady(); diff --git a/awx/ui/client/src/templates/survey-maker/surveys/edit.factory.js b/awx/ui/client/src/templates/survey-maker/surveys/edit.factory.js index c40f4751d3..90d2c734ce 100644 --- a/awx/ui/client/src/templates/survey-maker/surveys/edit.factory.js +++ b/awx/ui/client/src/templates/survey-maker/surveys/edit.factory.js @@ -37,7 +37,7 @@ export default scope.survey_name = data.name; scope.survey_description = data.description; scope.survey_questions = data.spec; - scope.initiallyHadQuestions = true; + scope.isEditSurvey = true; Wait('stop'); } else { AddSurvey({