Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js?rev=1455957&r1=1455956&r2=1455957&view=diff
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js
 (original)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_person_profile.js
 Wed Mar 13 14:29:38 2013
@@ -19,374 +19,382 @@
 
 var rave = rave || {};
 rave.personprofile = rave.personprofile || (function() {
-     // map of {subpage name, boolean} tracking whether or not a sub page has 
been viewed at least once
-     var subPagesViewedStatus = {};
-     function initSubPages() {
-         var $tabs = $('#personProfileSubPages a[data-toggle="tab"]');
-         //If the implementation does not use bootstrap tabs / subpages, skip 
this method
-         if($tabs.length == 0){
-             return;
-         }
-         
+    // map of {subpage name, boolean} tracking whether or not a sub page has 
been viewed at least once
+    var subPagesViewedStatus = {};
+    function initSubPages() {
+        var $tabs = $('#personProfileSubPages a[data-toggle="tab"]');
+        //If the implementation does not use bootstrap tabs / subpages, skip 
this method
+        if($tabs.length == 0){
+            return;
+        }
+
         //Make the tab identified by hash url active, defaulting to the first 
tab (Twitter Bootstrap)
-         var activeSubPage = decodeURIComponent(location.hash).slice(1);
-         activeSubPage = activeSubPageExists(activeSubPage, $tabs) ? 
activeSubPage : "";
-         if (activeSubPage===''){
-             activeSubPage = $tabs.first().text();
-             location.hash = encodeURIComponent(activeSubPage);
-         }
-
-         $tabs.on('shown', function(event, ui) {
-             //on tab click, change the url hash
-             var page = $(this).text();
-             var target = $(this).attr('href');
-             location.hash = encodeURIComponent(page);
-
-             // refresh the widgets on the sub page when selected to ensure 
proper sizing
-             if (subPagesViewedStatus[page] == false) {
-                 $(target + " .widget-wrapper").each(function(){
-                     var regionWidget = 
rave.getRegionWidgetById(rave.getObjectIdFromDomId(this.id));
-                     if(regionWidget.restore) regionWidget.restore();
-                 });
-                 // mark that this sub page has been viewed at least once and 
there is no need to refresh
-                 // the widgets in future views
-                 subPagesViewedStatus[page] = true;
-             }
-         });
-
-         // build the subPageViewedStatus map to track if a given sub page has 
been viewed yet to determine if we need
-         // to refresh the widgets upon first viewing to ensure they are sized 
properly.  Set the default active tab to
-         // true since it will be rendered and sized properly as part of the 
initial page load
-         $.each($tabs, function(i, el){
-             var $tab = $(el);
-             var page = $tab.text();
-             var isActive =  (page == activeSubPage);
-             subPagesViewedStatus[page] = false;
+        var activeSubPage = decodeURIComponent(location.hash).slice(1);
+        activeSubPage = activeSubPageExists(activeSubPage, $tabs) ? 
activeSubPage : "";
+        if (activeSubPage===''){
+            activeSubPage = $tabs.first().text();
+            location.hash = encodeURIComponent(activeSubPage);
+        }
+
+        $tabs.on('shown', function(event, ui) {
+            //on tab click, change the url hash
+            var page = $(this).text();
+            var target = $(this).attr('href');
+            location.hash = encodeURIComponent(page);
+
+            // refresh the widgets on the sub page when selected to ensure 
proper sizing
+            if (subPagesViewedStatus[page] == false) {
+                $(target + " .widget-wrapper").each(function(){
+                    var regionWidget = 
rave.getRegionWidgetById(rave.getObjectIdFromDomId(this.id));
+                    if(regionWidget.restore) regionWidget.restore();
+                });
+                // mark that this sub page has been viewed at least once and 
there is no need to refresh
+                // the widgets in future views
+                subPagesViewedStatus[page] = true;
+            }
+        });
+
+        // build the subPageViewedStatus map to track if a given sub page has 
been viewed yet to determine if we need
+        // to refresh the widgets upon first viewing to ensure they are sized 
properly.  Set the default active tab to
+        // true since it will be rendered and sized properly as part of the 
initial page load
+        $.each($tabs, function(i, el){
+            var $tab = $(el);
+            var page = $tab.text();
+            var isActive =  (page == activeSubPage);
+            subPagesViewedStatus[page] = false;
             //show the initial tab
-             if(isActive){
-                 $tab.tab('show');
-             }
-         });
-     }
-
-     function activeSubPageExists(activeSubPage, tabs){
-         var exists = false;
-         $.each(tabs, function(i, el){
-             if(el.innerHTML === activeSubPage){
-                 exists = true;
-             }
-         });
-
-         return exists;
-     }
-
-     function dealWithUserResults(userResults){
-         var currentUser = $("#addRemoveFriend").get(0).value;
-         var searchTerm = $('#searchTerm').get(0).value;
-         if(searchTerm == undefined || searchTerm == ""){
-             $('#clearSearchButton').hide();
-         }else{
-             $('#clearSearchButton').show();
-         }
-         var legend;
-         if(userResults.result.resultSet.length < 1){
-             legend = rave.getClientMessage("no.results.found");
-         }else{
-             legend = 
rave.layout.searchHandler.updateParamsInString(rave.getClientMessage("search.list.result.x.to.y"),
-                 new Array(userResults.result.offset + 1, 
userResults.result.resultSet.length
-                     + userResults.result.offset, 
userResults.result.totalResults));
-         }
-         // show the listheader
-         $('#userSearchListHeader').text(legend);
-         var $targetDiv = $('#userSearchResults');
-         $targetDiv.empty();
-         // show the paginator
-         paginate(userResults);
-         //now build the content
-         $targetDiv
-             .append(
-                 $("<table/>")
-                     .addClass("searchdialogcontent")
-                         .append(
-                             $("<tr/>")
-                                 .append(
-                                     $("<td/>")
-                                     .addClass("textcell")
-                                     .append(
-                                         $("<b/>")
-                                         
.text(rave.getClientMessage("common.username"))
-                                     )
-                                 )
-                                 .append(
-                                     $("<td/>")
-                                     .addClass("booleancell")
-                                     .append(
-                                         $("<b/>")
-                                         
.text(rave.getClientMessage("common.friend.status"))
-                                     )
-                                 )
-                             )
-                     .append(
-                         $("<tbody/>")
-                         .attr("id", "searchResultsBody")
-                     )
-             );
-
-             jQuery.each(userResults.result.resultSet, function() {
-                 $('#searchResultsBody')
-                 .append(
-                     $("<tr/>")
-                     .attr("id", "searchResultRecord")
-                     .append(
-                         $("<td/>")
-                         .text(this.username)
-                     )
-                     .append(
-                         $("<td/>")
-                         .attr("id", "friendStatusButtonHolder" + this.id)
-                     )
-                 );
-
-                 if(this.username != currentUser){
-                     // check if already added
-                     if(rave.personprofile.isUserAlreadyFriend(this.username)){
-                         $('#friendStatusButtonHolder'+this.id)
-                         .append(
-                             $("<a/>")
-                             .attr("href", "#")
-                             .attr("id", this.entityId)
-                             .attr("onclick", 
"rave.personprofile.removeFriend("+this.id+", '"+this.username+"');")
-                             .text(rave.getClientMessage("common.remove"))
-                         );
-                     // check if already sent friend request
-                     }else 
if(rave.personprofile.isFriendRequestSent(this.username)){
-                         $('#friendStatusButtonHolder'+this.id)
-                         .append(
-                             $("<a/>")
-                             .attr("href", "#")
-                             .attr("id", this.entityId)
-                             .attr("onclick", 
"rave.personprofile.removeFriendRequestSent("+this.id+", '"+this.username+"');")
-                             
.text(rave.getClientMessage("common.cancel.request"))
-                         );
-                     }else 
if(rave.personprofile.isFriendRequestReceived(this.username)){
-                         $('#friendStatusButtonHolder'+this.id)
-                         .append(
-                             $("<a/>")
-                             .attr("href", "#")
-                             .attr("id", this.entityId)
-                             .attr("onclick", 
"rave.personprofile.acceptFriendRequest("+this.entityId+", 
'"+this.username+"');")
-                             .text(rave.getClientMessage("common.accept")),
-                             ' / ',
-                             $("<a/>")
-                             .attr("href", "#")
-                             .attr("id", this.id)
-                             .attr("onclick", 
"rave.personprofile.declineFriendRequest("+this.id+", '"+this.username+"');")
-                             .text(rave.getClientMessage("common.decline"))
-                         );
-                     }else {
-                         $('#friendStatusButtonHolder'+this.id)
-                         .append(
-                             $("<a/>")
-                             .attr("href", "#")
-                             .attr("id", this.id)
-                             .attr("onclick", 
"rave.personprofile.addFriend("+this.id+", '"+this.username+"');")
-                             .text(rave.getClientMessage("common.add"))
-                         );
-                     }
-                 }
-
-         });
-     }
-
-     function paginate(userResults){
-         var $pagingDiv = $('#userSearchListPaging');
-         $pagingDiv.empty();
-         if(userResults.result.pageSize < userResults.result.totalResults){
-             $pagingDiv.append('<div class="pagination"><ul id="pagingul" >');
-             if(userResults.result.currentPage > 1){
-                 offset = (userResults.result.currentPage - 2) * 
userResults.result.pageSize;
-                 $('#pagingul').append('<li><a href="#" 
onclick="rave.api.rpc.getUsers({offset: ' +
-                     offset+', successCallback: function(result)' +
-                         ' 
{rave.personprofile.dealWithUserResults(result);}});">&lt;</a></li>');
-             }
-             for(var i=1;i<=userResults.result.numberOfPages;i++){
-                 if(i == userResults.result.currentPage){
-                     $('#pagingul').append('<li class="active"><a 
href="#">'+i+'</a></li>');
-                 }else{
-                     offset = (i - 1) * userResults.result.pageSize;
-                     $('#pagingul').append('<li><a href="#" 
onclick="rave.api.rpc.getUsers({offset: ' +
-                         offset + ', successCallback: function(result)' +
-                             ' 
{rave.personprofile.dealWithUserResults(result);}});">' + i + '</a></li>');
-                 }
-             }
-             if (userResults.result.currentPage < 
userResults.result.numberOfPages){
-                 offset = (userResults.result.currentPage) * 
userResults.result.pageSize;
-                 $('#pagingul').append('<li><a href="#" 
onclick="rave.api.rpc.getUsers({offset: ' +
-                     offset + ', successCallback: function(result)' +
-                         ' 
{rave.personprofile.dealWithUserResults(result);}});">&gt;</a></li>');
-             }
-             $pagingDiv.append('</ul></div>');
-         }
-     }
-
-     // Add a friend to the current user
-     function addFriend(userId, username){
-             $('#friendStatusButtonHolder'+userId).hide();
-             rave.api.rpc.addFriend({friendUsername : username,
-                 successCallback: function(result) {
-                     rave.personprofile.addFriendRequestUI(username);
-                     $('#friendStatusButtonHolder'+userId).empty();
-                     $('#friendStatusButtonHolder'+userId)
-                         .append(
-                                 $("<a/>")
-                                 .attr("href", "#")
-                                 .attr("id", userId)
-                                 .attr("onclick", 
"rave.personprofile.removeFriendRequestSent(" +
-                                     userId+", '" + username+"');")
-                                 
.text(rave.getClientMessage("common.cancel.request"))
-                         );
-                     $('#friendStatusButtonHolder'+userId).show();
-                 }
-             });
-     }
-
-     // Remove a friend of the current user
-     function removeFriend(userId, username){
-         var message = 
rave.layout.searchHandler.updateParamsInString(rave.getClientMessage("remove.friend.confirm"),
-                 new Array(username));
-         if(confirm(message)){
-             $('#friendStatusButtonHolder'+userId).hide();
-             rave.api.rpc.removeFriend({friendUsername : username,
-                 successCallback: function(result) {
-                     rave.personprofile.removeFriendUI(username);
-                     $('#friendStatusButtonHolder'+userId).empty();
-                     $('#friendStatusButtonHolder'+userId)
-                         .append(
-                                 $("<a/>")
-                                 .attr("href", "#")
-                                 .attr("id", userId)
-                                 .attr("onclick", 
"rave.personprofile.addFriend(" +
-                                     userId+", '" + username+"');")
-                                 .text(rave.getClientMessage("common.add"))
-                         );
-                     $('#friendStatusButtonHolder'+userId).show();
-                 }
-             });
-         }
-     }
-
-     // Cancel the friend request already sent to a user
-     function removeFriendRequestSent(userId, username){
-         var message = 
rave.layout.searchHandler.updateParamsInString(rave.getClientMessage("remove.friend.request.confirm"),
-                 new Array(username));
-         if(confirm(message)){
-             $('#friendStatusButtonHolder'+userId).hide();
-             rave.api.rpc.removeFriend({friendUsername : username,
-                 successCallback: function(result) {
-                     rave.personprofile.removeFriendRequestSentUI(username);
-                     $('#friendStatusButtonHolder'+userId).empty();
-                     $('#friendStatusButtonHolder'+userId)
-                         .append(
-                                 $("<a/>")
-                                 .attr("href", "#")
-                                 .attr("id", userId)
-                                 .attr("onclick", 
"rave.personprofile.addFriend(" +
-                                     userId+", '" + username+"');")
-                                 .text(rave.getClientMessage("common.add"))
-                         );
-                     $('#friendStatusButtonHolder'+userId).show();
-                 }
-             });
-         }
-     }
-
-     // Accept the friend request received by user
-     function acceptFriendRequest(userId, username){
-         $('#friendStatusButtonHolder'+userId).hide();
-         rave.api.rpc.acceptFriendRequest({friendUsername : username,
-             successCallback: function(result) {
-                 rave.personprofile.removeFriendRequestReceivedUI(username);
-                 $('#friendStatusButtonHolder'+userId).empty();
-                 $('#friendStatusButtonHolder'+userId)
-                     .append(
-                             $("<a/>")
-                             .attr("href", "#")
-                             .attr("id", userId)
-                             .attr("onclick", 
"rave.personprofile.removeFriend(" +
-                                 userId+", '" + username+"');")
-                             .text(rave.getClientMessage("common.remove"))
-                     );
-                 $('#friendStatusButtonHolder'+userId).show();
-             }
-         });
-     }
-
-     // Decline the friend request received by user
-     function declineFriendRequest(userId, username){
-         $('#friendStatusButtonHolder'+userId).hide();
-         rave.api.rpc.removeFriend({friendUsername : username,
-             successCallback: function(result) {
-                 rave.personprofile.removeFriendRequestReceivedUI(username);
-                 $('#friendStatusButtonHolder'+userId).empty();
-                 $('#friendStatusButtonHolder'+userId)
-                     .append(
-                             $("<a/>")
-                             .attr("href", "#")
-                             .attr("id", userId)
-                             .attr("onclick", "rave.personprofile.addFriend(" +
-                                 userId+", '" + username+"');")
-                             .text(rave.getClientMessage("common.add"))
-                     );
-                 $('#friendStatusButtonHolder'+userId).show();
-             }
-         });
-     }
-     // Add an item to the List of friend requests sent(maintained for the UI)
-     function addFriendRequestUI(username){
-         rave.personprofile.requestsSent.push(username);
-     }
-
-     // Remove a friend from the list of friends(maintained for the UI)
-     function removeFriendUI(friendUsername){
-         
rave.personprofile.friends.splice(rave.personprofile.friends.indexOf(friendUsername),1);
-     }
-
-     // Remove a friend request from the list of friend requests 
sent(maintained for the UI)
-     function removeFriendRequestSentUI(friendUsername){
-         
rave.personprofile.requestsSent.splice(rave.personprofile.requestsSent.indexOf(friendUsername),1);
-     }
-
-     // Remove a friend request from the list of friend requests 
received(maintained for the UI)
-     function removeFriendRequestReceivedUI(friendUsername){
-         
rave.personprofile.friendRequestsReceived.splice(rave.personprofile.friendRequestsReceived.indexOf(friendUsername),1);
-     }
-
-     // Check if the user is already a friend
-     function isUserAlreadyFriend(username){
-         if(rave.personprofile.friends.indexOf(username)>=0){
-             return true;
-         } else {
-             return false;
-         }
-     }
-
-     // Check if a friend request is already sent to a particular user
-     function isFriendRequestSent(username){
-         if(rave.personprofile.requestsSent.indexOf(username)>=0){
-             return true;
-         } else {
-             return false;
-         }
-     }
-
-     // Check if a friend request is received from a particular user
-     function isFriendRequestReceived(username){
-         if(rave.personprofile.friendRequestsReceived.indexOf(username)>=0){
-             return true;
-         } else {
-             return false;
-         }
-     }
+            if(isActive){
+                $tab.tab('show');
+            }
+        });
+    }
+
+    function activeSubPageExists(activeSubPage, tabs){
+        var exists = false;
+        $.each(tabs, function(i, el){
+            if(el.innerHTML === activeSubPage){
+                exists = true;
+            }
+        });
+
+        return exists;
+    }
+
+    function updateParamsInString(i18nStr, itemsToReplace){
+        for(var i=0;i<itemsToReplace.length;i++){
+            var token = '{'+i+'}';
+            i18nStr = i18nStr.replace(token, itemsToReplace[i]);
+        }
+        return i18nStr;
+    }
+
+    function dealWithUserResults(userResults){
+        var currentUser = $("#addRemoveFriend").get(0).value;
+        var searchTerm = $('#searchTerm').get(0).value;
+        if(searchTerm == undefined || searchTerm == ""){
+            $('#clearSearchButton').hide();
+        }else{
+            $('#clearSearchButton').show();
+        }
+        var legend;
+        if(userResults.result.resultSet.length < 1){
+            legend = rave.getClientMessage("no.results.found");
+        }else{
+            legend = 
updateParamsInString(rave.getClientMessage("search.list.result.x.to.y"),
+                new Array(userResults.result.offset + 1, 
userResults.result.resultSet.length
+                    + userResults.result.offset, 
userResults.result.totalResults));
+        }
+        // show the listheader
+        $('#userSearchListHeader').text(legend);
+        var $targetDiv = $('#userSearchResults');
+        $targetDiv.empty();
+        // show the paginator
+        paginate(userResults);
+        //now build the content
+        $targetDiv
+            .append(
+                $("<table/>")
+                    .addClass("searchdialogcontent")
+                    .append(
+                        $("<tr/>")
+                            .append(
+                                $("<td/>")
+                                    .addClass("textcell")
+                                    .append(
+                                        $("<b/>")
+                                            
.text(rave.getClientMessage("common.username"))
+                                    )
+                            )
+                            .append(
+                                $("<td/>")
+                                    .addClass("booleancell")
+                                    .append(
+                                        $("<b/>")
+                                            
.text(rave.getClientMessage("common.friend.status"))
+                                    )
+                            )
+                    )
+                    .append(
+                        $("<tbody/>")
+                            .attr("id", "searchResultsBody")
+                    )
+            );
+
+        jQuery.each(userResults.result.resultSet, function() {
+            $('#searchResultsBody')
+                .append(
+                    $("<tr/>")
+                        .attr("id", "searchResultRecord")
+                        .append(
+                            $("<td/>")
+                                .text(this.username)
+                        )
+                        .append(
+                            $("<td/>")
+                                .attr("id", "friendStatusButtonHolder" + 
this.id)
+                        )
+                );
+
+            if(this.username != currentUser){
+                // check if already added
+                if(rave.personprofile.isUserAlreadyFriend(this.username)){
+                    $('#friendStatusButtonHolder'+this.id)
+                        .append(
+                            $("<a/>")
+                                .attr("href", "#")
+                                .attr("id", this.entityId)
+                                .attr("onclick", 
"rave.personprofile.removeFriend("+this.id+", '"+this.username+"');")
+                                .text(rave.getClientMessage("common.remove"))
+                        );
+                    // check if already sent friend request
+                }else 
if(rave.personprofile.isFriendRequestSent(this.username)){
+                    $('#friendStatusButtonHolder'+this.id)
+                        .append(
+                            $("<a/>")
+                                .attr("href", "#")
+                                .attr("id", this.entityId)
+                                .attr("onclick", 
"rave.personprofile.removeFriendRequestSent("+this.id+", '"+this.username+"');")
+                                
.text(rave.getClientMessage("common.cancel.request"))
+                        );
+                }else 
if(rave.personprofile.isFriendRequestReceived(this.username)){
+                    $('#friendStatusButtonHolder'+this.id)
+                        .append(
+                            $("<a/>")
+                                .attr("href", "#")
+                                .attr("id", this.entityId)
+                                .attr("onclick", 
"rave.personprofile.acceptFriendRequest("+this.entityId+", 
'"+this.username+"');")
+                                .text(rave.getClientMessage("common.accept")),
+                            ' / ',
+                            $("<a/>")
+                                .attr("href", "#")
+                                .attr("id", this.id)
+                                .attr("onclick", 
"rave.personprofile.declineFriendRequest("+this.id+", '"+this.username+"');")
+                                .text(rave.getClientMessage("common.decline"))
+                        );
+                }else {
+                    $('#friendStatusButtonHolder'+this.id)
+                        .append(
+                            $("<a/>")
+                                .attr("href", "#")
+                                .attr("id", this.id)
+                                .attr("onclick", 
"rave.personprofile.addFriend("+this.id+", '"+this.username+"');")
+                                .text(rave.getClientMessage("common.add"))
+                        );
+                }
+            }
+
+        });
+    }
+
+    function paginate(userResults){
+        var $pagingDiv = $('#userSearchListPaging');
+        $pagingDiv.empty();
+        if(userResults.result.pageSize < userResults.result.totalResults){
+            $pagingDiv.append('<div class="pagination"><ul id="pagingul" >');
+            if(userResults.result.currentPage > 1){
+                offset = (userResults.result.currentPage - 2) * 
userResults.result.pageSize;
+                $('#pagingul').append('<li><a href="#" 
onclick="rave.api.rpc.getUsers({offset: ' +
+                    offset+', successCallback: function(result)' +
+                    ' 
{rave.personprofile.dealWithUserResults(result);}});">&lt;</a></li>');
+            }
+            for(var i=1;i<=userResults.result.numberOfPages;i++){
+                if(i == userResults.result.currentPage){
+                    $('#pagingul').append('<li class="active"><a 
href="#">'+i+'</a></li>');
+                }else{
+                    offset = (i - 1) * userResults.result.pageSize;
+                    $('#pagingul').append('<li><a href="#" 
onclick="rave.api.rpc.getUsers({offset: ' +
+                        offset + ', successCallback: function(result)' +
+                        ' 
{rave.personprofile.dealWithUserResults(result);}});">' + i + '</a></li>');
+                }
+            }
+            if (userResults.result.currentPage < 
userResults.result.numberOfPages){
+                offset = (userResults.result.currentPage) * 
userResults.result.pageSize;
+                $('#pagingul').append('<li><a href="#" 
onclick="rave.api.rpc.getUsers({offset: ' +
+                    offset + ', successCallback: function(result)' +
+                    ' 
{rave.personprofile.dealWithUserResults(result);}});">&gt;</a></li>');
+            }
+            $pagingDiv.append('</ul></div>');
+        }
+    }
+
+    // Add a friend to the current user
+    function addFriend(userId, username){
+        $('#friendStatusButtonHolder'+userId).hide();
+        rave.api.rpc.addFriend({friendUsername : username,
+            successCallback: function(result) {
+                rave.personprofile.addFriendRequestUI(username);
+                $('#friendStatusButtonHolder'+userId).empty();
+                $('#friendStatusButtonHolder'+userId)
+                    .append(
+                        $("<a/>")
+                            .attr("href", "#")
+                            .attr("id", userId)
+                            .attr("onclick", 
"rave.personprofile.removeFriendRequestSent(" +
+                                userId+", '" + username+"');")
+                            
.text(rave.getClientMessage("common.cancel.request"))
+                    );
+                $('#friendStatusButtonHolder'+userId).show();
+            }
+        });
+    }
+
+    // Remove a friend of the current user
+    function removeFriend(userId, username){
+        var message = 
updateParamsInString(rave.getClientMessage("remove.friend.confirm"),
+            new Array(username));
+        if(confirm(message)){
+            $('#friendStatusButtonHolder'+userId).hide();
+            rave.api.rpc.removeFriend({friendUsername : username,
+                successCallback: function(result) {
+                    rave.personprofile.removeFriendUI(username);
+                    $('#friendStatusButtonHolder'+userId).empty();
+                    $('#friendStatusButtonHolder'+userId)
+                        .append(
+                            $("<a/>")
+                                .attr("href", "#")
+                                .attr("id", userId)
+                                .attr("onclick", 
"rave.personprofile.addFriend(" +
+                                    userId+", '" + username+"');")
+                                .text(rave.getClientMessage("common.add"))
+                        );
+                    $('#friendStatusButtonHolder'+userId).show();
+                }
+            });
+        }
+    }
+
+    // Cancel the friend request already sent to a user
+    function removeFriendRequestSent(userId, username){
+        var message = 
updateParamsInString(rave.getClientMessage("remove.friend.request.confirm"),
+            new Array(username));
+        if(confirm(message)){
+            $('#friendStatusButtonHolder'+userId).hide();
+            rave.api.rpc.removeFriend({friendUsername : username,
+                successCallback: function(result) {
+                    rave.personprofile.removeFriendRequestSentUI(username);
+                    $('#friendStatusButtonHolder'+userId).empty();
+                    $('#friendStatusButtonHolder'+userId)
+                        .append(
+                            $("<a/>")
+                                .attr("href", "#")
+                                .attr("id", userId)
+                                .attr("onclick", 
"rave.personprofile.addFriend(" +
+                                    userId+", '" + username+"');")
+                                .text(rave.getClientMessage("common.add"))
+                        );
+                    $('#friendStatusButtonHolder'+userId).show();
+                }
+            });
+        }
+    }
+
+    // Accept the friend request received by user
+    function acceptFriendRequest(userId, username){
+        $('#friendStatusButtonHolder'+userId).hide();
+        rave.api.rpc.acceptFriendRequest({friendUsername : username,
+            successCallback: function(result) {
+                rave.personprofile.removeFriendRequestReceivedUI(username);
+                $('#friendStatusButtonHolder'+userId).empty();
+                $('#friendStatusButtonHolder'+userId)
+                    .append(
+                        $("<a/>")
+                            .attr("href", "#")
+                            .attr("id", userId)
+                            .attr("onclick", 
"rave.personprofile.removeFriend(" +
+                                userId+", '" + username+"');")
+                            .text(rave.getClientMessage("common.remove"))
+                    );
+                $('#friendStatusButtonHolder'+userId).show();
+            }
+        });
+    }
+
+    // Decline the friend request received by user
+    function declineFriendRequest(userId, username){
+        $('#friendStatusButtonHolder'+userId).hide();
+        rave.api.rpc.removeFriend({friendUsername : username,
+            successCallback: function(result) {
+                rave.personprofile.removeFriendRequestReceivedUI(username);
+                $('#friendStatusButtonHolder'+userId).empty();
+                $('#friendStatusButtonHolder'+userId)
+                    .append(
+                        $("<a/>")
+                            .attr("href", "#")
+                            .attr("id", userId)
+                            .attr("onclick", "rave.personprofile.addFriend(" +
+                                userId+", '" + username+"');")
+                            .text(rave.getClientMessage("common.add"))
+                    );
+                $('#friendStatusButtonHolder'+userId).show();
+            }
+        });
+    }
+    // Add an item to the List of friend requests sent(maintained for the UI)
+    function addFriendRequestUI(username){
+        rave.personprofile.requestsSent.push(username);
+    }
+
+    // Remove a friend from the list of friends(maintained for the UI)
+    function removeFriendUI(friendUsername){
+        
rave.personprofile.friends.splice(rave.personprofile.friends.indexOf(friendUsername),1);
+    }
+
+    // Remove a friend request from the list of friend requests 
sent(maintained for the UI)
+    function removeFriendRequestSentUI(friendUsername){
+        
rave.personprofile.requestsSent.splice(rave.personprofile.requestsSent.indexOf(friendUsername),1);
+    }
+
+    // Remove a friend request from the list of friend requests 
received(maintained for the UI)
+    function removeFriendRequestReceivedUI(friendUsername){
+        
rave.personprofile.friendRequestsReceived.splice(rave.personprofile.friendRequestsReceived.indexOf(friendUsername),1);
+    }
+
+    // Check if the user is already a friend
+    function isUserAlreadyFriend(username){
+        if(rave.personprofile.friends.indexOf(username)>=0){
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    // Check if a friend request is already sent to a particular user
+    function isFriendRequestSent(username){
+        if(rave.personprofile.requestsSent.indexOf(username)>=0){
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    // Check if a friend request is received from a particular user
+    function isFriendRequestReceived(username){
+        if(rave.personprofile.friendRequestsReceived.indexOf(username)>=0){
+            return true;
+        } else {
+            return false;
+        }
+    }
 
     function initButtons() {
         // setup the edit button if it exists
@@ -443,8 +451,8 @@ rave.personprofile = rave.personprofile 
         // When the user accepts a friend request
         var $acceptFriend = $(".acceptFriendRequest");
         if($acceptFriend) {
-              $acceptFriend.click(function(e) {
-                  rave.api.rpc.acceptFriendRequest({friendUsername : this.id});
+            $acceptFriend.click(function(e) {
+                rave.api.rpc.acceptFriendRequest({friendUsername : this.id});
                 var listRequestItem = $(this).parents('.requestItem');
                 var friendRequestMenu = $(listRequestItem).parent();
                 $(listRequestItem).remove();
@@ -464,7 +472,7 @@ rave.personprofile = rave.personprofile 
         var $declineFriend = $(".declineFriendRequest");
         if($declineFriend) {
             $declineFriend.click(function(e) {
-                  rave.api.rpc.removeFriend({friendUsername : this.id});
+                rave.api.rpc.removeFriend({friendUsername : this.id});
                 var listRequestItem = $(this).parents('.requestItem');
                 var friendRequestMenu = $(listRequestItem).parent();
                 $(listRequestItem).remove();
@@ -483,7 +491,7 @@ rave.personprofile = rave.personprofile 
 
     // Gets the list of friends from the DB
     function getFriends(args) {
-           rave.personprofile.friends = new Array();
+        rave.personprofile.friends = new Array();
         rave.personprofile.requestsSent = new Array();
         rave.personprofile.friendRequestsReceived = new Array();
         rave.api.rpc.getFriends({

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_ui.js
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_ui.js?rev=1455957&r1=1455956&r2=1455957&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_ui.js 
(original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_ui.js 
Wed Mar 13 14:29:38 2013
@@ -20,31 +20,182 @@
 rave.ui = rave.ui || (function () {
     var exports = {};
 
-    init();
+    /*
+     Register View Helpers
+     */
+
+    Handlebars.registerHelper('getClientMessage', function (key) {
+        return rave.getClientMessage(key);
+    })
+
+    /*
+     Register templates
+     */
+    var templates = exports.templates = {};
+    $('[data-template-for]').each(function () {
+        var key = $(this).data('template-for');
+        var source = $(this).html();
+
+        templates[key] = Handlebars.compile(source);
+    });
+
+    /*
+     Build rave client side views
+     */
+    var views = exports.views = {};
+
+    /*
+     View for managing sharing / cloning of pages
+     */
+    var PageSharingModalView = rave.View.extend({
+        template:templates['user-search-view'],
+        //the bootstrap modal div
+        modalDiv:$('#sharePageDialog'),
+        //attach point for this view
+        container:$('#sharePageDialogContent'),
+
+        models:{
+            page:rave.models.currentPage,
+            users:rave.models.users
+        },
+
+        initialize:function () {
+            var page = this.models.page;
+            var users = this.models.users;
+
+            this.constructor.__super__.initialize.apply(this);
+
+            page.on('share', this.flash, this);
+            page.on('error', this.handleError, this);
+
+            //whenever the modal is displayed reset the view
+            this.modalDiv.on('show', function () {
+                users.fetchPage(1);
+            });
+
+            //extend users toViewModel function to include share properties
+            this.models.users.toViewModel = 
_.wrap(this.models.users.toViewModel, function (toViewModel) {
+                var model = toViewModel.apply(this);
+
+                _.each(model.users, function (user) {
+                    user.isOwner = page.isUserOwner(user.id);
+                    user.hasShare = page.isUserMember(user.id);
+                    user.hasEdit = page.isUserEditor(user.id);
+                });
+
+                return model;
+            });
+
+            this.container.html(this.$el);
+        },
+
+        events:{
+            'click #shareSearchButton':'search',
+            'keypress #searchTerm':'search',
+            'click #clearSearchButton':'clearSearch',
+            'click #pagingul a':'page',
+            'click .searchResultRecord a':'shareAction'
+        },
+
+        search:function (e) {
+            //allow search function to trigger from enter keypress or button 
click
+            if (e.which == 13 || _.isUndefined(e.which)) {
+                var term = $('#searchTerm', this.$el).val();
+
+                this.models.users.filter(term);
+            }
+        },
+
+        clearSearch:function (e) {
+            this.models.users.filter(null);
+        },
+
+        page:function (e) {
+            var page = $(e.target).data('pagenumber');
+
+            this.models.users.fetchPage(page);
+        },
+
+        //manages any add / remove share, editor or clone actions
+        shareAction:function (e) {
+            var userId = $(e.target).data('userid');
+            var action = $(e.target).data('action');
+
+            this.models.page[action](userId);
+        },
+
+        //flash success messages
+        flash:function (event, userId) {
+            var eventsToMessages = {
+                'member:add': 'create.share',
+                'member:remove': 'revoke.share',
+                'editor:add': '',
+                'editor:remove': '',
+                'clone':'success.clone.page'
+            }
+
+            var msg = eventsToMessages[event];
+
+            if(msg){
+                var message = rave.getClientMessage(msg);
+                var user = this.models.users.get(userId);
+                rave.showInfoMessage('('+user.get('username')+') '+message);
+            }
+        },
+
+        //TODO: deal with errors better. Until we have a better api or there 
is another view for this modal,
+        //manually manage the form
+        handleError: function(errorCode, userId){
+            var self = this;
+
+            if (errorCode == 'DUPLICATE_ITEM') {
+                this.modalDiv.modal('hide');
+                
$("#pageMenuDialogHeader").html(rave.getClientMessage("page.update"));
+                
$("#pageFormErrors").html(rave.getClientMessage("page.duplicate_name"));
+                $("#pageLayoutGroup").hide();
+                var $pageMenuUpdateButton = $("#pageMenuUpdateButton");
+                
$pageMenuUpdateButton.html(rave.getClientMessage("common.save"));
+                // unbind the previous click event since we are sharing the
+                // dialog between separate add/edit page actions
+                $pageMenuUpdateButton.unbind('click');
+                $pageMenuUpdateButton.click(function () {
+                    var $pageForm = $("#pageForm");
+                    var $tab_title_input = $("#tab_title");
+                    if ($pageForm.valid()) {
+                        self.models.page.cloneForUser(userId, 
$tab_title_input.val());
+                        $("#pageMenuDialog").modal('hide');
+                    }
+                });
+                $('#pageMenuDialog').on('shown', function () {
+                    $("#tab_title").first().focus();
+                });
+                //
+                $("#pageMenuDialog").modal('show');
+            } else {
+                $("#pageMenuDialog").modal('hide');
+                alert(rave.getClientMessage("api.rpc.error.internal"));
+            }
+        }
+    });
+
+    views.pageSharingModal = new PageSharingModalView();
+
+    //TODO: root app view, will be expanded significantly
+    var App = rave.View.extend({
+        models: {
+            page: rave.models.currentPage
+        },
+
+        initialize: function(){
+            this.models.page.on('acceptShare', rave.viewPage);
+            this.models.page.on('declineShare', function(){
+                //TODO: this doesn't actually work - but it's what current 
code did. Need to replace with a navigate to default page function
+                document.location.href = '/';
+            });
+        }
+    });
 
-    function init(){
-        registerViewHelpers();
-        registerTemplates();
-    }
-
-    function registerViewHelpers(){
-        //TODO: rave.getClientMessage view helper? Thank about it.
-        Handlebars.registerHelper('getClientMessage', function(key){
-            return rave.getClientMessage(key);
-        })
-    }
-
-    function registerTemplates() {
-        var templates = {};
-        $('[data-template-for]').each(function () {
-            var key = $(this).attr('data-template-for');
-            var source = $(this).html();
-
-            templates[key] = Handlebars.compile(source);
-        });
-
-        exports.templates = templates;
-    }
+    views.app = new App();
 
     return exports;
-})()
\ No newline at end of file
+})();
\ No newline at end of file

Modified: 
rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-server/rave-shindig-resources/src/main/webapp/index.jsp
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-server/rave-shindig-resources/src/main/webapp/index.jsp?rev=1455957&r1=1455956&r2=1455957&view=diff
==============================================================================
--- 
rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-server/rave-shindig-resources/src/main/webapp/index.jsp
 (original)
+++ 
rave/trunk/rave-providers/rave-opensocial-provider/rave-opensocial-server/rave-shindig-resources/src/main/webapp/index.jsp
 Wed Mar 13 14:29:38 2013
@@ -19,5 +19,5 @@
   $Id$
 --%>
 <%
- response.sendRedirect("/portal");
+    response.sendRedirect("/portal");
 %>


Reply via email to