From 0cacac09fa01493e9b430587112e54bc8aafb735 Mon Sep 17 00:00:00 2001 From: Tim Windelschmidt Date: Tue, 15 Sep 2015 08:19:24 +0200 Subject: [PATCH] Changed the Notificationsystem for better usage --- node/public/js/easter.js | 4 +- node/public/js/notification.js | 98 ---------------------------------- node/public/js/state-notify.js | 21 ++++++++ node/views/index.jade | 3 +- 4 files changed, 25 insertions(+), 101 deletions(-) delete mode 100644 node/public/js/notification.js create mode 100644 node/public/js/state-notify.js diff --git a/node/public/js/easter.js b/node/public/js/easter.js index 4db3d77..f5649eb 100644 --- a/node/public/js/easter.js +++ b/node/public/js/easter.js @@ -1,9 +1,9 @@ -cheet('↑ ↑ ↓ ↓ ← → ← → b a', function () { +cheet('↑ ↑ ↓ ↓ ← → ← → b a enter', function () { alert('Oh mein Gott! Ein wildes Konami!'); }); cheet('c t d o', function () { - showctdo(); + showNotification("CTDO - Easteregg", "Was? Nein! Wieso?", "/img/yellow.png", 4); }); cheet('d i c k b u t t', function () { diff --git a/node/public/js/notification.js b/node/public/js/notification.js deleted file mode 100644 index 7b1f04d..0000000 --- a/node/public/js/notification.js +++ /dev/null @@ -1,98 +0,0 @@ -var Notification = window.Notification || window.mozNotification || window.webkitNotification; -var data; -var laststate; - -Notification.requestPermission(function (permission) { - // console.log(permission); -}); - -function showopen() { - var instance = new Notification( - "CTDO - Status", { - body: "Der Chaostreff Dortmund ist nun offen.", - icon: "/img/green.png" - } - ); - - instance.onclick = function () { - // Something to do - }; - instance.onerror = function () { - // Something to do - }; - instance.onshow = function () { - setTimeout(function(){ - instance.close(); - }, 3000); - }; - instance.onclose = function () { - // Something to do - }; -} - -function showclose() { - var instance = new Notification( - "CTDO - Status", { - body: "Der Chaostreff Dortmund ist nun geschlossen.", - icon: "/img/red.png" - } - ); - - instance.onclick = function () { - // Something to do - }; - instance.onerror = function () { - // Something to do - }; - instance.onshow = function () { - setTimeout(function(){ - instance.close(); - }, 3000); - }; - instance.onclose = function () { - // Something to do - }; -} - -function showctdo() { - var instance = new Notification( - "CTDO - Easteregg", { - body: "Was? Nein! Wieso?", - icon: "/img/yellow.png" - } - ); - - instance.onclick = function () { - showctdo; - }; - instance.onerror = function () { - // Something to do - }; - instance.onshow = function () { - setTimeout(function(){ - instance.close(); - }, 3000); - }; - instance.onclose = function () { - // Something to do - }; -} - -window.setInterval(function(){ - $.getJSON("/api/simple/v2", function(data){ - var html = []; - - $.each(data, function(index, value){ - if (index == 'state' && value == false && laststate != false) { - laststate = false; - showclose(); - } - else if (index == 'state' && value == true && laststate != true) { - laststate = true; - showopen(); - }else { - // Nothing - } - }); - }); -}, 60000); diff --git a/node/public/js/state-notify.js b/node/public/js/state-notify.js new file mode 100644 index 0000000..67223e4 --- /dev/null +++ b/node/public/js/state-notify.js @@ -0,0 +1,21 @@ +var data; +var laststate; + +window.setInterval(function(){ + $.getJSON("/api/simple/v2", function(data){ + var html = []; + + $.each(data, function(index, value){ + if (index == 'state' && value == false && laststate != false) { + laststate = false; + showNotification("CTDO - Status", "Der Chaostreff Dortmund ist nun geschlossen.", "/img/red.png", 4); + } + else if (index == 'state' && value == true && laststate != true) { + laststate = true; + showNotification("CTDO - Status", "Der Chaostreff Dortmund ist nun offen.", "/img/green.png", 4); + }else { + // Nothing + } + }); + }); +}, 60000); diff --git a/node/views/index.jade b/node/views/index.jade index 3a836ba..8a02019 100644 --- a/node/views/index.jade +++ b/node/views/index.jade @@ -59,5 +59,6 @@ block scripts script(type="text/javascript",src="/js/vendor/raphael.2.1.0.min.js") script(type="text/javascript",src="/js/vendor/justgage.1.0.1.min.js") script(type="text/javascript",src="/js/vendor/cheet.min.js") - script(type="text/javascript",src="/js/notification.js") + script(type="text/javascript",src="/js/vendor/notification.js") + script(type="text/javascript",src="/js/state-notify.js") script(type="text/javascript",src="/js/easter.js")