client/app/app.js
changeset 10 90918426079c
parent 9 ae8a74bd6add
child 11 c0f9f9ab2a8a
equal deleted inserted replaced
9:ae8a74bd6add 10:90918426079c
    58                 }
    58                 }
    59                 if($scope.currentInterval){
    59                 if($scope.currentInterval){
    60                     $interval.cancel($scope.currentInterval);
    60                     $interval.cancel($scope.currentInterval);
    61                     $scope.currentInterval = false;
    61                     $scope.currentInterval = false;
    62                 }
    62                 }
    63                 $scope.currentInterval = $interval(function(){ console.log('fin interval !'); $interval.cancel($scope.currentInterval); $scope.showAlertDiv = false; }, 2000, 1);
    63                 $scope.currentInterval = $interval(function(){ $interval.cancel($scope.currentInterval); $scope.showAlertDiv = false; }, 2000, 1);
    64             }
    64             }
       
    65             $scope.annotPile = [];
    65             
    66             
    66             
    67             
    67 
    68 
    68             // Socket management
    69             // Socket management
    69             var sock = null;
    70             var sock = null;
   113 
   114 
   114                 sock.onmessage = function(e) {
   115                 sock.onmessage = function(e) {
   115                     if(context.logging===true){
   116                     if(context.logging===true){
   116                         log('Got message: ' + e.data);
   117                         log('Got message: ' + e.data);
   117                     }
   118                     }
   118                     showAlert('Annotation bien reçue.', true);
   119                     //showAlert('Annotation bien reçue.', true);
       
   120                     console.log('2 message', $scope.annotPile.length);
       
   121                     if($scope.annotPile.length>0){
       
   122                         var c = $scope.annotPile.shift();
       
   123                         console.log('3 message', c);
       
   124                         var i;
       
   125                         if(c===false){
       
   126                             //showAlert('Annotation envoyée.', true);
       
   127                             $scope.sendBtnSuccess = true;
       
   128                             i = $interval(function(){ $interval.cancel(i); $scope.sendBtnSuccess = false; }, 2000, 1);
       
   129                         }
       
   130                         else{
       
   131                             c.sendSuccess = true;
       
   132                             i = $interval(function(){ $interval.cancel(i); c.sendSuccess = false; }, 2000, 1);
       
   133                         }
       
   134                         if(!$scope.$$phase) {
       
   135                             $scope.$apply();
       
   136                         }
       
   137                     }
   119                 };
   138                 };
   120             }
   139             }
   121 
   140 
   122             $scope.sendAnnotation = function(eventCode){
   141             $scope.sendAnnotation = function(eventCode, c){
   123                 if($scope.username==='' || typeof $scope.username==='undefined'){
   142                 if($scope.username==='' || typeof $scope.username==='undefined'){
   124                     showAlert('Vous devez indiquer un nom d\'utilisateur.', false);
   143                     showAlert('Vous devez indiquer un nom d\'utilisateur.', false);
   125                     return;
   144                     return;
   126                 }
   145                 }
   127                 if(eventCode==='' || typeof eventCode==='undefined'){
   146                 if(eventCode==='' || typeof eventCode==='undefined'){
   136                     };
   155                     };
   137                     sock.send(JSON.stringify(new_annot));
   156                     sock.send(JSON.stringify(new_annot));
   138                     if(context.logging===true){
   157                     if(context.logging===true){
   139                         log('Sent: ' + JSON.stringify(new_annot));
   158                         log('Sent: ' + JSON.stringify(new_annot));
   140                     }
   159                     }
       
   160                     if(typeof c==='undefined'){
       
   161                         $scope.annotPile.push(false);
       
   162                     }
       
   163                     else{
       
   164                         $scope.annotPile.push(c);
       
   165                     }
   141                 } else {
   166                 } else {
   142                     showAlert('La socket ne fonctionne pas.', false);
   167                     showAlert('La socket ne fonctionne pas.', false);
   143                     if(context.logging===true){
   168                     if(context.logging===true){
   144                         log('Not connected.');
   169                         log('Not connected.');
   145                     }
   170                     }
   146                 }
   171                 }
   147             };
   172             };
   148             
   173             
   149             // Interface management
   174             // Interface management
   150             $scope.selectLevel = function(i, eventCode){
   175             $scope.selectLevel = function(eventCode, c){
   151                 if(i===false){
   176                 if(typeof c==='undefined'){
   152                     $scope.returnVisStyle = {visibility:'hidden'};
   177                     $scope.returnVisStyle = {visibility:'hidden'};
   153                     $scope.selectedlevel = false;
   178                     $scope.selectedlevel = false;
   154                     return;
   179                     return;
   155                 }
   180                 }
   156                 if(typeof $scope.data.categories[i].subcategories!=='undefined' && $scope.data.categories[i].subcategories.length>0){
   181                 if(typeof c.subcategories!=='undefined' && c.subcategories.length>0){
   157                     $scope.selectedlevel = $scope.data.categories[i].subcategories;
   182                     $scope.selectedlevel = c.subcategories;
   158                     $scope.returnVisStyle = {visibility:'show'};
   183                     $scope.returnVisStyle = {visibility:'show'};
   159                 }
   184                 }
   160                 else{
   185                 else{
   161                     // Send query
   186                     // Send query
   162                     $scope.sendAnnotation(eventCode);
   187                     console.log('send ntm', c);
       
   188                     $scope.sendAnnotation(eventCode, c);
   163                 }
   189                 }
   164             };
   190             };
   165             
   191             
   166         });
   192         });
   167 
   193