2020-04-17 23:57:57 +02:00
|
|
|
notifimgon='<?php echo($notifs["imgon"]); ?>';
|
|
|
|
notifimgoff='<?php echo($notifs["imgoff"]); ?>';
|
|
|
|
function shidenotifs() {
|
|
|
|
var notifc=document.getElementById('notifc');
|
|
|
|
var ctrli=document.getElementById('bell');
|
|
|
|
if (notifc.style.display=='block') {
|
|
|
|
notifc.style.display='none';
|
|
|
|
ctrli.src=notifimgoff;
|
|
|
|
ctrli.title='Mostra le notifiche';
|
|
|
|
} else {
|
|
|
|
notifc.style.display='block';
|
|
|
|
ctrli.src=notifimgon;
|
|
|
|
ctrli.title='Nascondi le notifiche';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function markread(notif) {
|
|
|
|
let xhr=new XMLHttpRequest();
|
|
|
|
xhr.open('GET','notifsh.php?act=markread&id='+notif.id.replace(/^notif-([0-9]+)$/,'$1'));
|
|
|
|
xhr.responseType='json';
|
|
|
|
xhr.send();
|
|
|
|
xhr.onload=function() {
|
|
|
|
let jarr=xhr.response;
|
|
|
|
if (jarr['hmunseen']==0) {
|
|
|
|
notifimgon='imgs/bell_on.svg';
|
|
|
|
notifimgoff='imgs/bell_off.svg';
|
|
|
|
bell.src=notifimgon;
|
|
|
|
}
|
2020-05-15 20:04:58 +02:00
|
|
|
|
|
|
|
if (notif.classList.contains("notifunseen")){
|
|
|
|
// Notifica nella navbar
|
|
|
|
notif.className='notifseen';
|
|
|
|
} else if (notif.classList.contains("unseen")) {
|
|
|
|
// Notifica nella pagina di gestione notifiche
|
|
|
|
notif.classList.remove("unseen");
|
|
|
|
notif.classList.add("seen");
|
|
|
|
}
|
2020-04-17 23:57:57 +02:00
|
|
|
};
|
|
|
|
xhr.onerror=function() {
|
|
|
|
alert('La richiesta è fallita.');
|
|
|
|
};
|
|
|
|
}
|
2020-05-16 10:44:34 +02:00
|
|
|
|
|
|
|
function markdeleted(notif) {
|
2020-05-16 23:41:54 +02:00
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('GET', 'notifsh.php?act=delete&id=' + notif.id.replace(/^notif-([0-9]+)$/, '$1'));
|
|
|
|
xhr.responseType = 'json';
|
2020-05-16 10:44:34 +02:00
|
|
|
xhr.send();
|
2020-05-16 23:41:54 +02:00
|
|
|
xhr.onload = function () {
|
2020-05-16 10:44:34 +02:00
|
|
|
if (xhr.response['deleted']) {
|
2020-05-18 15:13:23 +02:00
|
|
|
notif.classList.add("deleted");
|
2020-05-16 10:44:34 +02:00
|
|
|
} else {
|
2020-05-16 23:41:54 +02:00
|
|
|
alert("Il server non ha potuto cancellare la notifica '" + notif.text + "'");
|
2020-05-16 10:44:34 +02:00
|
|
|
}
|
|
|
|
};
|
2020-05-16 23:41:54 +02:00
|
|
|
xhr.onerror = function () {
|
2020-05-16 10:44:34 +02:00
|
|
|
alert('La richiesta è fallita.');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-18 20:16:37 +02:00
|
|
|
function getAliveNotifs(){
|
|
|
|
let notifs = Array.from(document.querySelectorAll("div.notif"));
|
2020-05-19 20:00:13 +02:00
|
|
|
return notifs.filter(n => {
|
|
|
|
let classes = Array.from(n.classList);
|
|
|
|
return !(classes.includes("deleted") || classes.includes("filtered"));
|
|
|
|
})
|
2020-05-18 20:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function getAliveCheckboxes() {
|
|
|
|
let notifs = getAliveNotifs();
|
|
|
|
return notifs.map(n => n.querySelector("input.seen-checkbox"))
|
|
|
|
}
|
|
|
|
|
2020-05-18 15:13:23 +02:00
|
|
|
function readSelected() {
|
|
|
|
let selected = getSelectedNotifs()
|
|
|
|
let request = {
|
|
|
|
"act": "massread",
|
|
|
|
"ids": selected.map(div => div.id.replace(/^notif-([0-9]+)$/, '$1'))
|
|
|
|
}
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('POST', 'notifs.php');
|
|
|
|
xhr.setRequestHeader('Content-type','application/json');
|
|
|
|
xhr.responseType = 'json';
|
|
|
|
xhr.send(JSON.stringify(request));
|
|
|
|
xhr.onload = function () {
|
|
|
|
if (xhr.response['done']) {
|
|
|
|
selected.forEach(notif => {
|
|
|
|
notif.classList.remove("unseen");
|
|
|
|
notif.classList.add("seen");
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
alert("Il server non ha potuto completare la richiesta:\n" + xhr.response["error"]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhr.onerror = function () {
|
|
|
|
alert('La richiesta è fallita.');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSelected() {
|
|
|
|
let selected = getSelectedNotifs()
|
|
|
|
let request = {
|
|
|
|
"act": "massdelete",
|
|
|
|
"ids": selected.map(div => div.id.replace(/^notif-([0-9]+)$/, '$1'))
|
|
|
|
}
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('POST', 'notifs.php');
|
|
|
|
xhr.setRequestHeader('Content-type','application/json');
|
|
|
|
xhr.responseType = 'json';
|
|
|
|
xhr.send(JSON.stringify(request));
|
|
|
|
xhr.onload = function () {
|
|
|
|
if (xhr.response['done']) {
|
|
|
|
selected.forEach(notif => notif.classList.add("deleted"));
|
|
|
|
} else {
|
|
|
|
alert("Il server non ha potuto completare la richiesta:\n" + xhr.response["error"]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhr.onerror = function () {
|
|
|
|
alert('La richiesta è fallita.');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSelectedNotifs() {
|
2020-05-18 20:16:37 +02:00
|
|
|
let notifs = getAliveNotifs();
|
2020-05-18 15:13:23 +02:00
|
|
|
return notifs.filter(notif => notif.querySelector("input.seen-checkbox").checked)
|
2020-05-16 10:44:34 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 15:13:23 +02:00
|
|
|
lmt =<?php echo($notifs['lastmicrotime']); ?>;
|
2020-04-17 23:57:57 +02:00
|
|
|
chunk=0;
|
|
|
|
end=false;
|
|
|
|
loading=false;
|
|
|
|
function morenotifs() {
|
|
|
|
if (!loading && !end && notifs.scrollHeight-notifs.clientHeight-notifs.scrollTop<20) {
|
|
|
|
loading=true;
|
|
|
|
chunk++;
|
|
|
|
let xhr=new XMLHttpRequest();
|
|
|
|
xhr.open('GET','notifsh.php?act=loadchunk&chunk='+chunk);
|
|
|
|
xhr.responseType='json';
|
|
|
|
xhr.send();
|
|
|
|
xhr.onload=function() {
|
|
|
|
let jarr=xhr.response;
|
|
|
|
//console.log(jarr);
|
|
|
|
let i=0, html='';
|
|
|
|
for (i=0; i<jarr.length; i++)
|
|
|
|
html+=jarr[i];
|
|
|
|
notifs.innerHTML+=html;
|
|
|
|
if (jarr.length<<?php echo($notifs['chunksize']); ?>)
|
|
|
|
end=true;
|
|
|
|
loading=false;
|
|
|
|
};
|
|
|
|
xhr.onerror=function() {
|
|
|
|
alert('La richiesta è fallita.');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadingupd=false;
|
|
|
|
function updnotifs() {
|
|
|
|
if (!loadingupd) {
|
|
|
|
loadingupd=true;
|
|
|
|
let xhr=new XMLHttpRequest();
|
|
|
|
xhr.open('GET','notifsh.php?act=loadnew&lmt='+lmt);
|
|
|
|
xhr.responseType='json';
|
|
|
|
xhr.send();
|
|
|
|
xhr.onload=function() {
|
|
|
|
let jarr=xhr.response;
|
|
|
|
//console.log(jarr);
|
|
|
|
let i=0, html='';
|
|
|
|
for (i=0; i<jarr['buf'].length; i++)
|
|
|
|
html+=jarr['buf'][i];
|
|
|
|
notifs.innerHTML=html+notifs.innerHTML;
|
|
|
|
lmt=jarr['newlmt'];
|
|
|
|
if (jarr['newunread']) {
|
|
|
|
notifimgoff='imgs/bell_act_on.svg';
|
|
|
|
notifimgon='imgs/bell_act_off.svg';
|
|
|
|
(notifc.style.display=='block') ? bell.src=notifimgoff : bell.src=notifimgon;
|
|
|
|
}
|
|
|
|
loadingupd=false;
|
|
|
|
};
|
|
|
|
xhr.onerror=function() {
|
|
|
|
alert('La richiesta è fallita.');
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
console.log('Già sto caricando...');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updint=setInterval(updnotifs,3000);
|