From f3fd0be2b84ea6c6d53cb3d9b36fff4450c50111 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 1 Mar 2021 18:00:28 +0100 Subject: [PATCH] Able to duplicate existing survey --- htdocs/js/atsebayt.js | 18 +++++++++++++++++- htdocs/views/survey.html | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/htdocs/js/atsebayt.js b/htdocs/js/atsebayt.js index def21a9..2eb5cd7 100644 --- a/htdocs/js/atsebayt.js +++ b/htdocs/js/atsebayt.js @@ -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; } diff --git a/htdocs/views/survey.html b/htdocs/views/survey.html index 91304d6..e1a6871 100644 --- a/htdocs/views/survey.html +++ b/htdocs/views/survey.html @@ -54,7 +54,8 @@
- + +