annot-server/static/js/app.min.js
author ymh <ymh.work@gmail.com>
Thu, 22 Jan 2015 08:07:09 +0100
changeset 109 8546e2181a73
parent 107 6d41506f9482
child 159 f2e4641681f6
permissions -rw-r--r--
correct color codes sent by client
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
109
8546e2181a73 correct color codes sent by client
ymh <ymh.work@gmail.com>
parents: 107
diff changeset
     1
!function(){"use strict";angular.module("mons",["ngResource","ngRoute","autocomplete"]).config(function(e){e.when("/",{controller:"homeCtrl"}).otherwise({redirectTo:"/"})}).config(function(e){e.debugEnabled(!0)}).service("dataApi",function(e,n){this.dataResource=e(n.urls.dataUrl)}).service("dataModel",function(e,n){this.data="undefined"!=typeof n.categories_json&&n.categories_json?JSON.parse(n.categories_json):e.dataResource.get()}).controller("homeCtrl",function(e,n,t,o,r){function s(e){return decodeURI((new RegExp(e+"=(.+?)(&|$)").exec(location.search)||[,null])[1])}function i(e){var n=/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(e);return n?"#"+(1<<24|n[1]<<16|n[2]<<8|n[3]).toString(16).substr(1):e}function a(n,t){e.alertMessage=n,e.showSuccessAlert=t,e.showAlertDiv=!0,e.$$phase||e.$apply(),e.currentInterval&&(r.cancel(e.currentInterval),e.currentInterval=!1),e.currentInterval=r(function(){r.cancel(e.currentInterval),e.showAlertDiv=!1},2e3,1)}function c(e){u&&(u.innerHTML+=e+"\n",u.scrollTop=u.scrollHeight)}e.data=t.data;var l=function(n){if("undefined"!=typeof n.categories&&n.categories.length>0){for(var t=[],o=n.categories.length,r=0;o>r;r++)if(t.push(n.categories[r].label),"undefined"!=typeof n.categories[r].subcategories&&n.categories[r].subcategories.length>0)for(var s=n.categories[r].subcategories.length,i=0;s>i;i++)t.push(n.categories[r].subcategories[i].label);e.allCatLabels="undefined"==typeof n.autocomplete||0===n.autocomplete.length?t:n.autocomplete}};"undefined"!=typeof t.data.$promise?t.data.$promise.then(l):l(t.data),e.selectedlevel=!1,e.currentInterval=!1,e.showSuccessAlert=!1,e.showAlertDiv=!1,e.annotPile=[];var d=null,u=null;u=document.getElementById("log");var f;f="file:"===window.location.protocol?"ws://127.0.0.1:8090/annot":"ws://"+window.location.hostname+":8090/annot";var g=o.event_code;return"undefined"!=typeof g&&""!==g||(g=n.search().event,"undefined"!=typeof g&&""!==g||(g=s("event"),"undefined"!=typeof g&&""!==g))?(f=f+"?event="+g,"WebSocket"in window?d=new WebSocket(f):"MozWebSocket"in window?d=new window.MozWebSocket(f):(o.logging===!0&&c("Browser does not support WebSocket!"),window.location="http://autobahn.ws/unsupportedbrowser"),d&&(d.onopen=function(){o.logging===!0&&c("Connected to "+f)},d.onclose=function(e){o.logging===!0&&c("Connection closed (wasClean = "+e.wasClean+", code = "+e.code+", reason = "+e.reason+")"),a("Communication interrompue : la socket vient de se fermer.",!1),d=null},d.onmessage=function(n){var t=JSON.parse(n.data);if(o.logging&&c("Got message: "+n.data),e.annotPile.length>0){var s,i=e.annotPile.shift(),a="OK"===t.status;i===!1?(e.sendBtnSuccess=a,e.sendBtnError=!a,s=r(function(){r.cancel(s),e.sendBtnSuccess=!1,e.sendBtnError=!1},2e3,1)):(i.sendSuccess=a,i.sendError=!a,s=r(function(){r.cancel(s),i.sendSuccess=!1,i.sendError=!1},2e3,1)),e.$$phase||e.$apply()}}),e.sendFreeAnnotation=function(n,t){e.sendAnnotation(n,window.S(n).slugify().s,n,t,e.data.defaultColor||"#536991")},e.sendAnnotation=function(n,t,r,s,l,u){if(""===e.username||"undefined"==typeof e.username)return void a("Vous devez indiquer un nom d'utilisateur.",!1);if(""===n||"undefined"==typeof n)return void a("Vous devez indiquer un nom de catégorie.",!1);if(d){("undefined"==typeof t||""===t)&&(t=window.S(n).slugify().s);var f;f="rgb("===l.substring(0,4)?i(l):l;var g={category:{code:t,label:n},text:s,color:f,user:e.username};d.send(JSON.stringify(g)),o.logging===!0&&c("Sent: "+JSON.stringify(g)),e.annotPile.push("undefined"==typeof u?!1:u),e.catText="",e.catLabel=""}else a("La socket ne fonctionne pas.",!1),o.logging===!0&&c("Not connected.")},void(e.selectLevel=function(n,t,o,r,s,i){return"undefined"==typeof i?(e.returnVisStyle={visibility:"hidden"},void(e.selectedlevel=!1)):void("undefined"!=typeof i.subcategories&&i.subcategories.length>0?(e.selectedlevel=i.subcategories,e.returnVisStyle={visibility:"show"}):e.sendAnnotation(n,t,o,r,s,i))})):void alert("le code de l'événement doit être indiqué dans un paramètre de template u dans l'url selon ?event=CODE_EVENEMENT.")})}();