# HG changeset patch # User Thierry Florac # Date 1467985040 -7200 # Node ID 9698e68537811963ad3347845772ba8ff13907cf # Parent 1ccb516d65a39c7303ae83fe1d4412ca968f9882 Added checks on globals diff -r 1ccb516d65a3 -r 9698e6853781 src/pyams_notify/skin/resources/js/pyams_notify.js --- a/src/pyams_notify/skin/resources/js/pyams_notify.js Fri Jun 24 16:25:25 2016 +0200 +++ b/src/pyams_notify/skin/resources/js/pyams_notify.js Fri Jul 08 15:37:20 2016 +0200 @@ -29,7 +29,9 @@ }, onSocketOpened: function(event) { - console.debug("WS subscription connection opened"); + if (globals.console) { + globals.console.debug("WS notifications connection opened"); + } MyAMS.ajax.post('get-notifications-context.json', {}, function(result) { if (result.principal.id !== '') { PyAMS_notify.connection.send(JSON.stringify({ @@ -49,12 +51,16 @@ }, onSocketError: function(event) { - console.log(event); + if (globals.console) { + globals.console.log(event); + } }, onSocketClosed: function(event) { PyAMS_notify.connection = null; - console.debug("WS connection closed"); + if (globals.console) { + globals.console.debug("WS connection closed"); + } }, notifyOnDesktop: function(data) { diff -r 1ccb516d65a3 -r 9698e6853781 src/pyams_notify/skin/resources/js/pyams_notify.min.js --- a/src/pyams_notify/skin/resources/js/pyams_notify.min.js Fri Jun 24 16:25:25 2016 +0200 +++ b/src/pyams_notify/skin/resources/js/pyams_notify.min.js Fri Jul 08 15:37:20 2016 +0200 @@ -1,1 +1,1 @@ -(function(c,b){var d=b.MyAMS;var a={connection:null,initConnection:function(){var f=c("[data-ams-notify-server]","#user-activity").data("ams-notify-server");if(f){var e=c.WebSocket("ws://"+f+"/subscribe");e.onopen=a.onSocketOpened;e.onmessage=a.onSocketMessage;e.onerror=a.onSocketError;e.onclose=a.onSocketClosed;a.connection=e;setInterval(a.checkConnection,30000)}},checkConnection:function(){if((a.connection===null)||(a.connection.readyState===WebSocket.CLOSED)){a.initConnection()}},onSocketOpened:function(e){console.debug("WS subscription connection opened");d.ajax.post("get-notifications-context.json",{},function(f){if(f.principal.id!==""){a.connection.send(JSON.stringify({action:"subscribe",principal:f.principal,context:f.context}));d.ajax.post("get-user-notifications.json",{},a.showNotifications)}})},onSocketMessage:function(e){var f=JSON.parse(e.data);a.notifyOnDesktop(f);a.notifyInWebpage(f)},onSocketError:function(e){console.log(e)},onSocketClosed:function(e){a.connection=null;console.debug("WS connection closed")},notifyOnDesktop:function(e){function f(){var g={title:e.title,body:e.message,icon:e.source.avatar};var h=new Notification(g.title,g);h.onclick=function(){if(e.url){window.open(e.url)}}}if(window.Notification&&(Notification.permission!=="denied")){if(Notification.permission==="default"){Notification.requestPermission(function(g){if(g==="granted"){f()}})}else{f()}}},createNotification:function(h){var e=c("
  • ");var f=c("");var g=c("").addClass("msg").attr("href",h.url);if(h.source.avatar){c("").addClass("air air-top-left margin-top-2").attr("src",h.source.avatar).appendTo(g)}else{c("").addClass("fa fa-2x fa-user air air-top-left img margin-left-5 margin-top-2").appendTo(g)}c("").text(h.timestamp).appendTo(g);c("").addClass("from").text(h.source.title).appendTo(g);c("").addClass("msg-body").text(h.message).appendTo(g);g.appendTo(f);f.appendTo(e);return e},notifyInWebpage:function(h){var e=c(".badge","#user-activity >span");var g=parseInt(e.text());e.text(g+1);var f=c(".notification-body","#user-activity");a.createNotification(h).prependTo(f);d.skin.checkNotification()},showNotifications:function(h){var e=c(".badge","#user-activity >span");e.text(h.length);var g=c(".notification-body","#user-activity");g.empty();if(h.length>0){g.prev("p").hide();for(var f=0;f");var f=c("");var g=c("").addClass("msg").attr("href",h.url);if(h.source.avatar){c("").addClass("air air-top-left margin-top-2").attr("src",h.source.avatar).appendTo(g)}else{c("").addClass("fa fa-2x fa-user air air-top-left img margin-left-5 margin-top-2").appendTo(g)}c("").text(h.timestamp).appendTo(g);c("").addClass("from").text(h.source.title).appendTo(g);c("").addClass("msg-body").text(h.message).appendTo(g);g.appendTo(f);f.appendTo(e);return e},notifyInWebpage:function(h){var e=c(".badge","#user-activity >span");var g=parseInt(e.text());e.text(g+1);var f=c(".notification-body","#user-activity");a.createNotification(h).prependTo(f);d.skin.checkNotification()},showNotifications:function(h){var e=c(".badge","#user-activity >span");e.text(h.length);var g=c(".notification-body","#user-activity");g.empty();if(h.length>0){g.prev("p").hide();for(var f=0;f