/*******************************************************************************
 * Name: QuizziPedia::Front-End::Controllers::UserDetailsController;
 * Description: questa classe permette di recuperare i dati dell'utente;
 * Relations with other classes:
 * +
 * Creation data: 12-05-2016;
 * Author: Matteo Granzotto;
 * License: MIT.
 ********************************************************************************
 * Updates history
 *-------------------------------------------------------------------------------
 * ID: SearchController_20160512;
 * Update data: 12-05-2016;
 * Description: Creata e iniziata stesura della classe;
 * Author: Alberto Ferrara.
 *-------------------------------------------------------------------------------
 *******************************************************************************/


app.controller('UserDetailsController', UserDetailsController);

UserDetailsController.$inject = ['$scope', '$rootScope', '$routeParams', '$location', '$mdDialog', 'ErrorInfoModel', 'UserDetailsService', 'QuizService'];

function UserDetailsController($scope, $rootScope, $routeParams, $location, $mdDialog , ErrorInfoModel, UserDetailsService, QuizService) {
    //console.log($rootScope.userLogged.getUsername());
    if($rootScope.userLogged != undefined){
        $scope.user = $rootScope.userLogged;
        loadQuizzes();
    }
    else{
        var ist = $rootScope.$on("userDownloaded", function(event, args) {
            if(args){
                $scope.user = $rootScope.userLogged;
                loadQuizzes();
            }
        });
        $scope.$on('$destroy', ist);
    }

    function loadQuizzes() {
       QuizService.getDoneQuestionnaire($routeParams.lang)
           .then(function (result) {
               $scope.quizzes = result.data;
               //console.log("quiz: " + $scope.quizzes);
           }, function (err) {
               console.log(err);
               $scope.error = new ErrorInfoModel("8", "Errore", "Caricamento questionari utente non andato a buon fine");
               alert = $mdDialog.alert()
                   .title($scope.error.getTitle())
                   .content($scope.error.getMessage())
                   .ok('Ok');
               $mdDialog
                   .show(alert)
                   .finally(function () {
                       alert = undefined;
                   });
           });
        }
}


@@ -1911,16 +1911,158 @@
 g(err);%0A
+               //controllo per evitare il popup in caso l'utente non abbia svolto questionari%0A               if(err.data.code != %22914%22) %7B%0A    
         
@@ -2182,32 +2182,36 @@
 %0A               
+    
 alert = $mdDialo
@@ -2220,16 +2220,20 @@
 alert()%0A
+    
         
@@ -2294,16 +2294,20 @@
         
+    
 .content
@@ -2353,16 +2353,20 @@
         
+    
 .ok('Ok'
@@ -2383,16 +2383,20 @@
         
+   
+ 
 $mdDialo
@@ -2397,16 +2397,20 @@
 dDialog%0A
+    
         
@@ -2452,16 +2452,20 @@
         
+    
 .finally
@@ -2494,32 +2494,36 @@
                 
+   
+ 
 alert = undefine
@@ -2536,32 +2536,36 @@
                 
+    
 %7D);%0A           %7D
@@ -2554,32 +2554,38 @@
   %7D);%0A          
+     %7D
  %7D);%0A        %7D%0A%7D

update popup