Author: psharples
Date: Wed Oct 17 14:45:09 2012
New Revision: 1399281

URL: http://svn.apache.org/viewvc?rev=1399281&view=rev
Log:
Added functionality to clone/copy page as well as share. See RAVE-819.

Modified:
    
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java
    
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
    
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
    rave/trunk/rave-portal-resources/src/main/resources/messages.properties
    rave/trunk/rave-portal-resources/src/main/resources/messages_es.properties
    rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties
    rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/page.jsp
    rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_api.js
    
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_layout.js

Modified: 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java
 (original)
+++ 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/PageService.java
 Wed Oct 17 14:45:09 2012
@@ -214,6 +214,16 @@ public interface PageService {
     Page movePageToDefault(long pageId);
 
     /**
+     * Clone the page and then share it with another user (Page is detached 
from original)
+     * @param pageId - the id of the page in question
+     * @param userId - the userid to add
+     * @param pageName = name of the page
+     * @return true or false whether the user was added
+     */
+    @PreAuthorize("hasPermission(#pageId, 'org.apache.rave.portal.model.Page', 
'update')")
+    Boolean clonePageForUser(long pageId, long userId, String pageName);
+
+    /**
      * Add another user to share this page with
      * @param pageId - the id of the page in question
      * @param userId - the userid to add
@@ -221,7 +231,7 @@ public interface PageService {
      */
     @PreAuthorize("hasPermission(#pageId, 'org.apache.rave.portal.model.Page', 
'update')")
     Boolean addMemberToPage(long pageId, long userId);
-    
+
     /**
      * Remove an existing user from the page share
      * @param pageId - the id of the page in question

Modified: 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
 (original)
+++ 
rave/trunk/rave-components/rave-core/src/main/java/org/apache/rave/portal/service/impl/DefaultPageService.java
 Wed Oct 17 14:45:09 2012
@@ -317,6 +317,33 @@ public class DefaultPageService implemen
     }
 
     @Transactional
+    public Boolean clonePageForUser(long pageId, long userId, String pageName) 
{
+        Widget widget = null;
+        Page page = getPage(pageId);
+        if(pageName == null || pageName.equals("null")){
+            // try to use the original page name if none supplied
+            pageName = page.getName();
+        }
+        Page clonedPage = addNewUserPage(userService.getUserById(userId), 
pageName, page.getPageLayout().getCode());
+        // populate all the widgets in cloned page from original
+        for(int i=0; i<page.getRegions().size(); i++){
+            for(int j=0; j<page.getRegions().get(i).getRegionWidgets().size(); 
j++){
+                widget = 
page.getRegions().get(i).getRegionWidgets().get(j).getWidget();
+                addWidgetToPageRegion(clonedPage.getId(), widget.getId(), 
clonedPage.getRegions().get(i).getId());
+            }
+        }
+        // newly created page - so only one pageUser
+        PageUser pageUser = clonedPage.getMembers().get(0);
+        // update status to pending
+        pageUser.setPageStatus(PageInvitationStatus.PENDING);
+        if(pageRepository.save(clonedPage) != null){
+            return Boolean.TRUE;
+        }else{
+            return Boolean.FALSE;
+        }
+    }
+
+    @Transactional
     public Boolean addMemberToPage(long pageId, long userId){
         Page page = getPage(pageId);
         PageUser pageUser = new PageUserImpl();
@@ -335,7 +362,16 @@ public class DefaultPageService implemen
 
     @Transactional
     public Boolean removeMemberFromPage(long pageId, long userId){
+        User user = userService.getAuthenticatedUser();
         Page page = this.getPage(pageId);
+        if(page.getOwner().equals(user)){
+            // If I am the owner, this page has been cloned
+            // Declining a cloned page means there is no need to strip
+            // out this users pageUser object, instead remove the page itself
+            // which also removes the pageUser object further down the stack
+            pageRepository.delete(page);
+            return true;
+        }
         PageUser pageUserToRemove = null;
         for(PageUser pageUser : page.getMembers()){
             if(pageUser.getUser().getId().equals(userId)){

Modified: 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
 (original)
+++ 
rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/api/rpc/PageApi.java
 Wed Oct 17 14:45:09 2012
@@ -233,6 +233,17 @@ public class PageApi {
     }
 
     @ResponseBody
+    @RequestMapping(value = "{pageId}/clone", method = RequestMethod.POST)
+    public RpcResult<Boolean> clonePageForUser(@PathVariable final long 
pageId, @RequestParam final long userId, @RequestParam final String pageName) {
+        return new RpcOperation<Boolean>() {
+             @Override
+             public Boolean execute() {
+               return pageService.clonePageForUser(pageId, userId, pageName);
+             }
+        }.getResult();
+    }
+
+    @ResponseBody
     @RequestMapping(value = "{pageId}/addmember", method = RequestMethod.POST)
     public RpcResult<Boolean> addMemberToPage(@PathVariable final long pageId, 
@RequestParam final long userId) {
         return new RpcOperation<Boolean>() {

Modified: 
rave/trunk/rave-portal-resources/src/main/resources/messages.properties
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/resources/messages.properties?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/resources/messages.properties 
(original)
+++ rave/trunk/rave-portal-resources/src/main/resources/messages.properties Wed 
Oct 17 14:45:09 2012
@@ -364,6 +364,7 @@ widget.menu.title=Widget Actions
 sharing.page.confirm.message={0} has shared this page with you. Do you wish to 
accept and add this page to your collection?
 sharing.page.tab.icon.tip.from=This page has been shared with you by {0}
 sharing.page.tab.icon.tip.to=You have shared this page with other users
+cloned.page.confirm.message=Another user has made a copy of his/her page and 
shared it with you. Do you wish to accept and add this page to your collection?
 
 
#######################################################################################################################
 # messages available to the client javascript via the MessageBundleController 
must start with "_rave_client."
@@ -421,4 +422,8 @@ _rave_client.success.add.from.marketplac
 _rave_client.person.profile.friend.requests.none=No Friend Requests
 _rave_client.person.profile.friend.requests=Friend Requests
 _rave_client.import.page.not.supported=Your browser does not support this 
operation
+_rave_client.confirm.clone.page=Are you sure you wish to create a copy of this 
page and share it with this user?
+_rave_client.success.clone.page=Cloned page was added to the users collection
+_rave_client.page.clone.dialog.title=Clone
+_rave_client.page.clone.dialog.detail=New
 page.general.status=Relationship Status\:

Modified: 
rave/trunk/rave-portal-resources/src/main/resources/messages_es.properties
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/resources/messages_es.properties?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/resources/messages_es.properties 
(original)
+++ rave/trunk/rave-portal-resources/src/main/resources/messages_es.properties 
Wed Oct 17 14:45:09 2012
@@ -369,6 +369,7 @@ widget.menu.title=Acciones de Widget
 
 sharing.page.tab.icon.tip.from=Esta pagina ha sido compartida con usted por 
{0}.
 sharing.page.tab.icon.tip.to=Usted ha compartido esta pagina con otros usuarios
+cloned.page.confirm.message=Otro usuario ha realizado una copia de su su / 
page y lo compartio con usted. Desea aceptar y anadir esta pagina a su 
coleccion?
 
 
#######################################################################################################################
 # todo lo relacionado con javascript mediante el MessageBundleController debe 
comenzar con "_rave_client."
@@ -430,4 +431,8 @@ _rave_client.common.cancel.request=Cance
 _rave_client.person.profile.friend.requests=Solicitudes de Amistad
 _rave_client.person.profile.friend.requests.none=No hay solicitudes de amistad
 _rave_client.import.page.not.supported=Su navegador no soporta esta operacion
+_rave_client.confirm.clone.page=Esta seguro que desea crear una copia de esta 
pagina y compartala con este usuario?
+_rave_client.success.clone.page=Pagina clonado fue anadido a la coleccion de 
usuarios
+_rave_client.page.clone.dialog.title=Clonar
+_rave_client.page.clone.dialog.detail=nuevo
 page.profile.friend.requests=Solicitudes de Amistad

Modified: 
rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties 
(original)
+++ rave/trunk/rave-portal-resources/src/main/resources/messages_nl.properties 
Wed Oct 17 14:45:09 2012
@@ -369,6 +369,7 @@ widget.menu.title=Widget acties
 sharing.page.confirm.message={0} heeft een pagina met jou gedeeld. Wil je deze 
gedeelde pagina accepteren en toevoegen?
 sharing.page.tab.icon.tip.from=Deze pagina is met jou gedeeld door {0}.
 sharing.page.tab.icon.tip.to=U hebt deze pagina met andere gebruikers gedeeld
+cloned.page.confirm.message=Een andere gebruiker heeft een kopie van zijn / 
haar pagina en gedeeld met je. Wilt u accepteren en deze pagina toe te voegen 
aan uw collectie?
 
 
#######################################################################################################################
 # boodschappen ter beschikking van de opdrachtgever javascript via de 
MessageBundleController moet beginnen met "_rave_client."
@@ -434,3 +435,7 @@ _rave_client.success.add.from.marketplac
 _rave_client.person.profile.friend.requests=Vriendschapsverzoeken
 _rave_client.person.profile.friend.requests.none=Geen vriendschapsverzoeken
 _rave_client.import.page.not.supported=Uw browser biedt geen ondersteuning 
voor deze bewerking
+_rave_client.confirm.clone.page=Weet u zeker dat u een kopie van deze pagina 
te maken en te delen met deze gebruiker?
+_rave_client.success.clone.page=Gekloonde pagina werd toegevoegd aan de 
gebruikers verzamelen
+_rave_client.page.clone.dialog.title=nieuw
+_rave_client.page.clone.dialog.detail=kloon

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/page.jsp
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/page.jsp?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/page.jsp 
(original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/WEB-INF/jsp/views/page.jsp 
Wed Oct 17 14:45:09 2012
@@ -156,9 +156,16 @@
                 <div class="emptyPageMessage">
                     <div>
                         <div id="confirmSharePageLegend">
-                            <fmt:message key="sharing.page.confirm.message">
-                                <fmt:param value="${page.owner.username}"/>
-                            </fmt:message>
+                            <c:choose>
+                                <c:when test="${page.owner.username == 
principleUsername}">
+                                    <fmt:message 
key="cloned.page.confirm.message"/>
+                                </c:when>
+                                <c:otherwise>
+                                    <fmt:message 
key="sharing.page.confirm.message">
+                                        <fmt:param 
value="${page.owner.username}"/>
+                                    </fmt:message>
+                                </c:otherwise>
+                            </c:choose>
                         </div>
                     </div>
                     <div>&nbsp;</div>
@@ -264,7 +271,7 @@
                             <input id="tab_title" name="tab_title" 
class="input-xlarge focused required" type="text" value="" />
                         </div>
                     </div>
-                    <div class="control-group">
+                    <div class="control-group" id="pageLayoutGroup">
                         <label class="control-label" 
for="pageLayout"><fmt:message key="page.general.addpage.selectlayout"/></label>
                         <div class="controls">
                             <select name="pageLayout" id="pageLayout">

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_api.js
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_api.js?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_api.js 
(original)
+++ rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_api.js 
Wed Oct 17 14:45:09 2012
@@ -479,6 +479,17 @@ rave.api = rave.api || (function() {
                     }).error(handleError);
         }
 
+        function clonePageForUser(args) {
+            $.post(rave.getContext() + path + "page/" + args.pageId + "/clone",
+               {"userId": args.userId,
+                "pageName" : args.pageName},
+               function(result) {
+                   if (typeof args.successCallback == 'function') {
+                        args.successCallback(result);
+                   }
+               }).error(handleError);
+        }
+
         function addMemberToPage(args) {
             $.post(rave.getContext() + path + "page/" + args.pageId + 
"/addmember",
                {"userId": args.userId},
@@ -625,6 +636,7 @@ rave.api = rave.api || (function() {
             getWidgetMetadataGroup: getWidgetMetadataGroup,
             getUsers : getUsers,
             searchUsers : searchUsers,
+            clonePageForUser : clonePageForUser,
             addMemberToPage : addMemberToPage,
             removeMemberFromPage : removeMemberFromPage,
             updateSharedPageStatus : updateSharedPageStatus,

Modified: 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_layout.js
URL: 
http://svn.apache.org/viewvc/rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_layout.js?rev=1399281&r1=1399280&r2=1399281&view=diff
==============================================================================
--- 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_layout.js 
(original)
+++ 
rave/trunk/rave-portal-resources/src/main/webapp/static/script/rave_layout.js 
Wed Oct 17 14:45:09 2012
@@ -104,6 +104,7 @@ rave.layout = rave.layout || (function()
                 }else{
                     
$("#pageMenuDialogHeader").html(rave.getClientMessage("page.add"));
                     var $pageMenuUpdateButton = $("#pageMenuUpdateButton");
+                    $("#pageLayoutGroup").show();
                     
$pageMenuUpdateButton.html(rave.getClientMessage("common.add"));
                     // unbind the previous click event since we are sharing the
                     // dialog between separate add/edit page actions
@@ -125,6 +126,7 @@ rave.layout = rave.layout || (function()
                                             
$page_layout_input.val(result.result.pageLayout.code);
                                             
$("#pageMenuDialogHeader").html(rave.getClientMessage("page.update"));
                                             var $pageMenuUpdateButton = 
$("#pageMenuUpdateButton");
+                                            $("#pageLayoutGroup").show();
                                             
$pageMenuUpdateButton.html(rave.getClientMessage("common.save"));
                                             // unbind the previous click event 
since we are sharing the
                                             // dialog between separate 
add/edit page actions
@@ -270,6 +272,13 @@ rave.layout = rave.layout || (function()
             }
         }
 
+        function clonePageForUser(userId, username){
+            var answer = confirm(rave.getClientMessage("confirm.clone.page") + 
" ("+username+")");
+            if(answer){
+                rave.layout.clonePage(this.pageId, userId, null);
+            }
+        }
+
         function addMemberToPage(userId, username){
             var answer = confirm(rave.getClientMessage("create.share.confirm") 
+ " ("+username+")");
             if(answer){
@@ -488,6 +497,14 @@ rave.layout = rave.layout || (function()
                                             
.text(rave.getClientMessage("common.editing.auth"))
                                         )
                                     )
+                                    .append(
+                                        $("<td/>")
+                                        .addClass("booleancell")
+                                        .append(
+                                            $("<b/>")
+                                            
.text(rave.getClientMessage("page.clone.dialog.title"))
+                                        )
+                                    )
                                 )
                         .append(
                             $("<tbody/>")
@@ -512,9 +529,25 @@ rave.layout = rave.layout || (function()
                             $("<td/>")
                             .attr("id", "pageEditorStatusHolder" + this.id)
                         )
+                        .append(
+                            $("<td/>")
+                            .attr("id", "cloneButtonHolder" + this.id)
+                        )
                     )
 
+
                     if(this.username != rave.layout.searchHandler.username){
+                        //
+                        $('#cloneButtonHolder'+this.id)
+                                .append(
+                                    $("<a/>")
+                                    .attr("href", "#")
+                                    .attr("id", this.id)
+                                    .attr("onclick", 
"rave.layout.searchHandler.clonePageForUser("+this.id+", '"+this.username+"');")
+                                    
.text(rave.getClientMessage("page.clone.dialog.detail"))
+                                )
+                        //
+                        
                         // check if already added
                         
if(rave.layout.searchHandler.isUserAlreadyAdded(this.username)){
                             $('#shareButtonHolder'+this.id)
@@ -569,6 +602,7 @@ rave.layout = rave.layout || (function()
             isUserAlreadyAdded : isUserAlreadyAdded,
             isUserEditor : isUserEditor,
             addMemberToPage : addMemberToPage,
+            clonePageForUser : clonePageForUser,
             removeMemberFromPage : removeMemberFromPage,
             addEditingRightsToMember: addEditingRightsToMember,
             removeEditingRightsFromMember : removeEditingRightsFromMember,
@@ -847,6 +881,44 @@ rave.layout = rave.layout || (function()
                                             }});
         }
     }
+    
+    function clonePage(pageId, userId, pageName) {
+        rave.api.rpc.clonePageForUser({pageId: pageId, userId: userId, 
pageName: pageName,
+            successCallback: function(result) {
+                if (result.error) {
+                    if (result.errorCode == 'DUPLICATE_ITEM') {
+                        $("#sharePageDialog").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(){
+                            if ($pageForm.valid()) {
+                                rave.layout.clonePage(pageId, userId, 
$tab_title_input.val());
+                            }
+                        });
+                        $('#pageMenuDialog').on('shown', function () {
+                            $("#tab_title").first().focus();
+                        });
+                        //
+                        $("#pageMenuDialog").modal('show');
+                    } else {
+                        $("#pageMenuDialog").modal('hide');
+                        alert(rave.getClientMessage("api.rpc.error.internal"));
+                    }
+                }
+                else {
+                    $("#pageMenuDialog").modal('hide');
+                    alert(rave.getClientMessage("success.clone.page"));
+                }
+            }
+        });
+    }
 
     function closePageDialog() {
         $pageForm[0].reset();
@@ -935,6 +1007,7 @@ rave.layout = rave.layout || (function()
         addPage: addPage,
         addOrImportPage : addOrImportPage,
         updatePage: updatePage,
+        clonePage: clonePage,
         movePage: movePage,
         importPage: importPage,
         closePageDialog: closePageDialog,


Reply via email to