dolibarr 22.0.5
badges.inc.php
1<?php
2/* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
3 * Copyright (C) 2025 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: 1em;
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.badge-pill, .tabs .badge {
73 padding-right: .5em;
74 padding-left: .5em;
75 border-radius: 0.25rem;
76}
77
78.badge-dot {
79 padding: 0;
80 border-radius: 50%;
81 padding: 0.45em;
82 vertical-align: unset;
83}
84
85a.badge:focus, a.badge:hover {
86 text-decoration: none;
87}
88
89.liste_titre .badge:not(.nochangebackground) {
90 background-color: <?php print $badgeSecondary; ?>;
91 color: #fff;
92}
93
94span.badgeneutral {
95 padding: 2px 7px 2px 7px;
96 background-color: #e4e4e4;
97 color: #666;
98 border-radius: 10px;
99 white-space: nowrap;
100}
101
102
103/* PRIMARY */
104.badge-primary{
105 color: #fff !important;
106 background-color: <?php print $badgePrimary; ?>;
107}
108a.badge-primary.focus, a.badge-primary:focus {
109 outline: 0;
110 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgePrimary, 0.5); ?>;
111}
112a.badge-primary:focus, a.badge-primary:hover {
113 color: #fff !important;
114 background-color: <?php print colorDarker($badgePrimary, 10); ?>;
115}
116
117/* SECONDARY */
118.badge-secondary, .tabs .badge {
119 color: #fff !important;
120 background-color: <?php print $badgeSecondary; ?>;
121}
122a.badge-secondary.focus, a.badge-secondary:focus {
123 outline: 0;
124 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSecondary, 0.5); ?>;
125}
126a.badge-secondary:focus, a.badge-secondary:hover {
127 color: #fff !important;
128 background-color: <?php print colorDarker($badgeSecondary, 10); ?>;
129}
130
131/* SUCCESS */
132.badge-success {
133 color: #fff !important;
134 background-color: <?php print $badgeSuccess; ?>;
135}
136a.badge-success.focus, a.badge-success:focus {
137 outline: 0;
138 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeSuccess, 0.5); ?>;
139}
140a.badge-success:focus, a.badge-success:hover {
141 color: #fff !important;
142 background-color: <?php print colorDarker($badgeSuccess, 10); ?>;
143}
144
145/* DANGER */
146.badge-danger {
147 color: #fff !important;
148 background-color: <?php print $badgeDanger; ?>;
149}
150a.badge-danger.focus, a.badge-danger:focus {
151 outline: 0;
152 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDanger, 0.5); ?>;
153}
154a.badge-danger:focus, a.badge-danger:hover {
155 color: #fff !important;
156 background-color: <?php print colorDarker($badgeDanger, 10); ?>;
157}
158
159/* WARNING */
160.badge-warning {
161 color: #fff !important;
162 background-color: <?php print $badgeWarning; ?>;
163}
164a.badge-warning.focus, a.badge-warning:focus {
165 outline: 0;
166 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeWarning, 0.5); ?>;
167}
168a.badge-warning:focus, a.badge-warning:hover {
169 color: #212529 !important;
170 background-color: <?php print colorDarker($badgeWarning, 10); ?>;
171}
172
173/* WARNING colorblind */
174body[class*="colorblind-"] .badge-warning {
175 background-color: <?php print $colorblind_deuteranopes_badgeWarning; ?>;
176 }
177body[class*="colorblind-"] a.badge-warning.focus,body[class^="colorblind-"] a.badge-warning:focus {
178 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($colorblind_deuteranopes_badgeWarning, 0.5); ?>;
179}
180body[class*="colorblind-"] a.badge-warning:focus, a.badge-warning:hover {
181 background-color: <?php print colorDarker($colorblind_deuteranopes_badgeWarning, 10); ?>;
182}
183
184/* INFO */
185.badge-info {
186 color: #fff !important;
187 background-color: <?php print $badgeInfo; ?>;
188}
189a.badge-info.focus, a.badge-info:focus {
190 outline: 0;
191 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeInfo, 0.5); ?>;
192}
193a.badge-info:focus, a.badge-info:hover {
194 color: #fff !important;
195 background-color: <?php print colorDarker($badgeInfo, 10); ?>;
196}
197
198/* LIGHT */
199.badge-light {
200 color: #212529 !important;
201 background-color: <?php print $badgeLight; ?>;
202}
203a.badge-light.focus, a.badge-light:focus {
204 outline: 0;
205 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeLight, 0.5); ?>;
206}
207a.badge-light:focus, a.badge-light:hover {
208 color: #212529 !important;
209 background-color: <?php print colorDarker($badgeLight, 10); ?>;
210}
211
212/* DARK */
213.badge-dark {
214 color: #fff !important;
215 background-color: <?php print $badgeDark; ?>;
216}
217a.badge-dark.focus, a.badge-dark:focus {
218 outline: 0;
219 box-shadow: 0 0 0 0.2rem <?php print colorHexToRgb($badgeDark, 0.5); ?>;
220}
221a.badge-dark:focus, a.badge-dark:hover {
222 color: #fff !important;
223 background-color: <?php print colorDarker($badgeDark, 10); ?>;
224}
225
226
227@media only screen and (max-width: 570px)
228{
229 span.badge.badge-status {
230 overflow: hidden;
231 max-width: 130px;
232 text-overflow: ellipsis;
233 }
234}
235
236
237/* STATUS BADGES */
238<?php
239for ($i = 0; $i <= 10; $i++) {
240 /* Default Status */
241 _createStatusBadgeCss((string) $i, '', "STATUS".$i);
242
243 // create status for accessibility
244 _createStatusBadgeCss((string) $i, 'colorblind_deuteranopes_', "COLORBLIND STATUS".$i, 'body[class*="colorblind-"] ');
245}
246
247_createStatusBadgeCss('1b', '', "STATUS1b");
248_createStatusBadgeCss('4b', '', "STATUS4b");
249
261function _createStatusBadgeCss($statusName, $statusVarNamePrefix = '', $commentLabel = '', $cssPrefix = '')
262{
263 global ${$statusVarNamePrefix.'badgeStatus'.$statusName}, ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
264
265 if (!empty(${$statusVarNamePrefix.'badgeStatus'.$statusName})) {
266 print "\n/* ".strtoupper($commentLabel)." - ".$statusName." */\n";
267
268 $thisBadgeBackgroundColor = $thisBadgeBorderColor = ${$statusVarNamePrefix.'badgeStatus'.$statusName};
269
270
271 $TBadgeBorderOnly = array('0', '1b', '3', '4b', '5', '7', '10');
272 $thisBadgeTextColor = colorIsLight(${$statusVarNamePrefix.'badgeStatus'.$statusName}) ? '#212529' : '#ffffff';
273
274 if (!empty(${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName})) {
275 $thisBadgeTextColor = ${$statusVarNamePrefix.'badgeStatus_textColor'.$statusName};
276 }
277
278 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
279 $thisBadgeTextColor = '#9c850b';
280 $thisBadgeBackgroundColor = "#fff";
281 }
282
283 if (in_array((string) $statusName, array('4b'))) {
284 $thisBadgeTextColor = '#25a580';
285 }
286 if (in_array((string) $statusName, array('7'))) {
287 $thisBadgeTextColor = '#277d1e';
288 }
289 if (in_array((string) $statusName, array('0', '5', '9', '10'))) {
290 $thisBadgeTextColor = '#999999';
291 }
292 if (in_array((string) $statusName, array('6'))) {
293 $thisBadgeTextColor = '#777777';
294 }
295
296 // badge-statusX
297 print $cssPrefix.".badge-status".$statusName." {\n";
298 print " color: ".$thisBadgeTextColor." !important;\n";
299 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
300 print " border-color: ".$thisBadgeBorderColor." !important;\n";
301 }
302 if ($thisBadgeBackgroundColor != '') {
303 print " background-color: ".$thisBadgeBackgroundColor." !important;\n";
304 }
305 print "}\n";
306
307 print $cssPrefix.".font-status".$statusName." {\n";
308 if ($thisBadgeBackgroundColor != '') {
309 print " color: ".$thisBadgeBackgroundColor." !important;\n";
310 }
311 print "}\n";
312
313 // badge-statusX:focus
314
315 print $cssPrefix.".badge-status".$statusName.".focus, ".$cssPrefix.".badge-status".$statusName.":focus {\n";
316 print " outline: 0;\n";
317 print " box-shadow: 0 0 0 0.2rem ".colorHexToRgb($thisBadgeBackgroundColor, 0.5)." !important;\n";
318 print "}\n";
319
320 print $cssPrefix.".badge-status".$statusName.":focus, ".$cssPrefix.".badge-status".$statusName.":hover {\n";
321 print " color: ".$thisBadgeTextColor." !important;\n";
322 if (in_array((string) $statusName, $TBadgeBorderOnly)) {
323 print " border-color: ".colorDarker($thisBadgeBorderColor, 10)." !important;\n";
324 }
325 print "}\n";
326 }
327}
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.