dolibarr 22.0.5
badges.inc.php
1<?php
2/* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
3 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
4 */
5if (!defined('ISLOADEDBYSTEELSHEET')) {
6 die('Must be called by steelsheet');
7}
8
9// From theme_vars.inc, must be included by steelsheet
21'
22@phan-var-force string $badgePrimary
23@phan-var-force string $badgeSecondary
24@phan-var-force string $badgeSuccess
25@phan-var-force string $badgeDanger
26@phan-var-force string $badgeWarning
27@phan-var-force string $badgeInfo
28@phan-var-force string $badgeLight
29@phan-var-force string $badgeDark
30@phan-var-force string $colorblind_deuteranopes_badgeWarning
31';
32?>
33
34/* IDE Hack <style type="text/css"> */
35
36/* Badge style is based on bootstrap framework */
37
38.badge {
39 display: inline-block;
40 padding: .1em .35em;
41 font-size: 80%;
42 font-weight: 700 !important;
43 line-height: 1;
44 text-align: center;
45 white-space: nowrap;
46 vertical-align: baseline;
47 border-radius: .25rem;
48 transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
49 border-width: 2px;
50 border-style: solid;
51 border-color: rgba(255,255,255,0);
52 box-sizing: border-box;
53}
54
55.badge-status {
56 font-size: 0.95em;
57 padding: .19em .35em; /* more than 0.19 generate a change into height of lines */
58}
59.tabBar .arearef .statusref .badge-status, .tabBar .arearefnobottom .statusref .badge-status {
60 font-size: 1.1em;
61 padding: .4em .4em;
62}
63/* Force values for small screen 767 */
64@media only screen and (max-width: 767px)
65{
66 .tabBar .arearef .statusref .badge-status, .tabBar .arearefnobottom .statusref .badge-status {
67 font-size: 0.95em;
68 padding: .3em .2em;
69 }
70}
71
72.tabs .badge {
73 padding-right: .5em;
74 padding-left: .5em;
75 border-radius: 0.25rem;
76}
77
78.badge-pill{
79 /* Use the .badge-pill modifier class to make badges more rounded (with a larger border-radius and additional horizontal padding). */
80 padding-right: .8em;
81 padding-left: 0.8em;
82 border-radius: 0.5rem;
83}
84
85.badge-dot {
86 padding: 0;
87 border-radius: 50%;
88 padding: 0.45em;
89 vertical-align: text-top;
90}
91
92a.badge:focus, a.badge:hover {
93 text-decoration: none;
94}
95
96.liste_titre .badge:not(.nochangebackground) {
97 background-color: <?php print $badgeSecondary; ?>;
98 color: #fff;
99}
100
101span.badgeneutral {
102 padding: 2px 7px 2px 7px;
103 background-color: #e4e4e4;
104 color: #666;
105 border-radius: 10px;
106 white-space: nowrap;
107}
108
109
110/* PRIMARY */
111.badge-primary{
112 color: #fff !important;
113 background-color: <?php print $badgePrimary; ?>;
114}
115a.badge-primary.focus, a.badge-primary:focus {
116 outline: 0;
117 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgePrimary, 0.5); ?>;
118}
119a.badge-primary:focus, a.badge-primary:hover {
120 color: #fff !important;
121 background-color: <?php print colorDarker($badgePrimary, 10); ?>;
122}
123
124/* SECONDARY */
125.badge-secondary, .tabs .badge {
126 color: #fff !important;
127 background-color: <?php print $badgeSecondary; ?>;
128}
129a.badge-secondary.focus, a.badge-secondary:focus {
130 outline: 0;
131 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSecondary, 0.5); ?>;
132}
133a.badge-secondary:focus, a.badge-secondary:hover {
134 color: #fff !important;
135 background-color: <?php print colorDarker($badgeSecondary, 10); ?>;
136}
137
138/* SUCCESS */
139.badge-success {
140 color: #fff !important;
141 background-color: <?php print $badgeSuccess; ?>;
142}
143a.badge-success.focus, a.badge-success:focus {
144 outline: 0;
145 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSuccess, 0.5); ?>;
146}
147a.badge-success:focus, a.badge-success:hover {
148 color: #fff !important;
149 background-color: <?php print colorDarker($badgeSuccess, 10); ?>;
150}
151
152/* DANGER */
153.badge-danger {
154 color: #fff !important;
155 background-color: <?php print $badgeDanger; ?>;
156}
157a.badge-danger.focus, a.badge-danger:focus {
158 outline: 0;
159 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDanger, 0.5); ?>;
160}
161a.badge-danger:focus, a.badge-danger:hover {
162 color: #fff !important;
163 background-color: <?php print colorDarker($badgeDanger, 10); ?>;
164}
165
166/* WARNING */
167.badge-warning {
168 color: #fff !important;
169 background-color: <?php print $badgeWarning; ?>;
170}
171a.badge-warning.focus, a.badge-warning:focus {
172 outline: 0;
173 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeWarning, 0.5); ?>;
174}
175a.badge-warning:focus, a.badge-warning:hover {
176 color: #212529 !important;
177 background-color: <?php print colorDarker($badgeWarning, 10); ?>;
178}
179
180/* WARNING colorblind */
181body[class*="colorblind-"] .badge-warning {
182 background-color: <?php print $colorblind_deuteranopes_badgeWarning; ?>;
183 }
184body[class*="colorblind-"] a.badge-warning.focus,body[class^="colorblind-"] a.badge-warning:focus {
185 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($colorblind_deuteranopes_badgeWarning, 0.5); ?>;
186}
187body[class*="colorblind-"] a.badge-warning:focus, a.badge-warning:hover {
188 background-color: <?php print colorDarker($colorblind_deuteranopes_badgeWarning, 10); ?>;
189}
190
191/* INFO */
192.badge-info {
193 color: #fff !important;
194 background-color: <?php print $badgeInfo; ?>;
195}
196a.badge-info.focus, a.badge-info:focus {
197 outline: 0;
198 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeInfo, 0.5); ?>;
199}
200a.badge-info:focus, a.badge-info:hover {
201 color: #fff !important;
202 background-color: <?php print colorDarker($badgeInfo, 10); ?>;
203}
204
205/* LIGHT */
206.badge-light {
207 color: #212529 !important;
208 background-color: <?php print $badgeLight; ?>;
209}
210a.badge-light.focus, a.badge-light:focus {
211 outline: 0;
212 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeLight, 0.5); ?>;
213}
214a.badge-light:focus, a.badge-light:hover {
215 color: #212529 !important;
216 background-color: <?php print colorDarker($badgeLight, 10); ?>;
217}
218
219/* DARK */
220.badge-dark {
221 color: #fff !important;
222 background-color: <?php print $badgeDark; ?>;
223}
224a.badge-dark.focus, a.badge-dark:focus {
225 outline: 0;
226 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDark, 0.5); ?>;
227}
228a.badge-dark:focus, a.badge-dark:hover {
229 color: #fff !important;
230 background-color: <?php print colorDarker($badgeDark, 10); ?>;
231}
232
233
234@media only screen and (max-width: 570px)
235{
236 span.badge.badge-status {
237 overflow: hidden;
238 max-width: 130px;
239 text-overflow: ellipsis;
240 }
241}
242
243
244/* STATUS BADGES */
245<?php
246for ($i = 0; $i <= 10; $i++) {
247 /* Default Status */
248 _createStatusBadgeCss((string) $i, '', "STATUS".$i);
249
250 // create status for accessibility
251 _createStatusBadgeCss((string) $i, 'colorblind_deuteranopes_', "COLORBLIND STATUS".$i, 'body[class*="colorblind-"] ');
252}
253
254_createStatusBadgeCss('1b', '', "STATUS1b");
255_createStatusBadgeCss('4b', '', "STATUS4b");
256
257
269function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentLabel = '', $cssPrefix = '')
270{
271 global ${$statusVarNamePrefix.'badgeStatus'.$statusName}, ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
272
273 if (!empty(${$statusVarNamePrefix.'badgeStatus'.$statusName})) {
274 print "\n/* ".strtoupper($commentLabel)." - ".$statusName." */\n";
275
276 $thisBadgeBackgroundColor = $thisBadgeBorderColor = ${$statusVarNamePrefix.'badgeStatus'.$statusName};
277
278 $TBadgeBorderOnly = array('0', '1b', '3', '4b', '5', '7', '10');
279 $thisBadgeTextColor = colorIsLight(${$statusVarNamePrefix.'badgeStatus'.$statusName}) ? '#212529' : '#ffffff';
280
281 if (!empty(${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName})) {
282 $thisBadgeTextColor = ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
283 }
284
285 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
286 $thisBadgeTextColor = '#9c850b';
287 $thisBadgeBackgroundColor = "hsl(0, 0%, 0%, 0)";
288 }
289
290 if (in_array((string) $statusName, array('4b', '7'))) {
291 $thisBadgeTextColor = '#25a580';
292 }
293 if (in_array((string) $statusName, array('0', '5', '9', '10'))) {
294 $thisBadgeTextColor = '#999999';
295 }
296 if (in_array((string) $statusName, array('6'))) {
297 $thisBadgeTextColor = '#777777';
298 }
299
300 // badge-statusX
301 print $cssPrefix.".badge-status".$statusName." {\n";
302 print " color: ".$thisBadgeTextColor." !important;\n";
303 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
304 print " border-color: ".$thisBadgeBorderColor." !important;\n";
305 }
306 if ($thisBadgeBackgroundColor != '') {
307 print " background-color: ".$thisBadgeBackgroundColor." !important;\n";
308 }
309 print "}\n";
310
311 print $cssPrefix.".font-status".$statusName." {\n";
312 if ($thisBadgeBackgroundColor != '') {
313 print " color: ".$thisBadgeBackgroundColor." !important;\n";
314 }
315 print "}\n";
316
317 // badge-statusX:focus
318
319 print $cssPrefix.".badge-status".$statusName.".focus, ".$cssPrefix.".badge-status".$statusName.":focus {\n";
320 print " outline: 0;\n";
321 print " box-shadow: 0 0 0 0.2rem ".colorHexToRgb($thisBadgeBackgroundColor, 0.5)." !important;\n";
322 print "}\n";
323
324 print $cssPrefix.".badge-status".$statusName.":focus, ".$cssPrefix.".badge-status".$statusName.":hover {\n";
325 print " color: ".$thisBadgeTextColor." !important;\n";
326 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
327 print " border-color: ".colorDarker($thisBadgeBorderColor, 10)." !important;\n";
328 }
329 print "}\n";
330 }
331}
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
colorHexToRgb($hex, $alpha=false, $returnArray=false)
colorDarker($hex, $percent)
colorIsLight($stringcolor)
Return true if the color is light.