dolibarr 25.0.0-alpha
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 The setEventMessage tool is defined with <code>{ overwrite: true }</code>, so a module providing another notification library can replace it.
34 The script must be loaded after the Dolibarr context files (this is the case for module js files), otherwise the core tool would replace it:
35 </p>
36 <?php
37 $lines = array(
38 '<script nonce="<?php print getNonce() ?>" >',
39 ' document.addEventListener(\'Dolibarr:Init\', function(e) {',
40 ' Dolibarr.defineTool(\'setEventMessage\', (msg, status = \'mesgs\', sticky = false) => {',
41 ' // Call your notification library here',
42 ' }, { overwrite: true });',
43 ' });',
44 '</script>',
45 );
46 $documentation->showCode($lines, 'php');
47 ?>
48 <p>
49 This means all developers can write features without worrying about frontend compatibility or future library replacements. Enjoy!
50
51 </p>
52 <?php
53 $lines = array(
54 '<script nonce="<?php print getNonce() ?>" >',
55 ' document.addEventListener(\'Dolibarr:Ready\', function(e) {',
56 '',
57 ' document.getElementById(\'setEventMessage-success\').addEventListener(\'click\', function(e) {',
58 ' Dolibarr.tools.setEventMessage(\'Success Test\');',
59 ' });',
60 '',
61 ' document.getElementById(\'setEventMessage-error\').addEventListener(\'click\', function(e) {',
62 ' Dolibarr.tools.setEventMessage(\'Error Test\', \'errors\');',
63 ' });',
64 '',
65 ' document.getElementById(\'setEventMessage-error-sticky\').addEventListener(\'click\', function(e) {',
66 ' Dolibarr.tools.setEventMessage(\'Error Test\', \'errors\', true);',
67 ' });',
68 '',
69 ' document.getElementById(\'setEventMessage-warning\').addEventListener(\'click\', function(e) {',
70 ' Dolibarr.tools.setEventMessage(\'Warning Test\', \'warnings\');',
71 ' });',
72 '',
73 ' });',
74 '</script>',
75 );
76 $documentation->showCode($lines, 'php'); ?>
77 <div class="documentation-example">
78
79 <script nonce="<?php print getNonce() ?>" >
80 document.addEventListener('Dolibarr:Ready', function(e) {
81
82 document.getElementById('setEventMessage-success').addEventListener('click', function(e) {
83 Dolibarr.tools.setEventMessage('Success Test')
84 });
85
86 document.getElementById('setEventMessage-error').addEventListener('click', function(e) {
87 Dolibarr.tools.setEventMessage('Error Test', 'errors');
88 });
89
90 document.getElementById('setEventMessage-error-sticky').addEventListener('click', function(e) {
91 Dolibarr.tools.setEventMessage('Error Test', 'errors', true);
92 });
93
94 document.getElementById('setEventMessage-warning').addEventListener('click', function(e) {
95 Dolibarr.tools.setEventMessage('Warning Test', 'warnings');
96 });
97
98 });
99 </script>
100 <button id="setEventMessage-success" class="button">Alert success</button>
101 <button id="setEventMessage-error" class="button">Alert error</button>
102 <button id="setEventMessage-error-sticky" class="button">Alert error sticky</button>
103 <button id="setEventMessage-warning" class="button">Alert warning</button>
104 </div>
105
106</div>
write(string $newInnerBlock)
Replace the whole permissions block, markers included, in a single write.
Class to manage UI documentation.
multi select button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button