mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-11 12:01:23 +01:00
Clean code for browser notifications
This commit is contained in:
@@ -62,13 +62,11 @@ class Notify
|
|||||||
*/
|
*/
|
||||||
public $fk_project;
|
public $fk_project;
|
||||||
|
|
||||||
// Les codes actions sont definis dans la table llx_notify_def
|
// This codes actions are defined into table llx_notify_def
|
||||||
|
static public $arrayofnotifsupported = array(
|
||||||
// codes actions supported are
|
|
||||||
// @todo defined also into interface_50_modNotification_Notification.class.php
|
|
||||||
public $arrayofnotifsupported = array(
|
|
||||||
'BILL_VALIDATE',
|
'BILL_VALIDATE',
|
||||||
'BILL_PAYED',
|
'BILL_PAYED',
|
||||||
|
'ORDER_CREATE',
|
||||||
'ORDER_VALIDATE',
|
'ORDER_VALIDATE',
|
||||||
'PROPAL_VALIDATE',
|
'PROPAL_VALIDATE',
|
||||||
'PROPAL_CLOSE_SIGNED',
|
'PROPAL_CLOSE_SIGNED',
|
||||||
|
|||||||
@@ -68,22 +68,27 @@ print ' var time_auto_update = '.$conf->global->MAIN_BROWSER_NOTIFICATION_FREQUE
|
|||||||
print ' var time_js_next_test;'."\n";
|
print ' var time_js_next_test;'."\n";
|
||||||
?>
|
?>
|
||||||
|
|
||||||
/* Check if permission ok */
|
/* Check if Notification is supported */
|
||||||
if (Notification.permission !== "granted") {
|
if ("Notification" in window) {
|
||||||
|
/* Check if permission ok */
|
||||||
|
if (Notification.permission !== "granted") {
|
||||||
console.log("Ask Notification.permission");
|
console.log("Ask Notification.permission");
|
||||||
Notification.requestPermission()
|
Notification.requestPermission()
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Launch timer */
|
||||||
|
|
||||||
|
// We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one.
|
||||||
|
//var time_first_execution = (time_auto_update + (time_js_next_test - nowtime)) * 1000; //need milliseconds
|
||||||
|
var time_first_execution = <?php echo max(3, empty($conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>;
|
||||||
|
|
||||||
|
setTimeout(first_execution, time_first_execution * 1000);
|
||||||
|
time_js_next_test = nowtime + time_first_execution;
|
||||||
|
console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" time_js_next_check = "+time_js_next_test);
|
||||||
|
} else {
|
||||||
|
console.log("This browser in this context does not support Notification.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Launch timer */
|
|
||||||
|
|
||||||
// We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one.
|
|
||||||
//var time_first_execution = (time_auto_update + (time_js_next_test - nowtime)) * 1000; //need milliseconds
|
|
||||||
var time_first_execution = <?php echo max(3, empty($conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION) ? 0 : $conf->global->MAIN_BROWSER_NOTIFICATION_CHECK_FIRST_EXECUTION); ?>;
|
|
||||||
|
|
||||||
setTimeout(first_execution, time_first_execution * 1000);
|
|
||||||
time_js_next_test = nowtime + time_first_execution;
|
|
||||||
console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" time_js_next_check = "+time_js_next_test);
|
|
||||||
|
|
||||||
|
|
||||||
function first_execution() {
|
function first_execution() {
|
||||||
console.log("Call first_execution then set repeat time to time_auto_update = MAIN_BROWSER_NOTIFICATION_FREQUENCY = "+time_auto_update);
|
console.log("Call first_execution then set repeat time to time_auto_update = MAIN_BROWSER_NOTIFICATION_FREQUENCY = "+time_auto_update);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
* \brief File of class of triggers for notification module
|
* \brief File of class of triggers for notification module
|
||||||
*/
|
*/
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,26 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
|
|||||||
*/
|
*/
|
||||||
class InterfaceNotification extends DolibarrTriggers
|
class InterfaceNotification extends DolibarrTriggers
|
||||||
{
|
{
|
||||||
// @todo Defined also into notify.class.php
|
public $listofmanagedevents = array();
|
||||||
public $listofmanagedevents = array(
|
|
||||||
'BILL_VALIDATE',
|
|
||||||
'BILL_PAYED',
|
|
||||||
'ORDER_CREATE',
|
|
||||||
'ORDER_VALIDATE',
|
|
||||||
'PROPAL_VALIDATE',
|
|
||||||
'PROPAL_CLOSE_SIGNED',
|
|
||||||
'FICHINTER_VALIDATE',
|
|
||||||
'FICHINTER_ADD_CONTACT',
|
|
||||||
'ORDER_SUPPLIER_VALIDATE',
|
|
||||||
'ORDER_SUPPLIER_APPROVE',
|
|
||||||
'ORDER_SUPPLIER_REFUSE',
|
|
||||||
'SHIPPING_VALIDATE',
|
|
||||||
'EXPENSE_REPORT_VALIDATE',
|
|
||||||
'EXPENSE_REPORT_APPROVE',
|
|
||||||
'HOLIDAY_VALIDATE',
|
|
||||||
'HOLIDAY_APPROVE',
|
|
||||||
'ACTION_CREATE'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -66,6 +48,8 @@ class InterfaceNotification extends DolibarrTriggers
|
|||||||
// 'development', 'experimental', 'dolibarr' or version
|
// 'development', 'experimental', 'dolibarr' or version
|
||||||
$this->version = self::VERSION_DOLIBARR;
|
$this->version = self::VERSION_DOLIBARR;
|
||||||
$this->picto = 'email';
|
$this->picto = 'email';
|
||||||
|
|
||||||
|
$this->listofmanagedevents = Notify::$arrayofnotifsupported;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,15 +69,13 @@ class InterfaceNotification extends DolibarrTriggers
|
|||||||
return 0; // Module not active, we do nothing
|
return 0; // Module not active, we do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
|
if (!in_array($action, $this->listofmanagedevents)) {
|
||||||
$notify = new Notify($this->db);
|
|
||||||
|
|
||||||
if (!in_array($action, $notify->arrayofnotifsupported)) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||||
|
|
||||||
|
$notify = new Notify($this->db);
|
||||||
$notify->send($action, $object);
|
$notify->send($action, $object);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -114,6 +96,7 @@ class InterfaceNotification extends DolibarrTriggers
|
|||||||
$sql = "SELECT rowid, code, label, description, elementtype";
|
$sql = "SELECT rowid, code, label, description, elementtype";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
|
$sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
|
||||||
$sql .= $this->db->order("rang, elementtype, code");
|
$sql .= $this->db->order("rang, elementtype, code");
|
||||||
|
|
||||||
dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
|
dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
|
|||||||
Reference in New Issue
Block a user