client/app/app.js
changeset 9 ae8a74bd6add
parent 7 813fec862542
child 10 90918426079c
--- a/client/app/app.js	Thu Oct 09 15:59:48 2014 +0200
+++ b/client/app/app.js	Fri Oct 10 12:03:01 2014 +0200
@@ -22,7 +22,7 @@
             //console.log('dataModel',this,dataApi);
             this.data = dataApi.dataResource.get();
         })
-        .controller('homeCtrl', function($scope, $location, dataModel, context){
+        .controller('homeCtrl', function($scope, $location, dataModel, context, $interval){
             //console.log('homeCtrl 1', $scope, $location, context);
             console.log('homeCtrl 2', context);
             $scope.data = dataModel.data;
@@ -45,7 +45,23 @@
             });
             
             $scope.selectedlevel = false;
-            
+
+            $scope.currentInterval = false;
+            $scope.showSuccessAlert = false;
+            $scope.showAlertDiv = false;
+            function showAlert(m, success){
+                $scope.alertMessage = m;
+                $scope.showSuccessAlert = success;
+                $scope.showAlertDiv = true;
+                if(!$scope.$$phase) {
+                    $scope.$apply();
+                }
+                if($scope.currentInterval){
+                    $interval.cancel($scope.currentInterval);
+                    $scope.currentInterval = false;
+                }
+                $scope.currentInterval = $interval(function(){ console.log('fin interval !'); $interval.cancel($scope.currentInterval); $scope.showAlertDiv = false; }, 2000, 1);
+            }
             
             
 
@@ -79,7 +95,7 @@
                 }
                 window.location = 'http://autobahn.ws/unsupportedbrowser';
             }
-            console.log('socket in controller = ', sock);
+            
             if (sock) {
                 sock.onopen = function() {
                     if(context.logging===true){
@@ -91,7 +107,7 @@
                     if(context.logging===true){
                         log('Connection closed (wasClean = ' + e.wasClean + ', code = ' + e.code + ', reason = ' + e.reason + ')');
                     }
-                    alert('Communication interrompue : la socket vient de se fermer.');
+                    showAlert('Communication interrompue : la socket vient de se fermer.', false);
                     sock = null;
                 };
 
@@ -99,17 +115,17 @@
                     if(context.logging===true){
                         log('Got message: ' + e.data);
                     }
-                    alert('Annotation bien reçue.');
+                    showAlert('Annotation bien reçue.', true);
                 };
             }
 
             $scope.sendAnnotation = function(eventCode){
                 if($scope.username==='' || typeof $scope.username==='undefined'){
-                    alert('Vous devez indiquer un nom d\'utilisateur.');
+                    showAlert('Vous devez indiquer un nom d\'utilisateur.', false);
                     return;
                 }
                 if(eventCode==='' || typeof eventCode==='undefined'){
-                    alert('Vous devez indiquer un nom de catégorie.');
+                    showAlert('Vous devez indiquer un nom de catégorie.', false);
                     return;
                 }
                 // Send query
@@ -123,7 +139,7 @@
                         log('Sent: ' + JSON.stringify(new_annot));
                     }
                 } else {
-                    alert('La socket ne fonctionne pas.');
+                    showAlert('La socket ne fonctionne pas.', false);
                     if(context.logging===true){
                         log('Not connected.');
                     }