Skip to content

Commit 0e443bd

Browse files
committed
Debug star extrafields (set initial highlight in php instead of js)
1 parent 90ac6c0 commit 0e443bd

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

htdocs/core/class/extrafields.class.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,7 @@ public function showOutputField($key, $value, $moreparam = '', $extrafieldsobjec
24192419
$value = dol_trunc(preg_replace('/./i', '*', $value), 8, 'right', 'UTF-8', 1);
24202420
} elseif ($type == 'stars') {
24212421
$objectid = (int) $object->id;
2422+
$nbstars = (int) $value;
24222423
if ($showValueInsteadOfInputField == 1) {
24232424
$value = '<span style="display:none;" id="'.$key.$object->id.'">'.dol_escape_htmltag($value).'</span>';
24242425
} else {
@@ -2428,31 +2429,32 @@ public function showOutputField($key, $value, $moreparam = '', $extrafieldsobjec
24282429
$value .= '<div class="star-selection" id="'.$key.$objectid.'_selection">';
24292430
$i = 1;
24302431
while ($i <= $size) {
2431-
$value .= '<span class="star" data-value="'.$i.'">'.img_picto('', 'fontawesome_star_fas').'</span>';
2432+
$value .= '<span class="star'.($i <= $nbstars ? ' active' : '').'" data-value="'.$i.'">'.img_picto('', 'fontawesome_star_fas').'</span>';
24322433
$i++;
24332434
}
24342435
$value .= '</div>';
24352436
$value .= '<script>
24362437
$(document).ready(function() {
24372438
let container = $("#'.$key.$objectid.'_selection");
24382439
let selectedStars = parseInt($("#'.$key.$objectid.'").val() || $("#'.$key.$objectid.'").text()) || 0;
2439-
container.find(".star").each(function() {
2440-
$(this).toggleClass("active", $(this).data("value") <= selectedStars);
2441-
});';
2440+
';
24422441
if ($showValueInsteadOfInputField == 0) {
24432442
$value .= '
24442443
container.find(".star").on("mouseover", function() {
2444+
console.log("Mouse over a star");
24452445
let selectedStar = $(this).data("value");
24462446
container.find(".star").each(function() {
24472447
$(this).toggleClass("active", $(this).data("value") <= selectedStar);
24482448
});
24492449
});
24502450
container.on("mouseout", function() {
2451+
console.log("Mouse out of star");
24512452
container.find(".star").each(function() {
24522453
$(this).toggleClass("active", $(this).data("value") <= selectedStars);
24532454
});
24542455
});
24552456
container.find(".star").off("click").on("click", function() {
2457+
console.log("We click on star, we call the ajax core/ajax/updateextrafield.php");
24562458
selectedStars = $(this).data("value");
24572459
if (selectedStars == 1 && $("#'.$key.$objectid.'").val() == 1) {
24582460
selectedStars = 0;
@@ -2469,7 +2471,7 @@ public function showOutputField($key, $value, $moreparam = '', $extrafieldsobjec
24692471
objectId: '.((int) $objectid).',
24702472
field: \''.dol_escape_js($key).'\',
24712473
value: selectedStars,
2472-
token: "'.newToken().'"
2474+
token: \''.newToken().'\'
24732475
},
24742476
success: function(response) {
24752477
var res = JSON.parse(response);

htdocs/theme/eldy/global.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5387,7 +5387,7 @@
53875387
.star-selection {
53885388
font-size: 1rem;
53895389
cursor: pointer;
5390-
display: flex;
5390+
display: inline-block;
53915391
}
53925392
.star {
53935393
color: #ccc;

htdocs/theme/md/style.css.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5372,7 +5372,7 @@
53725372
.star-selection {
53735373
font-size: 1rem;
53745374
cursor: pointer;
5375-
display: flex;
5375+
display: inline-block;
53765376
}
53775377
.star {
53785378
color: #ccc;

0 commit comments

Comments
 (0)