annot-server/static/js/app.min.js
author rougeronj
Thu, 22 Jan 2015 09:26:43 +0100
changeset 111 a7b72620d227
parent 84 d7c5bffdd2d8
child 107 6d41506f9482
permissions -rw-r--r--
Add variable "wait". When this variable set, the annotsroll wait ignore some annotations, and wait before printing an otherone so there is no superposition. Can be passed as an options

!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,i){function r(e){return decodeURI((new RegExp(e+"=(.+?)(&|$)").exec(location.search)||[,null])[1])}function s(n,t){e.alertMessage=n,e.showSuccessAlert=t,e.showAlertDiv=!0,e.$$phase||e.$apply(),e.currentInterval&&(i.cancel(e.currentInterval),e.currentInterval=!1),e.currentInterval=i(function(){i.cancel(e.currentInterval),e.showAlertDiv=!1},2e3,1)}function a(e){d&&(d.innerHTML+=e+"\n",d.scrollTop=d.scrollHeight)}e.data=t.data;var c=function(n){if("undefined"!=typeof n.categories&&n.categories.length>0){for(var t=[],o=n.categories.length,i=0;o>i;i++)if(t.push(n.categories[i].label),"undefined"!=typeof n.categories[i].subcategories&&n.categories[i].subcategories.length>0)for(var r=n.categories[i].subcategories.length,s=0;r>s;s++)t.push(n.categories[i].subcategories[s].label);e.allCatLabels=t}};"undefined"!=typeof t.data.$promise?t.data.$promise.then(c):c(t.data),e.selectedlevel=!1,e.currentInterval=!1,e.showSuccessAlert=!1,e.showAlertDiv=!1,e.annotPile=[];var l=null,d=null;d=document.getElementById("log");var u;u="file:"===window.location.protocol?"ws://127.0.0.1:8090/annot":"ws://"+window.location.hostname+":8090/annot";var f=o.event_code;return"undefined"!=typeof f&&""!==f||(f=n.search().event,"undefined"!=typeof f&&""!==f||(f=r("event"),"undefined"!=typeof f&&""!==f))?(u=u+"?event="+f,"WebSocket"in window?l=new WebSocket(u):"MozWebSocket"in window?l=new window.MozWebSocket(u):(o.logging===!0&&a("Browser does not support WebSocket!"),window.location="http://autobahn.ws/unsupportedbrowser"),l&&(l.onopen=function(){o.logging===!0&&a("Connected to "+u)},l.onclose=function(e){o.logging===!0&&a("Connection closed (wasClean = "+e.wasClean+", code = "+e.code+", reason = "+e.reason+")"),s("Communication interrompue : la socket vient de se fermer.",!1),l=null},l.onmessage=function(n){var t=JSON.parse(n.data);if(o.logging&&a("Got message: "+n.data),e.annotPile.length>0){var r,s=e.annotPile.shift(),c="OK"===t.status;s===!1?(e.sendBtnSuccess=c,e.sendBtnError=!c,r=i(function(){i.cancel(r),e.sendBtnSuccess=!1,e.sendBtnError=!1},2e3,1)):(s.sendSuccess=c,s.sendError=!c,r=i(function(){i.cancel(r),s.sendSuccess=!1,s.sendError=!1},2e3,1)),e.$$phase||e.$apply()}}),e.sendAnnotation=function(n,t,i){if(""===e.username||"undefined"==typeof e.username)return void s("Vous devez indiquer un nom d'utilisateur.",!1);if(""===n||"undefined"==typeof n)return void s("Vous devez indiquer un nom de catégorie.",!1);if(l){("undefined"==typeof t||""===t)&&(t=window.S(n).slugify().s);var r={category:{code:t,label:n},user:e.username};l.send(JSON.stringify(r)),o.logging===!0&&a("Sent: "+JSON.stringify(r)),e.annotPile.push("undefined"==typeof i?!1:i)}else s("La socket ne fonctionne pas.",!1),o.logging===!0&&a("Not connected.")},void(e.selectLevel=function(n,t,o){return"undefined"==typeof o?(e.returnVisStyle={visibility:"hidden"},void(e.selectedlevel=!1)):void("undefined"!=typeof o.subcategories&&o.subcategories.length>0?(e.selectedlevel=o.subcategories,e.returnVisStyle={visibility:"show"}):e.sendAnnotation(n,t,o))})):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.")})}();