Able to duplicate existing survey
continuous-integration/drone/push Build is passing Details

This commit is contained in:
nemunaire 2021-03-01 18:00:28 +01:00
parent 000ac334cc
commit f3fd0be2b8
2 changed files with 19 additions and 2 deletions

View File

@ -280,7 +280,7 @@ angular.module("AtsebaytApp")
}
})
.controller("SurveyController", function($scope, $rootScope, Survey, $routeParams, $location) {
.controller("SurveyController", function($scope, $rootScope, Survey, SurveyQuest, $routeParams, $location) {
$rootScope.qactive = true;
$rootScope.uactive = false;
$scope.survey = Survey.get({ surveyId: $routeParams.surveyId });
@ -300,6 +300,22 @@ angular.module("AtsebaytApp")
}
}
$scope.duplicateSurvey = function() {
var bakSurveyId = this.survey.id;
delete this.survey.id;
this.survey.$save(function() {
// Now recopy questions
var questions = SurveyQuest.query({ surveyId: bakSurveyId });
questions.$promise.then(function (questions) {
questions.forEach(function (question) {
delete question.id
question.$save({ surveyId: $scope.survey.id });
})
$location.url("surveys/" + $scope.survey.id);
})
});
}
$scope.editSurvey = function() {
this.survey.edit = true;
}

View File

@ -54,7 +54,8 @@
<div class="form-group row">
<div class="col-sm-10">
<button type="submit" class="btn btn-primary">Enregistrer</button>
<button type="button" class="btn btn-danger" ng-click="deleteSurvey()">Supprimer</button>
<button type="button" class="btn btn-danger" ng-if="survey.id" ng-click="deleteSurvey()">Supprimer</button>
<button type="button" class="btn btn-secondary" ng-if="survey.id" ng-click="duplicateSurvey()">Dupliquer avec ces nouveaux paramètres</button>
</div>
</div>