mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-06 17:48:25 +01:00
Debug notifications on browser
This commit is contained in:
@@ -44,6 +44,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
|
||||
/* Check if permission ok */
|
||||
if (Notification.permission !== "granted") {
|
||||
console.log("Ask Notification.permission");
|
||||
Notification.requestPermission()
|
||||
}
|
||||
|
||||
@@ -65,7 +66,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
function check_events() {
|
||||
if (Notification.permission === "granted")
|
||||
{
|
||||
console.log("Call check_events time_js_next_test = date we are looking for event after ="+time_js_next_test);
|
||||
console.log("Call check_events time_js_next_test = date we are looking for event after this date = "+time_js_next_test);
|
||||
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php'; ?>", {
|
||||
type: "post", // Usually post or get
|
||||
async: true,
|
||||
@@ -82,15 +83,15 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
var listofreminderids = '';
|
||||
|
||||
$.each(arr, function (index, value) {
|
||||
var url="notdefined";
|
||||
var title="Not defined";
|
||||
var body = value['tipo'] + ': ' + value['titulo'];
|
||||
var url = "notdefined";
|
||||
var title = "Not defined";
|
||||
var body = value['type'] + ': ' + value['label'];
|
||||
if (value['type'] == 'agenda' && value['location'] != null && value['location'] != '') {
|
||||
body += '\n' + value['location'];
|
||||
}
|
||||
|
||||
if(value['type'] == 'agenda' && (value['date'] != null || value['date'] != '')) {
|
||||
body += '\n' + value['date'];
|
||||
if(value['type'] == 'agenda' && (value['event_date_start_formated'] != null || event_date_start_formated['event_date_start'] != '')) {
|
||||
body += '\n' + value['event_date_start_formated'];
|
||||
}
|
||||
|
||||
if (value['type'] == 'agenda')
|
||||
@@ -105,6 +106,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
};
|
||||
|
||||
// We release the notify
|
||||
console.log("Send notification on browser");
|
||||
var noti = new Notification(title, extra);
|
||||
if (index==0 && audio)
|
||||
{
|
||||
@@ -113,19 +115,20 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
|
||||
if (noti) {
|
||||
noti.onclick = function (event) {
|
||||
console.log("An event to notify on browser was received");
|
||||
console.log("A click on notification on browser has been done");
|
||||
event.preventDefault(); // prevent the browser from focusing the Notification's tab
|
||||
window.focus();
|
||||
window.open(url, '_blank');
|
||||
noti.close();
|
||||
};
|
||||
|
||||
listofreminderids = listofreminderids + ',' + value['id']
|
||||
listofreminderids = listofreminderids + '-' + value['id_reminder']
|
||||
}
|
||||
});
|
||||
|
||||
// Update status of all notifications we sent on browser (listofreminderids)
|
||||
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderis='; ?>"+listofreminderids, {
|
||||
console.log("Flag notification as done for listofreminderids="+listofreminderids);
|
||||
$.ajax("<?php print DOL_URL_ROOT.'/core/ajax/check_notifications.php?action=stopreminder&listofreminderids='; ?>"+listofreminderids, {
|
||||
type: "get", // Usually post or get
|
||||
async: true,
|
||||
data: {time: time_js_next_test}
|
||||
@@ -136,7 +139,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("Cancel check_events. Useless because Notification.permission is "+Notification.permission);
|
||||
console.log("Cancel check_events. Useless because javascript Notification.permission is "+Notification.permission+".");
|
||||
}
|
||||
|
||||
time_js_next_test += time_auto_update;
|
||||
|
||||
Reference in New Issue
Block a user