annot-server/static/js/app.js
changeset 112 3e075a48e19e
parent 109 8546e2181a73
child 116 61d4a6610ba4
equal deleted inserted replaced
111:a7b72620d227 112:3e075a48e19e
    31 
    31 
    32             function getURLParameter(name) {
    32             function getURLParameter(name) {
    33                 return decodeURI(
    33                 return decodeURI(
    34                     (new RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    34                     (new RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    35                 );
    35                 );
       
    36             }
       
    37 
       
    38             function colorToHex(c) {
       
    39                 var m = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(c);
       
    40                 return m ? '#' + (1 << 24 | m[1] << 16 | m[2] << 8 | m[3]).toString(16).substr(1) : c;
    36             }
    41             }
    37 
    42 
    38             $scope.data = dataModel.data;
    43             $scope.data = dataModel.data;
    39 
    44 
    40             var process_categories = function(data) {
    45             var process_categories = function(data) {
    48                             for(var j=0;j<nbSubCat;j++){
    53                             for(var j=0;j<nbSubCat;j++){
    49                                 cats.push(data.categories[i].subcategories[j].label);
    54                                 cats.push(data.categories[i].subcategories[j].label);
    50                             }
    55                             }
    51                         }
    56                         }
    52                     }
    57                     }
    53                     $scope.allCatLabels = cats;
    58                     if(typeof data.autocomplete === 'undefined' || data.autocomplete.length === 0) {
       
    59                         $scope.allCatLabels = cats;
       
    60                     }
       
    61                     else {
       
    62                         $scope.allCatLabels = data.autocomplete;
       
    63                     }
    54                 }
    64                 }
    55             };
    65             };
    56 
    66 
    57             if (typeof dataModel.data.$promise !== 'undefined') {
    67             if (typeof dataModel.data.$promise !== 'undefined') {
    58                 dataModel.data.$promise.then(process_categories);
    68                 dataModel.data.$promise.then(process_categories);
    99             if (window.location.protocol === 'file:') {
   109             if (window.location.protocol === 'file:') {
   100                 wsuri = 'ws://127.0.0.1:8090/annot';
   110                 wsuri = 'ws://127.0.0.1:8090/annot';
   101             } else {
   111             } else {
   102                 wsuri = 'ws://' + window.location.hostname + ':8090/annot';
   112                 wsuri = 'ws://' + window.location.hostname + ':8090/annot';
   103             }
   113             }
   104             
   114 
   105             var eventCode = context.event_code;
   115             var eventCode = context.event_code;
   106             if(typeof eventCode==='undefined' || eventCode===''){
   116             if(typeof eventCode==='undefined' || eventCode===''){
   107                 eventCode = $location.search().event;
   117                 eventCode = $location.search().event;
   108                 if(typeof eventCode==='undefined' || eventCode===''){
   118                 if(typeof eventCode==='undefined' || eventCode===''){
   109                     eventCode = getURLParameter('event');
   119                     eventCode = getURLParameter('event');
   171                         }
   181                         }
   172                     }
   182                     }
   173                 };
   183                 };
   174             }
   184             }
   175 
   185 
   176             $scope.sendAnnotation = function(label, code, c){
   186             $scope.sendFreeAnnotation = function(label, text) {
       
   187                 $scope.sendAnnotation(label, window.S(label).slugify().s, label, text, $scope.data.defaultColor || "#536991");
       
   188             };
       
   189 
       
   190             $scope.sendAnnotation = function(label, code, freeLabel, freetext, color, c){
       
   191 
   177                 if($scope.username==='' || typeof $scope.username==='undefined'){
   192                 if($scope.username==='' || typeof $scope.username==='undefined'){
   178                     showAlert('Vous devez indiquer un nom d\'utilisateur.', false);
   193                     showAlert('Vous devez indiquer un nom d\'utilisateur.', false);
   179                     return;
   194                     return;
   180                 }
   195                 }
   181                 if(label==='' || typeof label==='undefined'){
   196                 if(label==='' || typeof label==='undefined'){
   185                 // Send query
   200                 // Send query
   186                 if (sock) {
   201                 if (sock) {
   187                     if(typeof code==='undefined' || code===''){
   202                     if(typeof code==='undefined' || code===''){
   188                         code = window.S(label).slugify().s;
   203                         code = window.S(label).slugify().s;
   189                     }
   204                     }
       
   205 
       
   206                     var hexc;
       
   207                     if(color.substring(0, 4) === 'rgb(') {
       
   208                         hexc = colorToHex(color);
       
   209                     }
       
   210                     else {
       
   211                         hexc = color;
       
   212                     }
       
   213 
       
   214 
   190                     var new_annot = {
   215                     var new_annot = {
   191                             category: {code: code, label: label},
   216                             category: {code: code, label: label},
       
   217                             text: freetext,
       
   218                             color: hexc,
   192                             user : $scope.username
   219                             user : $scope.username
   193                     };
   220                     };
   194                     sock.send(JSON.stringify(new_annot));
   221                     sock.send(JSON.stringify(new_annot));
   195                     if(context.logging===true){
   222                      if(context.logging===true){
   196                         log('Sent: ' + JSON.stringify(new_annot));
   223                         log('Sent: ' + JSON.stringify(new_annot));
   197                     }
   224                     }
   198                     if(typeof c==='undefined'){
   225                     if(typeof c==='undefined'){
   199                         $scope.annotPile.push(false);
   226                         $scope.annotPile.push(false);
   200                     }
   227                     }
   201                     else{
   228                     else{
   202                         $scope.annotPile.push(c);
   229                         $scope.annotPile.push(c);
   203                     }
   230                     }
       
   231                     $scope.catText = "";
       
   232                     $scope.catLabel = "";
   204                 } else {
   233                 } else {
   205                     showAlert('La socket ne fonctionne pas.', false);
   234                     showAlert('La socket ne fonctionne pas.', false);
   206                     if(context.logging===true){
   235                     if(context.logging===true){
   207                         log('Not connected.');
   236                         log('Not connected.');
   208                     }
   237                     }
   209                 }
   238                 }
   210             };
   239             };
   211 
   240 
   212             // Interface management
   241             // Interface management
   213             $scope.selectLevel = function(label, code, c){
   242             $scope.selectLevel = function(label, code, freelabel, freetext, color, c){
   214                 if(typeof c==='undefined'){
   243                 if(typeof c==='undefined'){
   215                     $scope.returnVisStyle = {visibility:'hidden'};
   244                     $scope.returnVisStyle = {visibility:'hidden'};
   216                     $scope.selectedlevel = false;
   245                     $scope.selectedlevel = false;
   217                     return;
   246                     return;
   218                 }
   247                 }
   221                     $scope.returnVisStyle = {visibility:'show'};
   250                     $scope.returnVisStyle = {visibility:'show'};
   222                 }
   251                 }
   223                 else{
   252                 else{
   224                     // Send query
   253                     // Send query
   225                     //console.log('send ntm', c);
   254                     //console.log('send ntm', c);
   226                     $scope.sendAnnotation(label, code, c);
   255                     $scope.sendAnnotation(label, code, freelabel, freetext, color, c);
   227                 }
   256                 }
   228             };
   257             };
   229 
   258 
   230         });
   259         });
   231 
   260