forked from Wavyzz/dolibarr
Make notification by browser popup working.
This commit is contained in:
@@ -79,6 +79,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
success: function (result) {
|
||||
console.log(result);
|
||||
var arrayofpastreminders = Object.values(result.pastreminders);
|
||||
console.log("arrayofpastreminders.length"+arrayofpastreminders.length);
|
||||
if (arrayofpastreminders && arrayofpastreminders.length > 0) {
|
||||
var audio = null;
|
||||
<?php
|
||||
@@ -87,9 +88,9 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
}
|
||||
?>
|
||||
var listofreminderids = '';
|
||||
var noti = []
|
||||
|
||||
$.each(arrayofpastreminders, function (index, value) {
|
||||
console.log(index);
|
||||
console.log(value);
|
||||
var url = "notdefined";
|
||||
var title = "Not defined";
|
||||
@@ -104,30 +105,32 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
|
||||
if (value.type == 'agenda')
|
||||
{
|
||||
url = '<?php echo DOL_URL_ROOT.'/comm/action/card.php?id='; ?>' + value.id;
|
||||
title = '<?php print $langs->trans('AgendaReminder') ?>';
|
||||
url = '<?php echo DOL_URL_ROOT.'/comm/action/card.php?id='; ?>' + value.id_agenda;
|
||||
title = '<?php print $langs->trans('EventReminder') ?>';
|
||||
}
|
||||
var extra = {
|
||||
icon: '<?php print DOL_URL_ROOT.'/theme/common/bell.png'; ?>',
|
||||
//image: '<?php print DOL_URL_ROOT.'/theme/common/bell.png'; ?>',
|
||||
body: body,
|
||||
tag: value.id
|
||||
tag: value.id_agenda,
|
||||
requireInteraction: true
|
||||
};
|
||||
|
||||
// We release the notify
|
||||
console.log("Send notification on browser");
|
||||
var noti = new Notification(title, extra);
|
||||
noti[index] = new Notification(title, extra);
|
||||
if (index==0 && audio)
|
||||
{
|
||||
audio.play();
|
||||
}
|
||||
|
||||
if (noti) {
|
||||
noti.onclick = function (event) {
|
||||
if (noti[index]) {
|
||||
noti[index].onclick = function (event) {
|
||||
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();
|
||||
noti[index].close();
|
||||
};
|
||||
|
||||
listofreminderids = (listofreminderids == '' ? '' : listofreminderids + ',') + value.id_reminder
|
||||
@@ -140,7 +143,7 @@ if (!($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root.'/' || $_SERVER['HTTP
|
||||
type: "post", // Usually post or get
|
||||
async: true,
|
||||
data: { time_js_next_test: time_js_next_test, token: 'notrequired' }
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log("No past reminder found, next try at "+time_js_next_test);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user