dolibarr 21.0.0-beta
buttons.php
1<?php
2/*
3 * Copyright (C) 2024 Anthony Damhet <a.damhet@progiseize.fr>
4 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20// Load Dolibarr environment
21require '../../../../main.inc.php';
22
30// Protection if external user
31if ($user->socid > 0) {
33}
34
35// Includes
36require_once DOL_DOCUMENT_ROOT . '/admin/tools/ui/class/documentation.class.php';
37
38// Load documentation translations
39$langs->load('uxdocumentation');
40
41//
42$documentation = new Documentation($db);
43$morejs = [
44 '/includes/ace/src/ace.js',
45 '/includes/ace/src/ext-statusbar.js',
46 '/includes/ace/src/ext-language_tools.js',
47];
48// Output html head + body - Param is Title
49$documentation->docHeader('Buttons', $morejs);
50
51// Set view for menu and breadcrumb
52// Menu must be set in constructor of documentation class
53$documentation->view = array('Components','Buttons');
54
55// Output sidebar
56$documentation->showSidebar(); ?>
57
58<div class="doc-wrapper">
59
60 <?php $documentation->showBreadCrumb(); ?>
61
62 <div class="doc-content-wrapper">
63
64 <h1 class="documentation-title"><?php echo $langs->trans('DocButtonsTitle'); ?></h1>
65 <p class="documentation-text"><?php echo $langs->trans('DocButtonsMainDescription'); ?></p>
66
67 <!-- Summary -->
68 <?php $documentation->showSummary(); ?>
69
70 <!-- Example of simple usage -->
71 <div class="documentation-section" id="buttonsection-basicusage">
72 <h2 class="documentation-title"><?php echo $langs->trans('DocBasicUsage'); ?></h2>
73 <p class="documentation-text"><?php echo $langs->trans('DocButtonBasicUsageDescription'); ?></p>
74 <div class="documentation-example">
75 <?php
76 $label = 'My action label used for accessibility visually for impaired people';
77 $user_right = 1;
78
79 $html = '<span class="fa fa-clone paddingright" aria-hidden="true"></span> My default action';
80 $action_type = 'default';
81 $id = 'button-id-1';
82 $url = '#'.$id;
83 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right);
84
85 $html = '<span class="fa fa-trash-alt paddingright" aria-hidden="true"></span> My delete action';
86 $action_type = 'delete';
87 $id = 'button-id-2';
88 $url = '#'.$id;
89 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right);
90
91 $html = '<span class="fa fa-radiation paddingright" aria-hidden="true"></span> My danger action';
92 $action_type = 'danger';
93 $id = 'button-id-3';
94 $url = '#'.$id;
95 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right); ?>
96
97 <br><br>
98
99 <?php
100 $user_right = 0;
101
102 $html = '<span class="fa fa-clone paddingright" aria-hidden="true"></span> My default action';
103 $action_type = 'default';
104 $id = 'button-id-4';
105 $url = '#'.$id;
106 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right);
107
108 $html = '<span class="fa fa-trash-alt paddingright" aria-hidden="true"></span> My delete action';
109 $action_type = 'delete';
110 $id = 'button-id-5';
111 $url = '#'.$id;
112 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right);
113
114 $html = '<span class="fa fa-radiation paddingright" aria-hidden="true"></span> My danger action';
115 $action_type = 'danger';
116 $id = 'button-id-6';
117 $url = '#'.$id;
118 print dolGetButtonAction($label, $html, $action_type, $url, $id, $user_right); ?>
119 </div>
120 <?php
121 $lines = array(
122 '<?php',
123 '
135',
136 'print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);',
137 );
138 echo $documentation->showCode($lines, 'php'); ?>
139 </div>
140
141 <!-- Example of modal usage -->
142 <div class="documentation-section" id="buttonsection-modals">
143 <h2 class="documentation-title"><?php echo $langs->trans('DocButtonModal'); ?></h2>
144 <p class="documentation-text"><?php echo $langs->trans('DocButtonModalDescription'); ?></p>
145 <div class="documentation-example">
146 <?php
147 $userRight = 1;
148
149 $html = '<span class="fa fa-clone" paddingright" aria-hidden="true"></span> My default action';
150 $actionType = 'default';
151 $id = 'button-id-7';
152 $url = '#'.$id;
153 $params = array(
154 'confirm' => [],
155 );
156 print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);
157
158 $html = '<span class="fa fa-trash-alt paddingright" aria-hidden="true"></span> My delete action';
159 $actionType = 'delete';
160 $id = 'button-id-8';
161 $url = $_SERVER['PHP_SELF'] . '?token='.newToken().'#'.$id;
162 $params = array(
163 'confirm' => array(
164 'url' => 'your confirm action url',
165 'title' => 'Your title to display',
166 'action-btn-label' => 'Your confirm label',
167 'cancel-btn-label' => 'Your cancel label',
168 'content' => 'Content to display with <strong>HTML</strong> compatible <ul><li>test 01</li><li>test 02</li><li>test 03</li></ul>'
169 )
170 );
171 print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);
172
173 $userRight = 0;
174
175 $html = '<span class="fa fa-clone" ></span> My default action';
176 $actionType = 'delete';
177 $id = 'button-id-9';
178 $url = '#'.$id;
179 $params = array(
180 'confirm' => [],
181 );
182 print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); ?>
183 </div>
184 <?php
185 $lines = array(
186 '<?php',
187 '// Default parameters',
188 '$params = array(',
189 ' \'confirm\' => [],',
190 ');',
191 '',
192 '// Custom parameters',
193 '$params = array(',
194 ' \'confirm\' => array(',
195 ' \'url\' => \'your confirm action url\',',
196 ' \'title\' => \'Your title to display\',',
197 ' \'action-btn-label\' => \'Your confirm label\',',
198 ' \'cancel-btn-label\' => \'Your cancel label\',',
199 ' \'content\' => \'Content to display with <strong>HTML</strong> compatible <ul><li>test 01</li><li>test 02</li><li>test 03</li></ul>\',',
200 ' )',
201 ');',
202 '',
203 'print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);',
204 );
205 echo $documentation->showCode($lines, 'php'); ?>
206 </div>
207
208 <!-- Example of subbutton usage -->
209 <div class="documentation-section" id="buttonsection-submenu">
210 <h2 class="documentation-title"><?php echo $langs->trans('DocButtonSubmenu'); ?></h2>
211 <p class="documentation-text"><?php echo $langs->trans('DocButtonSubmenuDescription'); ?></p>
212 <div class="documentation-example">
213 <?php
214 $userRight = 1;
215 $html = '<span class="fa fa-clone" paddingright" aria-hidden="true"></span> My default action';
216 $actionType = 'default';
217 $id = 'button-id-7';
218 $submenu_url = str_replace(DOL_URL_ROOT, '', $_SERVER['PHP_SELF']);
219 $url = array(
220 array(
221 'lang'=>'documentation@documentation',
222 'url'=> $submenu_url.'#'.$id,
223 'label' => 'My SubAction 1',
224 'perm' => true,
225 'enabled' => true,
226 ),
227 array(
228 'lang'=>'documentation@documentation',
229 'url'=> $submenu_url.'#'.$id,
230 'label' => 'My SubAction 2',
231 'perm' => false,
232 'enabled' => true,
233 ),
234 );
235 $params = array();
236 print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params); ?>
237 </div>
238 <?php
239 $lines = array(
240 '<?php',
241 '// Simple button',
242 '$url = \'url_script\';',
243 'print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);',
244 '',
245 '// Dropdown button',
246 '$url = array(',
247 ' array(',
248 ' \'lang\' => \'langfile\',',
249 ' \'url\' => \'url_script_1\', // Url without DOL_URL_ROOT',
250 ' \'label\' => \'My SubAction 1\',',
251 ' \'perm\' => 1, // The user have the rights',
252 ' ),',
253 ' array(',
254 ' \'lang\' => \'langfile\',',
255 ' \'url\' => \'url_script_2\', // Url without DOL_URL_ROOT',
256 ' \'label\' => \'My SubAction 2\',',
257 ' \'perm\' => 0, // The user does not have the rights',
258 ' ),',
259 ');',
260 'print dolGetButtonAction($label, $html, $actionType, $url, $id, $userRight, $params);'
261 );
262 echo $documentation->showCode($lines, 'php'); ?>
263 </div>
264
265
266 <!-- Example of subbutton usage -->
267 <div class="documentation-section" id="buttonsection-icon-btn">
268 <h2 class="documentation-title"><?php echo $langs->trans('DocButtonIconsLowEmphasis'); ?></h2>
269 <p class="documentation-text"><?php echo $langs->trans('DocButtonIconsDescriptionLowEmphasis'); ?></p>
270 <div class="documentation-example">
271 <?php
272 $btnLabel = $langs->trans('Label');
273 print ' <button class="btn-low-emphasis --btn-icon" title="'.dol_escape_htmltag($btnLabel).'" aria-label="'.dol_escape_htmltag($btnLabel).'" >'.img_picto($btnLabel, 'fa-arrow-right', 'aria-hidden="true"', 0, 0, 1).'</button>';
274
275 $btnLabel = $langs->trans('Reset');
276 print ' <button class="btn-low-emphasis --btn-icon" title="'.dol_escape_htmltag($btnLabel).'" aria-label="'.dol_escape_htmltag($btnLabel).'" >'.img_picto($btnLabel, 'eraser', 'aria-hidden="true"', 0, 0, 1).'</button>';
277 ?>
278 </div>
279 <?php
280 $lines = array(
281 '<?php',
282 '$btnLabel = $langs->trans(\'Label\');',
283 'print \' <button class="btn-low-emphasis --btn-icon" title="\'.dol_escape_htmltag($btnLabel).\'" aria-label="\'.dol_escape_htmltag($btnLabel).\'" >\'.img_picto($btnLabel, \'fa-arrow-right\', \'aria-hidden="true"\', 0, 0, 1).\'</button>\';',
284 '',
285 '$btnLabel = $langs->trans(\'Reset\');',
286 'print \' <button class="btn-low-emphasis --btn-icon" title="\'.dol_escape_htmltag($btnLabel).\'" aria-label="\'.dol_escape_htmltag($btnLabel).\'" >\'.img_picto($btnLabel, \'eraser\', \'aria-hidden="true"\', 0, 0, 1).\'</button>\';',
287
288 );
289 echo $documentation->showCode($lines, 'php'); ?>
290 </div>
291
292 <!-- Example of subbutton usage -->
293 <div class="documentation-section" id="buttonsection-icon-btn">
294 <h2 class="documentation-title"><?php echo $langs->trans('DocButtonIconsForTitle'); ?></h2>
295 <div class="documentation-example">
296 <?php
297
298
299 $btnLabel = $langs->trans('Label');
300 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', 0); // Not Enough Permissions
301 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', 1); // Active
302 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', 2); // Active and selected
303 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', -1); // Functionality is disabled
304 print dolGetButtonTitle($btnLabel, '', 'fa fa-file', '#', '', -2); // Disabled without info
305
306
307 ?>
308 </div>
309 <?php
310 $lines = array(
311 '<?php',
312 '$btnLabel = $langs->trans(\'Label\');',
313 '$status = 0; // Not Enough Permissions',
314 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
315 '$status = 1; // Active',
316 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
317 '$status = 2; // Active and selected',
318 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
319 '$status = -1; // Functionality is disabled',
320 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
321 '$status = -2; // Disabled without info',
322 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-file\', \'#\', \'\', $status);',
323 );
324
325 echo $documentation->showCode($lines, 'php'); ?><div class="documentation-example">
326 <?php
327
328 $btnLabel = $langs->trans('Label', 'php');
329 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', 0, ['forcenohideoftext'=>1]); // Not Enough Permissions
330 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', 1, ['forcenohideoftext'=>1]); // Active
331 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', 2, ['forcenohideoftext'=>1]); // Active and selected
332 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', -1, ['forcenohideoftext'=>1]); // Functionality is disabled
333 print dolGetButtonTitle($btnLabel, '', 'fa fa-download', '#', '', -2, ['forcenohideoftext'=>1]); // Disabled without info
334
335 ?>
336 </div>
337
338 <?php
339 $lines = array(
340 '<?php',
341 '$btnLabel = $langs->trans(\'Label\');',
342 '$status = 0; // Not Enough Permissions',
343 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
344 '$status = 1; // Active',
345 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
346 '$status = 2; // Active and selected',
347 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
348 '$status = -1; // Functionality is disabled',
349 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
350 '$status = -2; // Disabled without info',
351 'print dolGetButtonTitle($btnLabel, \'\', \'fa fa-download\', \'#\', \'\', $status, [\'forcenohideoftext\'=>1]);',
352 );
353 echo $documentation->showCode($lines, 'php'); ?>
354 </div>
355
356 </div>
357
358</div>
359<?php
360// Output close body + html
361$documentation->docFooter();
362?>
$id
Definition account.php:48
Class to manage UI documentation.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
usage($program, $header)
Print the usage when executing scripts from install/.
Definition inc.php:94
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.