Fivestar uses a very custom AJAX setup. D7 has an AJAX framework in core that would serve the AJAX needs of fivestar better.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ericduran’s picture

Yep, this should help remove all the custom token/ajax stuff thats happening.

I completely agree with this.

ericduran’s picture

Priority: Normal » Major

Changing priority to emphasize on the importance :)

james.elliott’s picture

Here's a first pass at this. The biggest changes are the gutting of fivestar.js to allow it to use the AJAX framework and the alterations to how fivestar elements are expanded versus being altered by the custom_fivestar_widget form builder.

The changes to fivestar_expand are necessary so that when the AJAX form handler can update the display of the entire widget and not just the stars.

David_Rothstein’s picture

FileSize
2.47 KB

The above patch has some issues when the fivestar widget is being used on the node edit form. The star rating isn't saved correctly, and when you go back and edit the node you also don't see the correct default value initially.

The attached patch (to be applied on top of the one in #3) is a start at fixing that. I did not combine it with the above patch because it still doesn't work correctly yet; however, testing this in the Drupal Gardens development codebase (where we have some other patches in the Fivestar queue applied) it does solve the problem. So I think it's on the right track.

The patch also adds event.preventDefault() to the end of the Drupal.behaviors.fivestar.rate() function, because without that I was getting occasional page reloads when using the widget.

*****

One more note, not included in the attached patch, but I also experimented with adding these lines of code to Drupal.behaviors.fivestar.rate(), in place of the Drupal.behaviors.fivestar.updateDisplay() call that is there now:

    var $this_star = $this.closest('.star');
    $this_star.prevAll('.star').andSelf().addClass('on');
    $this_star.nextAll('.star').removeClass('on');

I did that because I was apparently working off a different version of the patch than the one posted here, which did not have the Drupal.behaviors.fivestar.updateDisplay() function in it, so I basically reinvented the wheel before noticing :( Not sure how that happened, but in any case, both do the same thing (make sure that after you click on the rating widget while on the node edit form, the correct number of stars are highlighted), so I thought I'd at least share that snippet as an alternative; it's what we'll be running in Drupal Gardens at least for the time being.

ericduran’s picture

Patch no longer applies cleanly, trying to re-roll now. Not the simplest one :(

ericduran’s picture

FileSize
48.29 KB

Here's an updated patch with both preview patch rolled into one. This still doesn't work, as expected.

When voting the values are correct but the stars don't have the appropriate classes, seems like a behavior might need to be re-attached, I haven't check yet.

ericduran’s picture

Priority: Major » Critical

This is probably that last missing critical issue in the d7 version.

Still have a couple of major issues, but this is probably the most important one, before we start cleaning everything up, and removing what I'm sure is a lot of cruft not being used now.

ksenzee’s picture

I'm working on rerolling this on top of the changes in #547050: Widget per axis. I think it's basically working. I'm not sure if it makes sense to upload a patch until that one lands, but if anyone wants it I can.

One bug I still see is that the voting widget's default value isn't being rounded, so it doesn't correctly display vote averages (unless the average happens to be a multiple of 20%). So if you have it set to display the average vote on initial page load, you see no stars instead. Eric, is that the same problem you saw in #6? Or was that something else?

ksenzee’s picture

Status: Active » Needs review
FileSize
52.74 KB

Here's a new version of this patch, meant to be applied on top of #547050-18: Widget per axis. I'll write some tests for it tomorrow. It fixes the bug I noted in #8. Re #6, as far as I can tell the classes are the same before and after voting, but if there's a bug there I'll look into it.

ericduran’s picture

@ksenzee any update on the bug you mention?

ksenzee’s picture

The patch in #9 fixes all the bugs I knew about. I was just asking for more info on #6. I wasn't sure whether what you were reporting in #6 is still a problem in the latest patch, but I was offering to fix it if so.

ericduran’s picture

Status: Needs review » Fixed

@ksenzee ok, Well this looks good to me too. This is now fixed -- http://drupalcode.org/project/fivestar.git/commit/a02c823

ksenzee’s picture

Awesome, thanks!

deeve’s picture

@ericduran: is this fix included within your latest release 7.x-2.x-dev or do I still need to apply this to that?
Thanks.

ericduran’s picture

@deeve, This is fixed. You just need to use the latest version of fivestar-dev.

deeve’s picture

Thanks.

ericduran’s picture

@deeve, No Problem.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.