Author: erinnp
Date: Fri Jun 28 15:19:55 2013
New Revision: 1497810

URL: http://svn.apache.org/r1497810
Log:
dropped handler api from rave_api, dropped last jquery dependency, moved 
functions to rave_store and rave_person_profile

Modified:
    
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/core/rave_api.js
    
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_person_profile.js
    
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_store.js

Modified: 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/core/rave_api.js
URL: 
http://svn.apache.org/viewvc/rave/branches/require/rave-portal-resources/src/main/webapp/static/script/core/rave_api.js?rev=1497810&r1=1497809&r2=1497810&view=diff
==============================================================================
--- 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/core/rave_api.js
 (original)
+++ 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/core/rave_api.js
 Fri Jun 28 15:19:55 2013
@@ -18,8 +18,8 @@
  */
 
 //TODO: jquery dependency should not be here.
-define(['underscore', 'jquery', 'core/rave_ajax', 'core/rave_state_manager', 
'core/rave_event_manager'],
-    function (_, $, ajax, stateManager, eventManager) {
+define(['underscore', 'core/rave_ajax', 'core/rave_state_manager', 
'core/rave_event_manager'],
+    function (_, ajax, stateManager, eventManager) {
         //stores virtual host context of application execution
 
         var context = '';
@@ -830,194 +830,8 @@ define(['underscore', 'jquery', 'core/ra
 
         })();
 
-        /*
-         *     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";
-                }
-            }
-
-            //TODO: git rid of dom manipulation
-            //function to toggle sliding down and up of user profile tabs
-            function userProfileTabHandler(profileTab) {
-                //parsing profile tab id to obtain panel id
-                var panelId = "#" + profileTab.id.substring(0, 
profileTab.id.indexOf("Tab")) + "Panel";
-                $(panelId).slideToggle("slow");
-            }
-
-            //function to toggle hide and show of tag pages
-            function userProfileTagHandler(profileTag, defaultTagPage) {
-
-                //first close any tag pages if open
-                $(".profile-tag-page").hide();
-
-                //show default tag page is set true
-                if (defaultTagPage != null) {
-                    $(defaultTagPage).show();
-                }
-
-                else {
-                    //extract the tag page id from profile tag id
-                    var tagPageId = "#" + profileTag.id + "Page";
-                    //show the requested tag page
-                    $(tagPageId).show();
-                }
-            }
-
-            function userProfileEditHandler(isEdit) {
-                //get the edit element
-                var profileInfo = document.getElementById("profileInfo");
-                //extract hidden fields through their class
-                var hiddenFields = "." + profileInfo.value + "-hidden";
-                //extract labels through their class
-                var visibleFields = "." + profileInfo.value + "-visible";
-
-                if (isEdit) {
-                    //make hidden fields visible
-                    $(hiddenFields).show();
-                    //make visible fields invisible
-                    $(visibleFields).hide();
-                }
-
-                else {
-                    //make hidden fields invisible
-                    $(hiddenFields).hide();
-                    //make visible fields visible
-                    $(visibleFields).show();
-                }
-            }
-
-            return {
-                widgetRatingHandler: widgetRatingHandler,
-                userProfileTabHandler: userProfileTabHandler,
-                userProfileTagHandler: userProfileTagHandler,
-                userProfileEditHandler: userProfileEditHandler
-            };
-
-        })();
-
-
         return {
             rest: restApi,
             rpc: rpcApi,
-            handler: handlerApi
         };
     })
\ No newline at end of file

Modified: 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_person_profile.js
URL: 
http://svn.apache.org/viewvc/rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_person_profile.js?rev=1497810&r1=1497809&r2=1497810&view=diff
==============================================================================
--- 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_person_profile.js
 (original)
+++ 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_person_profile.js
 Fri Jun 28 15:19:55 2013
@@ -88,6 +88,29 @@ define(["jquery", "portal/rave_portal", 
         return i18nStr;
     }
 
+    function userProfileEditHandler(isEdit) {
+        //get the edit element
+        var profileInfo = document.getElementById("profileInfo");
+        //extract hidden fields through their class
+        var hiddenFields = "." + profileInfo.value + "-hidden";
+        //extract labels through their class
+        var visibleFields = "." + profileInfo.value + "-visible";
+
+        if (isEdit) {
+            //make hidden fields visible
+            $(hiddenFields).show();
+            //make visible fields invisible
+            $(visibleFields).hide();
+        }
+
+        else {
+            //make hidden fields invisible
+            $(hiddenFields).hide();
+            //make visible fields visible
+            $(visibleFields).show();
+        }
+    }
+
     function dealWithUserResults(userResults){
         var currentUser = $("#addRemoveFriend").get(0).value;
         var searchTerm = $('#searchTerm').get(0).value;
@@ -399,7 +422,7 @@ define(["jquery", "portal/rave_portal", 
         var $editButton = $("#profileEdit");
         if ($editButton) {
             $editButton.click(function() {
-                rave.api.handler.userProfileEditHandler(true);
+                userProfileEditHandler(true);
             });
         }
         //user clicks add/remove friend button in the profile page
@@ -443,7 +466,7 @@ define(["jquery", "portal/rave_portal", 
         var $cancelButton = $("#cancelEdit");
         if ($cancelButton) {
             $cancelButton.click(function() {
-                rave.api.handler.userProfileEditHandler(false);
+                userProfileEditHandler(false);
             });
         }
 

Modified: 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_store.js
URL: 
http://svn.apache.org/viewvc/rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_store.js?rev=1497810&r1=1497809&r2=1497810&view=diff
==============================================================================
--- 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_store.js
 (original)
+++ 
rave/branches/require/rave-portal-resources/src/main/webapp/static/script/portal/rave_store.js
 Fri Jun 28 15:19:55 2013
@@ -57,7 +57,7 @@ define(["jquery", "rave", "portal/rave_p
                 };
 
                 //update the widget ratings on web page
-                rave.api.handler.widgetRatingHandler(widgetRating);
+                widgetRatingHandler(widgetRating);
 
                 $(this).addClass('btn-success');
                 $(this).siblings('.btn').removeClass('btn-danger');
@@ -82,7 +82,7 @@ define(["jquery", "rave", "portal/rave_p
                 };
 
                 //update the widget ratings on web page
-                rave.api.handler.widgetRatingHandler(widgetRating);
+                widgetRatingHandler(widgetRating);
 
                 $(this).addClass('btn-danger');
                 $(this).siblings('.btn').removeClass('btn-success');
@@ -229,6 +229,127 @@ define(["jquery", "rave", "portal/rave_p
         }
     }
 
+    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 incrementingTotalLabel;
+        var decrementingTotal = -1;
+        var decrementingTotalLabel;
+        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";
+        }
+    }
+
     function init(referringPageId){
         initRatings();
         initComments();


Reply via email to