--- 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) {
--- 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("<li></li>");var f=c("<span></span>");var g=c("<a></a>").addClass("msg").attr("href",h.url);if(h.source.avatar){c("<img>").addClass("air air-top-left margin-top-2").attr("src",h.source.avatar).appendTo(g)}else{c("<i></i>").addClass("fa fa-2x fa-user air air-top-left img margin-left-5 margin-top-2").appendTo(g)}c("<time></time>").text(h.timestamp).appendTo(g);c("<span></span>").addClass("from").text(h.source.title).appendTo(g);c("<span></span>").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<h.length;f++){var i=h[f];a.createNotification(i).appendTo(g)}}else{g.prev("p").show()}d.skin.checkNotification()},refreshNotifications:function(){return function(){d.ajax.post("get-user-notifications.json",{},a.showNotifications)}}};b.PyAMS_notify=a;d.ajax.check(c.WebSocket,"/--static--/pyams_notify/js/jquery-WebSocket"+d.devext+".js",function(){a.initConnection()})})(jQuery,this);
\ No newline at end of file
+(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){if(b.console){b.console.debug("WS notifications 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){if(b.console){b.console.log(e)}},onSocketClosed:function(e){a.connection=null;if(b.console){b.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("<li></li>");var f=c("<span></span>");var g=c("<a></a>").addClass("msg").attr("href",h.url);if(h.source.avatar){c("<img>").addClass("air air-top-left margin-top-2").attr("src",h.source.avatar).appendTo(g)}else{c("<i></i>").addClass("fa fa-2x fa-user air air-top-left img margin-left-5 margin-top-2").appendTo(g)}c("<time></time>").text(h.timestamp).appendTo(g);c("<span></span>").addClass("from").text(h.source.title).appendTo(g);c("<span></span>").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<h.length;f++){var i=h[f];a.createNotification(i).appendTo(g)}}else{g.prev("p").show()}d.skin.checkNotification()},refreshNotifications:function(){return function(){d.ajax.post("get-user-notifications.json",{},a.showNotifications)}}};b.PyAMS_notify=a;d.ajax.check(c.WebSocket,"/--static--/pyams_notify/js/jquery-WebSocket"+d.devext+".js",function(){a.initConnection()})})(jQuery,this);
\ No newline at end of file