Merge pull request #1783 from mabashian/1513-delete-last-survey-q

Delete the survey if the user removes all the survey questions
This commit is contained in:
Michael Abashian 2018-05-14 16:07:19 -04:00 committed by GitHub
commit 406d82b99c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 10 deletions

View File

@ -84,7 +84,7 @@
<button id="survey-delete-button" class="btn btn-sm SurveyMaker-deleteButton" ng-show="survey_exists && (job_template_obj.summary_fields.user_capabilities.edit || workflow_job_template_obj.summary_fields.user_capabilities.edit || canAdd)" ng-click="showDeleteOverlay('survey')" translate>DELETE SURVEY</button>
<button id="survey-close-button" class="btn btn-sm Form-buttonDefault" ng-click="closeSurvey('survey-modal-dialog')" ng-show="(job_template_obj.summary_fields.user_capabilities.edit || workflow_job_template_obj.summary_fields.user_capabilities.edit || canAdd)" translate>CANCEL</button>
<button id="survey-close-button" class="btn btn-sm Form-buttonDefault" ng-click="closeSurvey('survey-modal-dialog')" ng-show="!(job_template_obj.summary_fields.user_capabilities.edit || workflow_job_template_obj.summary_fields.user_capabilities.edit || canAdd)" translate>CLOSE</button>
<button id="survey-save-button" class="btn btn-sm Form-saveButton" ng-click="saveSurvey()" ng-disabled="survey_questions.length < 1 || !can_edit || editQuestionIndex !== null" ng-show="(job_template_obj.summary_fields.user_capabilities.edit || workflow_job_template_obj.summary_fields.user_capabilities.edit || canAdd)" translate>SAVE</button>
<button id="survey-save-button" class="btn btn-sm Form-saveButton" ng-click="saveSurvey()" ng-disabled="(!isEditSurvey && survey_questions.length < 1) || !can_edit || editQuestionIndex !== null" ng-show="(job_template_obj.summary_fields.user_capabilities.edit || workflow_job_template_obj.summary_fields.user_capabilities.edit || canAdd)" translate>SAVE</button>
</div>
</div>
</div>

View File

@ -7,6 +7,8 @@ export default
// modal title. We want this toggle to be on by default
scope.survey_enabled = true;
scope.isEditSurvey = false;
if (scope.removeDialogReady) {
scope.removeDialogReady();
}

View File

@ -37,6 +37,7 @@ export default
scope.survey_name = data.name;
scope.survey_description = data.description;
scope.survey_questions = data.spec;
scope.isEditSurvey = true;
Wait('stop');
} else {
AddSurvey({

View File

@ -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.