client/annot-client/app/app.js
author ymh <ymh.work@gmail.com>
Fri, 23 Jan 2015 01:08:34 +0100
changeset 130 0a2b4991d48c
parent 110 e4f0c105090d
child 159 f2e4641681f6
permissions -rw-r--r--
publish new version to server
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     1
(function(){
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     2
    'use strict';
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     3
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     4
    angular.module('mons', [ 'ngResource', 'ngRoute', 'autocomplete' ])
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     5
        .config(function($routeProvider) {
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     6
            $routeProvider.
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     7
                when('/', {
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     8
                    controller: 'homeCtrl'
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
     9
               }).
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    10
               otherwise({
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    11
                   redirectTo: '/'
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    12
               });
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    13
        })
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    14
        .config(function($logProvider){
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    15
            $logProvider.debugEnabled(true);
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    16
        })
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    17
        .service('dataApi', function($resource, context) {
34
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
    18
            //console.log('dataApi',$resource, context);
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    19
            this.dataResource = $resource(context.urls.dataUrl);
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    20
        })
44
76f2fa4eb4f7 correct client and requirements
cavaliet
parents: 42
diff changeset
    21
        .service('dataModel', function(dataApi, context) {
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    22
            //console.log('dataModel',this,dataApi);
42
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    23
            if(typeof context.categories_json !== 'undefined' && context.categories_json) {
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    24
                this.data = JSON.parse(context.categories_json);
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    25
            }
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    26
            else {
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    27
                this.data = dataApi.dataResource.get();
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    28
            }
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    29
        })
9
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    30
        .controller('homeCtrl', function($scope, $location, dataModel, context, $interval){
42
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    31
34
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
    32
            function getURLParameter(name) {
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
    33
                return decodeURI(
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
    34
                    (new RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
    35
                );
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
    36
            }
42
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    37
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    38
            function colorToHex(c) {
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    39
                var m = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(c);
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
    40
                return m ? '#' + (1 << 24 | m[1] << 16 | m[2] << 8 | m[3]).toString(16).substr(1) : c;
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    41
            }
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    42
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    43
            $scope.data = dataModel.data;
23
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    44
42
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    45
            var process_categories = function(data) {
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    46
                if(typeof data.categories!=='undefined' && data.categories.length>0){
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    47
                    var cats = [];
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    48
                    var nbCat = data.categories.length;
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    49
                    for(var i=0;i<nbCat;i++){
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    50
                        cats.push(data.categories[i].label);
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    51
                        if(typeof data.categories[i].subcategories!=='undefined' && data.categories[i].subcategories.length>0){
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    52
                            var nbSubCat = data.categories[i].subcategories.length;
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    53
                            for(var j=0;j<nbSubCat;j++){
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    54
                                cats.push(data.categories[i].subcategories[j].label);
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    55
                            }
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    56
                        }
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    57
                    }
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    58
                    if(typeof data.autocomplete === 'undefined' || data.autocomplete.length === 0) {
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    59
                        $scope.allCatLabels = cats;
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    60
                    }
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    61
                    else {
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    62
                        $scope.allCatLabels = data.autocomplete;
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    63
                    }
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    64
                }
42
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    65
            };
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    66
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    67
            if (typeof dataModel.data.$promise !== 'undefined') {
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    68
                dataModel.data.$promise.then(process_categories);
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    69
            }
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    70
            else {
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    71
                process_categories(dataModel.data);
926f0426ce78 add event + event session + admin + category json management. Must rebuild database
ymh <ymh.work@gmail.com>
parents: 36
diff changeset
    72
            }
23
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    73
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
    74
            $scope.selectedlevel = false;
9
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    75
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    76
            $scope.currentInterval = false;
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    77
            $scope.showSuccessAlert = false;
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    78
            $scope.showAlertDiv = false;
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    79
            function showAlert(m, success){
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    80
                $scope.alertMessage = m;
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    81
                $scope.showSuccessAlert = success;
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    82
                $scope.showAlertDiv = true;
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    83
                if(!$scope.$$phase) {
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    84
                    $scope.$apply();
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    85
                }
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    86
                if($scope.currentInterval){
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    87
                    $interval.cancel($scope.currentInterval);
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    88
                    $scope.currentInterval = false;
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    89
                }
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
    90
                $scope.currentInterval = $interval(function(){ $interval.cancel($scope.currentInterval); $scope.showAlertDiv = false; }, 2000, 1);
9
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
    91
            }
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
    92
            $scope.annotPile = [];
23
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    93
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    94
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
    95
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
    96
            // Socket management
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
    97
            var sock = null;
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
    98
            var ellog = null;
23
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
    99
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   100
            ellog = document.getElementById('log');
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   101
            function log(m) {
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   102
                if(ellog){
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   103
                    ellog.innerHTML += m + '\n';
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   104
                    ellog.scrollTop = ellog.scrollHeight;
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   105
                }
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   106
            }
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   107
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   108
            var wsuri;
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   109
            if (window.location.protocol === 'file:') {
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   110
                wsuri = 'ws://127.0.0.1:8090/annot';
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   111
            } else {
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   112
                wsuri = 'ws://' + window.location.hostname + ':8090/annot';
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   113
            }
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   114
44
76f2fa4eb4f7 correct client and requirements
cavaliet
parents: 42
diff changeset
   115
            var eventCode = context.event_code;
34
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
   116
            if(typeof eventCode==='undefined' || eventCode===''){
44
76f2fa4eb4f7 correct client and requirements
cavaliet
parents: 42
diff changeset
   117
                eventCode = $location.search().event;
34
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
   118
                if(typeof eventCode==='undefined' || eventCode===''){
44
76f2fa4eb4f7 correct client and requirements
cavaliet
parents: 42
diff changeset
   119
                    eventCode = getURLParameter('event');
76f2fa4eb4f7 correct client and requirements
cavaliet
parents: 42
diff changeset
   120
                    if(typeof eventCode==='undefined' || eventCode===''){
76f2fa4eb4f7 correct client and requirements
cavaliet
parents: 42
diff changeset
   121
                        alert('le code de l\'événement doit être indiqué dans un paramètre de template u dans l\'url selon ?event=CODE_EVENEMENT.');
76f2fa4eb4f7 correct client and requirements
cavaliet
parents: 42
diff changeset
   122
                        return;
76f2fa4eb4f7 correct client and requirements
cavaliet
parents: 42
diff changeset
   123
                    }
34
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
   124
                }
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
   125
            }
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
   126
            wsuri = wsuri + '?event=' + eventCode;
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   127
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   128
            if ('WebSocket' in window) {
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   129
                sock = new WebSocket(wsuri);
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   130
            } else if ('MozWebSocket' in window) {
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   131
                sock = new window.MozWebSocket(wsuri);
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   132
            } else {
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   133
                if(context.logging===true){
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   134
                    log('Browser does not support WebSocket!');
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   135
                }
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   136
                window.location = 'http://autobahn.ws/unsupportedbrowser';
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   137
            }
23
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
   138
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   139
            if (sock) {
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   140
                sock.onopen = function() {
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   141
                    if(context.logging===true){
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   142
                        log('Connected to ' + wsuri);
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   143
                    }
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   144
                };
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   145
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   146
                sock.onclose = function(e) {
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   147
                    if(context.logging===true){
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   148
                        log('Connection closed (wasClean = ' + e.wasClean + ', code = ' + e.code + ', reason = ' + e.reason + ')');
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   149
                    }
9
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
   150
                    showAlert('Communication interrompue : la socket vient de se fermer.', false);
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   151
                    sock = null;
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   152
                };
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   153
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   154
                sock.onmessage = function(e) {
36
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   155
                    var data_json = JSON.parse(e.data);
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   156
                    //console.log('1', data_json);
23
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
   157
                    if(context.logging){
36
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   158
                        log('Got message: ' + e.data);
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   159
                    }
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   160
                    //showAlert('Annotation bien reçue.', true);
34
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
   161
                    //console.log('2 message', $scope.annotPile.length);
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   162
                    if($scope.annotPile.length>0){
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   163
                        var c = $scope.annotPile.shift();
27
68b29e36c9a2 correct annotationclient for jshint
cavaliet
parents: 23
diff changeset
   164
                        //console.log('3 message', c);
36
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   165
                        //console.log('2',data_json.status,data_json.status==='OK');
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   166
                        var ok = data_json.status==='OK';
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   167
                        var i;
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   168
                        if(c===false){
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   169
                            //showAlert('Annotation envoyée.', true);
36
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   170
                            $scope.sendBtnSuccess = ok;
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   171
                            $scope.sendBtnError = !ok;
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   172
                            i = $interval(function(){ $interval.cancel(i); $scope.sendBtnSuccess = false; $scope.sendBtnError = false; }, 2000, 1);
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   173
                        }
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   174
                        else{
36
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   175
                            c.sendSuccess = ok;
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   176
                            c.sendError = !ok;
5d392dea4f49 error status management in client annotation
cavaliet
parents: 34
diff changeset
   177
                            i = $interval(function(){ $interval.cancel(i); c.sendSuccess = false; c.sendError = false; }, 2000, 1);
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   178
                        }
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   179
                        if(!$scope.$$phase) {
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   180
                            $scope.$apply();
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   181
                        }
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   182
                    }
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   183
                };
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   184
            }
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   185
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   186
            $scope.sendFreeAnnotation = function(label, text) {
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   187
                $scope.sendAnnotation(label, window.S(label).slugify().s, label, text, $scope.data.defaultColor || "#536991");
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   188
            };
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   189
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   190
            $scope.sendAnnotation = function(label, code, freeLabel, freetext, color, c){
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   191
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   192
                if($scope.username==='' || typeof $scope.username==='undefined'){
9
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
   193
                    showAlert('Vous devez indiquer un nom d\'utilisateur.', false);
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   194
                    return;
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   195
                }
11
c0f9f9ab2a8a clean messages and error.
cavaliet
parents: 10
diff changeset
   196
                if(label==='' || typeof label==='undefined'){
9
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
   197
                    showAlert('Vous devez indiquer un nom de catégorie.', false);
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   198
                    return;
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   199
                }
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   200
                // Send query
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   201
                if (sock) {
11
c0f9f9ab2a8a clean messages and error.
cavaliet
parents: 10
diff changeset
   202
                    if(typeof code==='undefined' || code===''){
c0f9f9ab2a8a clean messages and error.
cavaliet
parents: 10
diff changeset
   203
                        code = window.S(label).slugify().s;
c0f9f9ab2a8a clean messages and error.
cavaliet
parents: 10
diff changeset
   204
                    }
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   205
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   206
                    var hexc;
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   207
                    if(color.substring(0, 4) === 'rgb(') {
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
   208
                        hexc = colorToHex(color);
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   209
                    }
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   210
                    else {
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   211
                        hexc = color;
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   212
                    }
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   213
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   214
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   215
                    var new_annot = {
11
c0f9f9ab2a8a clean messages and error.
cavaliet
parents: 10
diff changeset
   216
                            category: {code: code, label: label},
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   217
                            text: freetext,
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   218
                            color: hexc,
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   219
                            user : $scope.username
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   220
                    };
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   221
                    sock.send(JSON.stringify(new_annot));
110
e4f0c105090d some quick and dirty fixes on colors to start the session
ymh <ymh.work@gmail.com>
parents: 109
diff changeset
   222
                 if(context.logging===true){
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   223
                        log('Sent: ' + JSON.stringify(new_annot));
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   224
                    }
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   225
                    if(typeof c==='undefined'){
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   226
                        $scope.annotPile.push(false);
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   227
                    }
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   228
                    else{
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   229
                        $scope.annotPile.push(c);
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   230
                    }
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   231
                    $scope.catText = "";
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   232
                    $scope.catLabel = "";
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   233
                } else {
9
ae8a74bd6add alert system for feedback
cavaliet
parents: 7
diff changeset
   234
                    showAlert('La socket ne fonctionne pas.', false);
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   235
                    if(context.logging===true){
7
813fec862542 little correction
cavaliet
parents: 6
diff changeset
   236
                        log('Not connected.');
6
c53e9b24f93f loggin in annotation client depends on a boolean
cavaliet
parents: 5
diff changeset
   237
                    }
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   238
                }
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   239
            };
23
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
   240
5
90a7c431b979 first step of working annotation real annotation client
cavaliet
parents: 1
diff changeset
   241
            // Interface management
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   242
            $scope.selectLevel = function(label, code, freelabel, freetext, color, c){
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   243
                if(typeof c==='undefined'){
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   244
                    $scope.returnVisStyle = {visibility:'hidden'};
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   245
                    $scope.selectedlevel = false;
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   246
                    return;
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   247
                }
10
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   248
                if(typeof c.subcategories!=='undefined' && c.subcategories.length>0){
90918426079c better feedback after annotation sent
cavaliet
parents: 9
diff changeset
   249
                    $scope.selectedlevel = c.subcategories;
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   250
                    $scope.returnVisStyle = {visibility:'show'};
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   251
                }
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   252
                else{
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   253
                    // Send query
34
dc21d793b5d4 event necessary in client annotation
cavaliet
parents: 27
diff changeset
   254
                    //console.log('send ntm', c);
107
6d41506f9482 correct annotation client
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
   255
                    $scope.sendAnnotation(label, code, freelabel, freetext, color, c);
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   256
                }
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   257
            };
23
16a1925df2df add status to annotation creation. Improve error management for annotation creation
ymh <ymh.work@gmail.com>
parents: 11
diff changeset
   258
1
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   259
        });
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   260
1cdebfeb77f9 add client folder and update hgignore
cavaliet
parents:
diff changeset
   261
})();