mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-10 19:41:26 +01:00
Clean code for browser notifications
This commit is contained in:
@@ -62,13 +62,11 @@ class Notify
|
||||
*/
|
||||
public $fk_project;
|
||||
|
||||
// Les codes actions sont definis dans la table llx_notify_def
|
||||
|
||||
// codes actions supported are
|
||||
// @todo defined also into interface_50_modNotification_Notification.class.php
|
||||
public $arrayofnotifsupported = array(
|
||||
// This codes actions are defined into table llx_notify_def
|
||||
static public $arrayofnotifsupported = array(
|
||||
'BILL_VALIDATE',
|
||||
'BILL_PAYED',
|
||||
'ORDER_CREATE',
|
||||
'ORDER_VALIDATE',
|
||||
'PROPAL_VALIDATE',
|
||||
'PROPAL_CLOSE_SIGNED',
|
||||
|
||||
@@ -68,6 +68,8 @@ print ' var time_auto_update = '.$conf->global->MAIN_BROWSER_NOTIFICATION_FREQUE
|
||||
print ' var time_js_next_test;'."\n";
|
||||
?>
|
||||
|
||||
/* Check if Notification is supported */
|
||||
if ("Notification" in window) {
|
||||
/* Check if permission ok */
|
||||
if (Notification.permission !== "granted") {
|
||||
console.log("Ask Notification.permission");
|
||||
@@ -83,6 +85,9 @@ var time_first_execution = <?php echo max(3, empty($conf->global->MAIN_BROWSER_N
|
||||
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.");
|
||||
}
|
||||
|
||||
|
||||
function first_execution() {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
* \brief File of class of triggers for notification module
|
||||
*/
|
||||
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
|
||||
{
|
||||
// @todo Defined also into notify.class.php
|
||||
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'
|
||||
);
|
||||
public $listofmanagedevents = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -66,6 +48,8 @@ class InterfaceNotification extends DolibarrTriggers
|
||||
// 'development', 'experimental', 'dolibarr' or version
|
||||
$this->version = self::VERSION_DOLIBARR;
|
||||
$this->picto = 'email';
|
||||
|
||||
$this->listofmanagedevents = Notify::$arrayofnotifsupported;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,15 +69,13 @@ class InterfaceNotification extends DolibarrTriggers
|
||||
return 0; // Module not active, we do nothing
|
||||
}
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
|
||||
$notify = new Notify($this->db);
|
||||
|
||||
if (!in_array($action, $notify->arrayofnotifsupported)) {
|
||||
if (!in_array($action, $this->listofmanagedevents)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
|
||||
|
||||
$notify = new Notify($this->db);
|
||||
$notify->send($action, $object);
|
||||
|
||||
return 1;
|
||||
@@ -114,6 +96,7 @@ class InterfaceNotification extends DolibarrTriggers
|
||||
$sql = "SELECT rowid, code, label, description, elementtype";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
|
||||
$sql .= $this->db->order("rang, elementtype, code");
|
||||
|
||||
dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql) {
|
||||
|
||||
Reference in New Issue
Block a user