diff --git a/notifications/static/notifications/notify.js b/notifications/static/notifications/notify.js index 7e464a5..df21a25 100644 --- a/notifications/static/notifications/notify.js +++ b/notifications/static/notifications/notify.js @@ -18,11 +18,9 @@ function fill_notification_badge(data) { function fill_notification_list(data) { var menu = document.getElementById(notify_menu_id); if (menu) { - menu.innerHTML = ""; - for (var i=0; i < data.unread_list.length; i++) { - var item = data.unread_list[i]; - console.log(item) - var message = "" + var content = []; + menu.innerHTML = data.unread_list.map(function (item) { + var message = ""; if(typeof item.actor !== 'undefined'){ message = item.actor; } @@ -35,9 +33,8 @@ function fill_notification_list(data) { if(typeof item.timestamp !== 'undefined'){ message = message + " " + item.timestamp; } - - menu.innerHTML = menu.innerHTML + "
  • "+ message + "
  • "; - } + return '
  • ' + message + '
  • '; + }).join('') } } @@ -50,17 +47,13 @@ function fetch_api_data() { //only fetch data if a function is setup var r = new XMLHttpRequest(); r.open("GET", notify_api_url+'?max='+notify_fetch_count, true); - r.onreadystatechange = function () { - if (r.readyState != 4 || r.status != 200) { - consecutive_misfires++; - } - else { - consecutive_misfires = 0; - for (var i=0; i < registered_functions.length; i++) { - var func = registered_functions[i]; - func(JSON.parse(r.responseText)); - } - } + r.onerror = function () { + consecutive_misfires++; + } + r.onready = function () { + consecutive_misfires = 0; + var data = JSON.parse(r.responseText); + registered_functions.forEach(function (func) { func(data); }); } r.send(); } @@ -75,4 +68,4 @@ function fetch_api_data() { } } -setTimeout(fetch_api_data,1000); \ No newline at end of file +setTimeout(fetch_api_data, 1000);