rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpie...@apache.org
Subject svn commit: r1229611 - in /incubator/rave/trunk/rave-portal-resources/src/main: resources/messages.properties resources/messages_nl.properties webapp/WEB-INF/jsp/views/store.jsp webapp/script/rave_api.js webapp/script/rave_store.js
Date Tue, 10 Jan 2012 15:59:22 GMT
Author: mpierce
Date: Tue Jan 10 15:59:21 2012
New Revision: 1229611

URL: http://svn.apache.org/viewvc?rev=1229611&view=rev
Log:
(RAVE-393) Committing patch contributed by Ankur Goyal to fix +1/-1 bug.

Modified:
    incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties
    incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/store.jsp
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js
    incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_store.js

Modified: incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties?rev=1229611&r1=1229610&r2=1229611&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/resources/messages.properties Tue
Jan 10 15:59:21 2012
@@ -123,6 +123,8 @@ page.widget.rate.dislike=Dislike
 page.widget.comments=Comments
 page.widget.comment.edit=Edit Comment
 page.widget.usercount=users
+page.widget.rate.likes=Likes: 
+page.widget.rate.dislikes=Dislikes: 
 
 page.addwidget.title=Add new widget
 page.addwidget.form.header=Widget

Modified: incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties?rev=1229611&r1=1229610&r2=1229611&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties Tue
Jan 10 15:59:21 2012
@@ -132,6 +132,8 @@ page.widget.rate.dislike=Niet leuk
 page.widget.comments=Opmerkingen
 page.widget.comment.edit=Bewerk opmerking
 page.widget.usercount=gebruikers
+page.widget.rate.likes=Leuk: 
+page.widget.rate.dislikes=Niet leuk: 
 
 page.addwidget.title=Voeg nieuwe widget toe
 page.addwidget.form.header=Widget

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/store.jsp
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/store.jsp?rev=1229611&r1=1229610&r2=1229611&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/store.jsp
(original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/store.jsp
Tue Jan 10 15:59:21 2012
@@ -188,24 +188,45 @@
                             </c:if>
                             <div class="widgetRating">
                                 <fmt:message key="page.widget.rate"/>
-                                <c:set var="totalLikes" value="${widgetStatistics.totalLike}"/>
-                                <c:set var="totalDislikes" value="${widgetStatistics.totalDislike}"/>
-
+                                
                                 <div id="rating-${widget.entityId}" class="ratingButtons">
+                                    <form>
+				    					<input type="hidden" id="rate-${widget.entityId}" 
+							 				   value="${widgetsStatistics[widget.entityId]!=null?widgetsStatistics[widget.entityId].userRating:"-1"}">
+				    				</form>
                                     <input type="radio" id="like-${widget.entityId}" class="widgetLikeButton"
-                                           name="rating-${widget.entityId}"${widgetStatistics.userRating==10?"
checked='true'":""}>
-                                    <label for="like-${widget.entityId}">${widgetStatistics!=null?widgetStatistics.totalLike:"0"}</label>
+                                            name="rating-${widget.entityId}"${widgetsStatistics[widget.entityId].userRating==10?"
checked='true'":""}>
+                                    <label for="like-${widget.entityId}"></label>
                                     <input type="radio" id="dislike-${widget.entityId}"
class="widgetDislikeButton"
-                                           name="rating-${widget.entityId}"${widgetStatistics.userRating==0?"
checked='true'":""}>
-                                    <label for="dislike-${widget.entityId}">${widgetStatistics!=null?widgetStatistics.totalDislike:"0"}</label>
+                                            name="rating-${widget.entityId}"${widgetsStatistics[widget.entityId].userRating==0?"
checked='true'":""}>
+                                    <label for="dislike-${widget.entityId}"> </label>
+                                    
+                                    <!-- Displaying the likes and dislikes rating along
with total votes -->
+                                    
                                 </div>
                             </div>
-                            <div class="widgetUserCount">
-                                <c:set var="widgetUserCountGreaterThanZero" value="${widgetStatistics
!= null && widgetStatistics.totalUserCount > 0}" />
-                                <c:if test="${widgetUserCountGreaterThanZero}"><a
href="javascript:void(0);" onclick="rave.displayUsersOfWidget(${widget.entityId});"></c:if>
-                                    <fmt:formatNumber groupingUsed="true" value="${widgetStatistics!=null?widgetStatistics.totalUserCount:0}"
/>&nbsp;<fmt:message key="page.widget.usercount"/>
-                                <c:if test="${widgetUserCountGreaterThanZero}"></a></c:if>
-                            </div>
+                            <ul class="horizontal-list">
+                            	<!-- display total likes -->
+                                <li>
+                                  	<c:set var="widgetLikes">
+                                   		${widgetsStatistics[widget.entityId]!=null?widgetsStatistics[widget.entityId].totalLike:"0"}
+                                   	</c:set>
+                                   	<fmt:message key="page.widget.rate.likes"/><label
id="totalLikes-${widget.entityId}" data-rave-widget-likes="${widgetLikes}">${widgetLikes}</label>
+                                </li>
+                                <!-- display total dislikes  -->
+                                <li>
+                                  	<c:set var="widgetDislikes">
+                                   		${widgetsStatistics[widget.entityId]!=null?widgetsStatistics[widget.entityId].totalDislike:"0"}
+                                   	</c:set>
+                                   	<fmt:message key="page.widget.rate.dislikes"/><label
id="totalDislikes-${widget.entityId}" data-rave-widget-dislikes="${widgetDislikes}">${widgetDislikes}</label>
+                            	</li>
+                            	<li class="widgetUserCount">
+                                	<c:set var="widgetUserCountGreaterThanZero" value="${widgetStatistics
!= null && widgetStatistics.totalUserCount > 0}" />
+                                	<c:if test="${widgetUserCountGreaterThanZero}"><a
href="javascript:void(0);" onclick="rave.displayUsersOfWidget(${widget.entityId});"></c:if>
+                                    	<fmt:formatNumber groupingUsed="true" value="${widgetStatistics!=null?widgetStatistics.totalUserCount:0}"
/>&nbsp;<fmt:message key="page.widget.usercount"/>
+                                	<c:if test="${widgetUserCountGreaterThanZero}"></a></c:if>
+                            	</li>
+                            </ul>
                         </div>
 
                         <div class="clear-float"></div>

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js?rev=1229611&r1=1229610&r2=1229611&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_api.js Tue Jan
10 15:59:21 2012
@@ -387,9 +387,141 @@ rave.api = rave.api || (function() {
 
     })();
 
+    /*
+     *	Handler functions to handle modifications on user events 
+     */
+    var handlerApi = (function() {
+    	
+    	//function to handle widget rating changes
+    	function widgetRatingHandler(widgetRating) {
+    		
+    		//retrieving the current total likes
+    		var likeTotalLabel = document.getElementById("totalLikes-"+ widgetRating.widgetId);
+    		var likeTotal = likeTotalLabel.getAttribute("data-rave-widget-likes"); 
+    		
+    		//retrieving the current total dislikes
+    		var dislikeTotalLabel = document.getElementById("totalDislikes-"+ widgetRating.widgetId);
+			var dislikeTotal = dislikeTotalLabel.getAttribute("data-rave-widget-dislikes"); 
+    		
+			//initializing temporary variables
+			var incrementingTotal = -1;
+			var decrementingTotal = -1;
+			var curButton = "";
+			var prevButton = "";
+			var prevRating = -1;
+			
+			//check if like rating needs to be updated
+    		if(widgetRating.isLike) {
+    			
+    			//set incrementing total to like total
+    			incrementingTotal = likeTotal;
+    			
+    			//set the incrementing total label to like total label
+    			incrementingTotalLabel = likeTotalLabel;
+    			
+    			//set decrementing total to dislike total
+    			decrementingTotal = dislikeTotal;
+    			
+    			//set the decrementing total label to dislike total label
+    			decrementingTotalLabel = dislikeTotalLabel;
+    			
+    			//set the current clicked button to like button
+    			curButton = widgetRating.widgetLikeButton;
+    			
+    			//set the previous clicked button to dislike button
+    			prevButton = widgetRating.widgetDislikeButton;
+    			
+    			//set the previous rating to 0 to check if dislike was clicked earlier 
+    			prevRating = 0;
+    		}
+    		
+    		//check if dislike rating needs to be updated
+    		else {
+    			    			
+    			//set incrementing total to dislike total
+    			incrementingTotal = dislikeTotal;
+    			
+    			//set the incrementing total label to dislike total label
+    			incrementingTotalLabel = dislikeTotalLabel;
+    			
+    			//set decrementing total to like total
+    			decrementingTotal = likeTotal;
+    			
+    			//set the decrementing total label to like total label
+    			decrementingTotalLabel = likeTotalLabel;
+    			
+    			//set the current clicked button to dislike button
+    			curButton = widgetRating.widgetDislikeButton;
+    			
+    			//set the previous clicked button to like button
+    			prevButton = widgetRating.widgetLikeButton;
+    			
+    			//set the previous rating to 10 to check if like was clicked earlier 
+    			prevRating = 10;
+    		}
+        		        		
+    		//update incrementing total
+        	incrementingTotal = parseInt(incrementingTotal) + 1;
+        	if(incrementingTotalLabel == likeTotalLabel) {
+        		incrementingTotalLabel.setAttribute("data-rave-widget-likes", incrementingTotal);
+        		incrementingTotalLabel.innerHTML = incrementingTotal;
+        	}
+        	else {
+        		incrementingTotalLabel.setAttribute("data-rave-widget-dislikes", incrementingTotal);
+        		incrementingTotalLabel.innerHTML = incrementingTotal;
+        	}
+        	
+        	//get the value of hidden user rating 
+        	var hiddenButton = document.getElementById("rate-"+ widgetRating.widgetId);
+        	var userPrevRate = hiddenButton.value;
+
+        	//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
+        	if (prevButton.get(0).getAttribute("checked") == "true" || curButton.checked ==
true) {
+        		prevButton.get(0).setAttribute("checked", "false");
+			
+        		//remove the previous rating made by the user if any by checking change in userRating
+        		if(parseInt(userPrevRate) == prevRating) {
+        			       				
+        			//update decrementing total
+        			if(parseInt(decrementingTotal) - 1 > -1) {
+        				decrementingTotal = parseInt(decrementingTotal) - 1;
+        				if(decrementingTotalLabel == likeTotalLabel) {
+        					decrementingTotalLabel.setAttribute("data-rave-widget-likes", decrementingTotal);
+        					decrementingTotalLabel.innerHTML = decrementingTotal;
+        				}
+        				else {
+        					decrementingTotalLabel.setAttribute("data-rave-widget-dislikes", decrementingTotal);
+        					decrementingTotalLabel.innerHTML = decrementingTotal;
+        				}
+        			}
+        		}
+            		
+        	}
+            
+        	//flag this element as the currently checked one
+        	curButton.setAttribute("checked", "true");
+
+        	//set the user rating of the hidden field
+        	if(widgetRating.isLike) {
+        		hiddenButton.value = "10";
+        	}
+        	else{
+        		hiddenButton.value = "0";
+        	}
+    	}
+    	
+    	return {
+    		widgetRatingHandler : widgetRatingHandler
+    	};
+    	
+    })();
+
     return {
         rest : restApi,
-        rpc : rpcApi
+        rpc : rpcApi,
+        handler : handlerApi
     };
 })();
 

Modified: incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_store.js
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_store.js?rev=1229611&r1=1229610&r2=1229611&view=diff
==============================================================================
--- incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_store.js (original)
+++ incubator/rave/trunk/rave-portal-resources/src/main/webapp/script/rave_store.js Tue Jan
10 15:59:21 2012
@@ -24,49 +24,55 @@ rave.store = rave.store || (function() {
 
         $(".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);
-                }
-            }
-            
-            //flag this element as the currently checked one
-            this.setAttribute("checked", "true");
-
+        }).click(function() {
+        	
+        	//check if like radio button is not checked already
+        	if(this.getAttribute("checked") != "true") {
+        		
+        		//retrieve widget id
+        		var widgetId = this.id.substring("like-".length);
+        		
+        		//update the widget score in database
+        		rave.api.rest.updateWidgetRating({widgetId: widgetId, score: 10});
+        		
+        		//call update widget rating handler function
+        		var widgetRating = {
+        				widgetId: widgetId, 
+					    widgetLikeButton: this, 
+					    widgetDislikeButton: $("#dislike-"+widgetId),
+						isLike: true
+        		};
+        		
+        		//update the widget ratings on web page
+        		rave.api.handler.widgetRatingHandler(widgetRating);
+            	
+        	}
         });
 
         $(".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);
-                }
-            }
-            
-            //flag this element as the currently checked item
-            this.setAttribute("checked", "true");
+        }).click(function() {
+        	
+        	//check if dislike radio button is not checked already
+        	if(this.getAttribute("checked") != "true") {
+            	
+        		//retrieve widget id
+        		var widgetId = this.id.substring("dislike-".length);
+        		
+        		//update the widget score in database
+        		rave.api.rest.updateWidgetRating({widgetId: widgetId, score: 0});
+        		
+        		//call update widget rating handler function
+        		var widgetRating = {
+        				widgetId: widgetId, 
+					    widgetLikeButton: $("#like-"+widgetId), 
+					    widgetDislikeButton: this,
+						isLike: false
+        		};
+        		
+        		//update the widget ratings on web page
+        		rave.api.handler.widgetRatingHandler(widgetRating);
+        	}
         });
     }
     



Mime
View raw message