dolibarr 24.0.0-beta
inc_seteventmessage.php
1<?php
2
11if (!defined('DOL_VERSION')) {die();}
12
13global $documentation, $setEventMessageJsContextTitle;
14
15if ($documentation === null || !($documentation instanceof Documentation)) { return; }
16
17
18?>
19
20<div class="documentation-section">
21 <h2 id="titlesection-tool-seteventmessage" class="documentation-title"><?php print $setEventMessageJsContextTitle ?? 'Set event message tool'; ?></h2>
22
23 <p>
24 Instead of calling JNotify directly in your code, use Dolibarr’s setEventMessage tool.
25 Dolibarr provides the configuration option DISABLE_JQUERY_JNOTIFY, which disables the jQuery JNotify system, usually because another notification library will be used instead.
26 </p>
27
28 <p>
29 If you rely on Dolibarr.tools.setEventMessage(), your code remains compatible even if the underlying notification system changes.
30 The setEventMessage tool can be replaced internally without requiring any changes in your modules or custom scripts.
31 </p>
32 <p>
33 This means all developers can write features without worrying about frontend compatibility or future library replacements. Enjoy!
34
35 </p>
36 <?php
37 $lines = array(
38 '<script nonce="<?php print getNonce() ?>" >',
39 ' document.addEventListener(\'Dolibarr:Ready\', function(e) {',
40 '',
41 ' document.getElementById(\'setEventMessage-success\').addEventListener(\'click\', function(e) {',
42 ' Dolibarr.tools.setEventMessage(\'Success Test\');',
43 ' });',
44 '',
45 ' document.getElementById(\'setEventMessage-error\').addEventListener(\'click\', function(e) {',
46 ' Dolibarr.tools.setEventMessage(\'Error Test\', \'errors\');',
47 ' });',
48 '',
49 ' document.getElementById(\'setEventMessage-error-sticky\').addEventListener(\'click\', function(e) {',
50 ' Dolibarr.tools.setEventMessage(\'Error Test\', \'errors\', true);',
51 ' });',
52 '',
53 ' document.getElementById(\'setEventMessage-warning\').addEventListener(\'click\', function(e) {',
54 ' Dolibarr.tools.setEventMessage(\'Warning Test\', \'warnings\');',
55 ' });',
56 '',
57 ' });',
58 '</script>',
59 );
60 $documentation->showCode($lines, 'php'); ?>
61 <div class="documentation-example">
62
63 <script nonce="<?php print getNonce() ?>" >
64 document.addEventListener('Dolibarr:Ready', function(e) {
65
66 document.getElementById('setEventMessage-success').addEventListener('click', function(e) {
67 Dolibarr.tools.setEventMessage('Success Test')
68 });
69
70 document.getElementById('setEventMessage-error').addEventListener('click', function(e) {
71 Dolibarr.tools.setEventMessage('Error Test', 'errors');
72 });
73
74 document.getElementById('setEventMessage-error-sticky').addEventListener('click', function(e) {
75 Dolibarr.tools.setEventMessage('Error Test', 'errors', true);
76 });
77
78 document.getElementById('setEventMessage-warning').addEventListener('click', function(e) {
79 Dolibarr.tools.setEventMessage('Warning Test', 'warnings');
80 });
81
82 });
83 </script>
84 <button id="setEventMessage-success" class="button">Alert success</button>
85 <button id="setEventMessage-error" class="button">Alert error</button>
86 <button id="setEventMessage-error-sticky" class="button">Alert error sticky</button>
87 <button id="setEventMessage-warning" class="button">Alert warning</button>
88 </div>
89
90</div>
Class to manage UI documentation.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button