I think I fixed the bug.

Attaching new patch here.

Made the following changes in rave_store.js:-
-> Changed the "change" function to "click" function
-> Added one if condition to each click function.

Regards,
Ankur Goyal

On Mon, Dec 5, 2011 at 1:30 PM, Cooper, Sean D. <[email protected]> wrote:

> Try abandoning the pre-wiring of the events.  Instead of marking the radio
> buttons as checked/unchecked see if using the jquery event model to
> check/uncheck the buttons resolves the problem.
>
> -Sean
>
> From: Ankur Goyal [mailto:[email protected]]
> Sent: Thursday, December 01, 2011 10:32 AM
> To: rave
> Subject: Fwd: Review Request: Rave-359 (WidgetRating UI: Initial load of
> page allows a double click for rating)
>
> Sending to the entire list.
> ---------- Forwarded message ----------
> From: Ankur Goyal <[email protected]<mailto:[email protected]>>
> Date: Wed, Nov 30, 2011 at 4:22 PM
> Subject: Re: Review Request: Rave-359 (WidgetRating UI: Initial load of
> page allows a double click for rating)
> To: "Cooper, Sean D." <[email protected]<mailto:[email protected]>>
> Cc: Marlon Pierce <[email protected]<mailto:[email protected]>>
>
>
> Hi Sean,
>
> I did some modifications which solved the problem you mentioned in your
> first email but there is a small problem and I am not able to understand it.
>
> When both like and dislike ratings are 0 and then if you click anyone of
> them (say like button) it updates properly but when you click on the other
> (dislike button), it shows no effect no matter how many times you click on
> it. But if you click once more on the first one which got updated (i.e.
> like button), it wont update and remain as 1 (as needed) and then try to
> click on the other (dislike button), the other one then updates to 1 with
> the first one updates to 0.
>
> The problem that i noticed was that change function in rave_store.js file
> is not been called for the first hit for the other button (dislike). I am
> unable to find a way out of it.
>
> example:
> initially
> like: 0 dislike: 0
> first hit on like button
> like: 1 dislike: 0
> second hit on dislike button
> like: 1 dislike: 0 (no change no matter how much you click on dislike
> button)
> click on like button again
> no change
> now click on dislike button
> like: 0 dislike: 1 (as expected)
> here after it works fine.
>
> I have attached my patch file with this. It will have some alert messages
> just to know the flow.
>
> Waiting for your reply,
>
> Regards,
> Ankur Goyal
>
> On Tue, Nov 29, 2011 at 4:25 PM, Cooper, Sean D. <[email protected]
> <mailto:[email protected]>> wrote:
> You might try creating a third radio button for the 'unset' state and have
> it be a hidden element on the page.  That way you can correctly set the
> state of the radio button to 'positive', 'negative' , and 'unset'
>
> -Sean
>
> >-----Original Message-----
> >From: Ankur Goyal [mailto:[email protected]<mailto:
> [email protected]>]
> >Sent: Tuesday, November 29, 2011 4:18 PM
> >To: Sean Cooper
> >Cc: Marlon Pierce; Ankur Goyal; rave
> >Subject: Re: Review Request: Rave-359 (WidgetRating UI: Initial load of
> page
> >allows a double click for rating)
> >
> >Hi Sean,
> >
> >I was looking into the problem you mentioned.
> >
> >There is some property called as "aria-pressed" which is always set as
> >"true" for like button and "false" for dislike button after every load of
> >widget store page.
> >
> >I am unable to find where this effect is brought from so thought to ask
> you
> >about this. :)
> >
> >Waiting for your reply,
> >
> >Regards,
> >Ankur Goyal
> >
> >On Mon, Nov 28, 2011 at 2:14 PM, Sean Cooper <[email protected]<mailto:
> [email protected]>>
> >wrote:
> >
> >>    This is an automatically generated e-mail. To reply, visit:
> >> https://reviews.apache.org/r/2917/
> >>
> >> This patch is forcing the button state to highlight the 'negative'
> option when
> >using chrome or firefox regardless of whether or not the user has already
> >selected one of the options (e.g. If the user has selected the 'positive'
> option
> >the 'negative' option is showing up as being selected)
> >>
> >>
> >> - Sean
> >>
> >> On November 22nd, 2011, 10:05 p.m., Ankur Goyal wrote:
> >>   Review request for rave and Marlon Pierce.
> >> By Ankur Goyal.
> >>
> >> *Updated 2011-11-22 22:05:24*
> >> Description
> >>
> >> WidgetRating UI: Initial load of page allows a double click for rating
> >> Files modified:
> >> rave_store.js
> >> store.jsp
> >>
> >>   Diffs
> >>
> >>    - trunk/rave-portal-resources/src/main/webapp/WEB-
> >INF/jsp/views/store.jsp
> >>    (1205187)
> >>    - trunk/rave-portal-resources/src/main/webapp/script/rave_store.js
> >>    (1205187)
> >>
> >> View Diff <https://reviews.apache.org/r/2917/diff/>
> >>
>
>
>
Index: rave-portal-resources/src/main/webapp/script/rave_store.js
===================================================================
--- rave-portal-resources/src/main/webapp/script/rave_store.js	(revision 1210544)
+++ rave-portal-resources/src/main/webapp/script/rave_store.js	(working copy)
@@ -24,49 +24,63 @@
 
         $(".widgetLikeButton").button( {
             icons: {primary: "ui-icon-plus"}
-        }).change(function() {
-            var widgetId = this.id.substring("like-".length);
-            rave.api.rest.updateWidgetRating({widgetId: widgetId, score: 10});
-            $(this).button("option", "label", parseInt($(this).button("option", "label")) + 1);
-
-            //if the other button in this pair was checked then ajdust its total, except in IE where
-            //the button has already toggled BEFORE the 'change' event in which case we have to assume
-            //that the user had a contrary selection prior to the change event
-            var dislikeButton = $("#dislike-"+widgetId);
-            if (dislikeButton.get(0).getAttribute("checked") == "true" || this.checked == true) {
-                dislikeButton.get(0).setAttribute("checked", "false");
-                var dislikes = parseInt(dislikeButton.button("option", "label")) - 1;
-                if (dislikes > -1) {
-                    $(dislikeButton).button("option", "label", dislikes);
-                }
-            }
+        }).click(function() {
+        	var widgetId = this.id.substring("like-".length);
+            
+            //check if like radio button is not checked already
+            if(this.getAttribute("checked") != "true") {
+            	rave.api.rest.updateWidgetRating({widgetId: widgetId, score: 10});
             
-            //flag this element as the currently checked one
-            this.setAttribute("checked", "true");
+            	$(this).button("option", "label", parseInt($(this).button("option", "label")) + 1);
+        	
 
+            	//if the other button in this pair was checked then ajdust its total, except in IE where
+            	//the button has already toggled BEFORE the 'change' event in which case we have to assume
+            	//that the user had a contrary selection prior to the change event
+            	var dislikeButton = $("#dislike-"+widgetId);
+            	if (dislikeButton.get(0).getAttribute("checked") == "true" || this.checked == true) {
+            		dislikeButton.get(0).setAttribute("checked", "false");
+            		var dislikes = parseInt(dislikeButton.button("option", "label")) - 1;
+            		if (dislikes > -1) {
+            			$(dislikeButton).button("option", "label", dislikes);
+            			
+            		}
+            		
+            	}
+            
+            	//flag this element as the currently checked one
+            	this.setAttribute("checked", "true");
+            	
+            }
         });
 
         $(".widgetDislikeButton").button( {
             icons: {primary: "ui-icon-minus"}
-        }).change(function() {
-            var widgetId = this.id.substring("dislike-".length);
-            rave.api.rest.updateWidgetRating({widgetId: widgetId, score: 0});
-            $(this).button("option", "label", parseInt($(this).button("option", "label")) + 1);
-
-            //if the other button in this pair was checked then ajdust its total, except in IE where
-            //the button has already toggled BEFORE the 'change' event in which case we have to assume
-            //that the user had a contrary selection prior to the change event
-            var likeButton = $("#like-"+widgetId);
-            if (likeButton.get(0).getAttribute("checked") == "true" || this.checked == true) {
-                likeButton.get(0).setAttribute("checked", "false");
-                var likes = parseInt(likeButton.button("option", "label")) - 1;
-                if (likes > -1) {
-                    $("#like-"+widgetId).button("option", "label", likes);
-                }
-            }
+        }).click(function() {
+        	var widgetId = this.id.substring("dislike-".length);
+            //check if dislike radio button is not checked already
+            
+            if(this.getAttribute("checked") != "true") {
+            	
+            	rave.api.rest.updateWidgetRating({widgetId: widgetId, score: 0});
             
-            //flag this element as the currently checked item
-            this.setAttribute("checked", "true");
+            	$(this).button("option", "label", parseInt($(this).button("option", "label")) + 1);
+            	
+            	//if the other button in this pair was checked then ajdust its total, except in IE where
+            	//the button has already toggled BEFORE the 'change' event in which case we have to assume
+            	//that the user had a contrary selection prior to the change event
+            	var likeButton = $("#like-"+widgetId);
+            	if (likeButton.get(0).getAttribute("checked") == "true" || this.checked == true) {
+            		likeButton.get(0).setAttribute("checked", "false");
+            		var likes = parseInt(likeButton.button("option", "label")) - 1;
+            		if (likes > -1) {
+            			$("#like-"+widgetId).button("option", "label", likes);
+            		}
+            	}
+            
+            	//flag this element as the currently checked item
+            	this.setAttribute("checked", "true");
+            }
         });
     }
     

Reply via email to