(function () {
const original_title = $('title').text()
let update_data = () => {
$.getJSON(window.TROJSTEN_NOTIFY_LIST_URL, (data) => {
let content = []
data.notifications.forEach(notification => {
content.push('
' + notification.message + '');
})
$('#notification-box-content').html(content.join(''))
if (data.unread > 0) {
$('#notification-box-number').show()
$('#notification-box-number').text(data.unread)
$('title').text('(' + data.unread + ') ' + original_title)
} else {
$('#notification-box-number').hide()
$('#notification-box-content').html('Žiadne notifikácie!')
$('title').text(original_title)
}
$('#notification-box-content').append('')
if (data.unread > 0) {
$('#notification-box-content').append(' Označiť všetky za prečítané')
$("#notifications-read-all").click(() => {
$.post(window.TROJSTEN_NOTIFY_READ_ALL_URL, update_data)
})
}
$('#notification-box-content').append(' Nastavenia notifikácií')
})
}
update_data()
setInterval(update_data, 5*60*1000)
})()