@@ -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);
0 commit comments