Currently, counter does not updated, when user press Up/Down vote (thumbs widget checked). I add this functionality to module. Also, new functionality work when you have several widgets on page (for example, inside view). Also, throbber image URL fixed.

Comments

Andrew Answer created an issue. See original summary.

andrew answer’s picture

Issue summary: View changes

marvil07 credited marvil07.

marvil07’s picture

Status: Needs review » Fixed
Issue tags: -Ajax

Thanks for the patch! I cannot test right now, but it looks OK, so I have just added it for now to 8.x-1.x.

andrew answer’s picture

Please check widgets other than "thumbs", I don't check it.

andrew answer’s picture

StatusFileSize
new4.17 KB

@marvil07, I update a patch with check - when user never vote before, no 'uservote' array exist.

andrew answer’s picture

Status: Fixed » Needs review
andrew answer’s picture

StatusFileSize
new3.77 KB

Paths fixed.

The last submitted patch, 7: vote_up_down.4.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 9: vote_up_down.4.patch, failed testing. View results

  • marvil07 committed 162cc60 on 8.x-1.x
    Revert "Issue #2912243 by Andrew Answer: Add AJAX to counter"
    
    This...
marvil07’s picture

First, thanks for the new patches!

Indeed, there was a problem as reported on #2921126: Vote is not working anymore since the latest release.
I decided to revert the original commit for now.

I still need to try the latest patch, but from reviewing it, I would suggest to:

+++ b/js/VoteUpDown.js
@@ -13,7 +13,8 @@
         var operation;
 
         if($(this).is('.inactive'))
-          baseWidget.append('<img class="throbber" src="' + drupalSettings.path.baseUrl + '/' + settings.basePath + '/img/status-active.gif">');
+          baseWidget.append('<img class="throbber" src="' + location.protocol + '//' + location.host + '/' +
+              (drupalSettings.path.baseUrl == '/' ? '' : drupalSettings.path.baseUrl + '/') + settings.basePath + '/img/status-active.gif">');
 
         if($(this).is('a.up.inactive'))
           operation = 'up';

Avoid making an absolute URL for the throbber, make it a relative path instead.

-        voteUpDownService.vote(baseWidget, routeUrl, operation, settings.basePath, settings.points, settings.uservote);
+        var data = routeUrl.split('?');
+        var url_data = data[0].split('/');
+        var entity_type = url_data[2];
+        var entity_id = url_data[3];
+        var points = settings.points[entity_type][entity_id];
+        var uservote = settings.uservote ? (settings.uservote[entity_type][entity_id] ? settings.uservote[entity_type][entity_id] : 0) : 0;
+        voteUpDownService.vote(baseWidget, routeUrl, operation, settings.basePath, points, uservote);

The entity* variables should be already defined, so it should not be extracted from routeUrl.

I may be wrong, but this may a be a bug on the php side not passing the right variables when the entity is not yet created, and should be fixed there to get the values form the field settings if the entity is not yet created.

jeffdavidgordon’s picture

StatusFileSize
new3.91 KB

Just re-rolling #9 so that it works with alpha4 and latest dev code

marvil07’s picture

@jeffdavidgordon: Is this still relevant after #2906057: Use drupal core ajax api?

jeffdavidgordon’s picture

Sorry for taking so long to get back to you, I can confirm that this patch is no longer needed for what's in the latest commit in 8.x-1.x branch.

marvil07’s picture

Status: Needs work » Closed (outdated)

@jeffdavidgordon: thanks for the confirmation!