diff -r a7b72620d227 -r 3e075a48e19e annot-server/static/js/app.js --- a/annot-server/static/js/app.js Thu Jan 22 09:26:43 2015 +0100 +++ b/annot-server/static/js/app.js Thu Jan 22 09:29:49 2015 +0100 @@ -35,6 +35,11 @@ ); } + function colorToHex(c) { + var m = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(c); + return m ? '#' + (1 << 24 | m[1] << 16 | m[2] << 8 | m[3]).toString(16).substr(1) : c; + } + $scope.data = dataModel.data; var process_categories = function(data) { @@ -50,7 +55,12 @@ } } } - $scope.allCatLabels = cats; + if(typeof data.autocomplete === 'undefined' || data.autocomplete.length === 0) { + $scope.allCatLabels = cats; + } + else { + $scope.allCatLabels = data.autocomplete; + } } }; @@ -101,7 +111,7 @@ } else { wsuri = 'ws://' + window.location.hostname + ':8090/annot'; } - + var eventCode = context.event_code; if(typeof eventCode==='undefined' || eventCode===''){ eventCode = $location.search().event; @@ -173,7 +183,12 @@ }; } - $scope.sendAnnotation = function(label, code, c){ + $scope.sendFreeAnnotation = function(label, text) { + $scope.sendAnnotation(label, window.S(label).slugify().s, label, text, $scope.data.defaultColor || "#536991"); + }; + + $scope.sendAnnotation = function(label, code, freeLabel, freetext, color, c){ + if($scope.username==='' || typeof $scope.username==='undefined'){ showAlert('Vous devez indiquer un nom d\'utilisateur.', false); return; @@ -187,12 +202,24 @@ if(typeof code==='undefined' || code===''){ code = window.S(label).slugify().s; } + + var hexc; + if(color.substring(0, 4) === 'rgb(') { + hexc = colorToHex(color); + } + else { + hexc = color; + } + + var new_annot = { category: {code: code, label: label}, + text: freetext, + color: hexc, user : $scope.username }; sock.send(JSON.stringify(new_annot)); - if(context.logging===true){ + if(context.logging===true){ log('Sent: ' + JSON.stringify(new_annot)); } if(typeof c==='undefined'){ @@ -201,6 +228,8 @@ else{ $scope.annotPile.push(c); } + $scope.catText = ""; + $scope.catLabel = ""; } else { showAlert('La socket ne fonctionne pas.', false); if(context.logging===true){ @@ -210,7 +239,7 @@ }; // Interface management - $scope.selectLevel = function(label, code, c){ + $scope.selectLevel = function(label, code, freelabel, freetext, color, c){ if(typeof c==='undefined'){ $scope.returnVisStyle = {visibility:'hidden'}; $scope.selectedlevel = false; @@ -223,7 +252,7 @@ else{ // Send query //console.log('send ntm', c); - $scope.sendAnnotation(label, code, c); + $scope.sendAnnotation(label, code, freelabel, freetext, color, c); } };