Index: lams_central/src/java/org/lamsfoundation/lams/web/planner/PedagogicalPlannerAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/planner/PedagogicalPlannerAction.java,v diff -u -r1.18.2.3.2.4 -r1.18.2.3.2.5 --- lams_central/src/java/org/lamsfoundation/lams/web/planner/PedagogicalPlannerAction.java 11 Mar 2010 19:55:01 -0000 1.18.2.3.2.4 +++ lams_central/src/java/org/lamsfoundation/lams/web/planner/PedagogicalPlannerAction.java 12 Mar 2010 16:48:43 -0000 1.18.2.3.2.5 @@ -92,6 +92,7 @@ import org.lamsfoundation.lams.learningdesign.ToolActivity; import org.lamsfoundation.lams.learningdesign.Transition; import org.lamsfoundation.lams.learningdesign.dao.hibernate.ActivityDAO; +import org.lamsfoundation.lams.learningdesign.exception.LearningDesignException; import org.lamsfoundation.lams.learningdesign.service.IExportToolContentService; import org.lamsfoundation.lams.learningdesign.service.ImportToolContentException; import org.lamsfoundation.lams.lesson.Lesson; @@ -106,6 +107,8 @@ import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.usermanagement.exception.UserAccessDeniedException; +import org.lamsfoundation.lams.usermanagement.exception.UserException; +import org.lamsfoundation.lams.usermanagement.exception.WorkspaceFolderException; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.CentralConstants; import org.lamsfoundation.lams.util.CentralToolContentHandler; @@ -120,6 +123,7 @@ import org.lamsfoundation.lams.web.action.LamsDispatchAction; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; +import org.lamsfoundation.lams.workspace.service.WorkspaceManagementService; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -1206,12 +1210,7 @@ return null; } - HttpSession session = SessionManager.getSession(); - UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER); - User user = (User) getUserManagementService().findById(User.class, userDto.getUserID()); - if (user == null) { - throw new ServletException(PedagogicalPlannerAction.ERROR_USER_NOT_FOUND); - } + User user = getUser(); List toolsErrorMsgs = new ArrayList(); Long learningDesignID = null; LearningDesign learningDesign = null; @@ -1285,6 +1284,20 @@ } return workspaceFolder.getWorkspaceFolderId(); } + + /** + * Returns current user stored in session. + * @throws ServletException + */ + private User getUser() throws ServletException { + HttpSession session = SessionManager.getSession(); + UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER); + User user = (User) getUserManagementService().findById(User.class, userDto.getUserID()); + if (user == null) { + throw new ServletException(PedagogicalPlannerAction.ERROR_USER_NOT_FOUND); + } + return user; + } /** * Copies the template files from repository into the selected dir. @@ -1540,11 +1553,9 @@ return mapping.findForward(PedagogicalPlannerAction.FORWARD_GROUPING); } - private List getRecentlyModifiedLearnindDesignsAsNodes() { + private List getRecentlyModifiedLearnindDesignsAsNodes() throws ServletException { // Add the recently modified learning design list, if it's the root node with no filtering - HttpSession session = SessionManager.getSession(); - UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER); - User user = (User) getUserManagementService().findById(User.class, userDto.getUserID()); + User user = getUser(); // the list is sorted most-recently-edited-on-top (so by the timestamp descending) Set recentLDs = user.getRecentlyModifiedLearningDesigns(); List recentNodes = new LinkedList(); @@ -1566,11 +1577,10 @@ * list. * * @param learningDesignId + * @throws ServletException */ - private void updateRecentLearningDesignList(Long learningDesignId) { - HttpSession session = SessionManager.getSession(); - UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER); - User user = (User) getUserManagementService().findById(User.class, userDto.getUserID()); + private void updateRecentLearningDesignList(Long learningDesignId) throws ServletException { + User user = getUser(); // the list is sorted most-recently-edited-on-top (so by the timestamp descending) Set recentLDs = user.getRecentlyModifiedLearningDesigns(); boolean ldFound = false; @@ -1594,7 +1604,43 @@ } /*-------------------------- TEMPLATE BASE METHODS -----------------*/ + + /** + * Copies LearningDesign to user's personal folder. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws ServletException + * @throws IOException + * @throws WorkspaceFolderException + * @throws UserException + * @throws LearningDesignException + */ + public ActionForward copyLearningDesign(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException, LearningDesignException, UserException, WorkspaceFolderException { + PedagogicalPlannerAction.log.debug("Copying LearningDesign to user's personal folder"); + Long designID = WebUtil.readLongParam(request, CentralConstants.PARAM_LEARNING_DESIGN_ID); + LearningDesign originalDesign = getAuthoringService().getLearningDesign(designID); + if (originalDesign == null) { + throw new LearningDesignException(getMessageService().getMessage("no.such.learningdesign.exist", + new Object[] { designID })); + } + User user = getUser(); + WorkspaceFolder targetFolder = user.getWorkspace().getDefaultFolder(); + Integer copyType = LearningDesign.COPY_TYPE_NONE; + boolean setOriginalDesign = false; + String newDesignName = originalDesign.getTitle(); + String customCSV = null; + + getAuthoringService().copyLearningDesign(originalDesign, copyType, user, targetFolder, setOriginalDesign, newDesignName, customCSV); + + return null; + } + /** * Saves additional, non tool-bound template details - currently only the title. * Index: lams_central/web/includes/javascript/pedagogicalPlanner.js =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/javascript/pedagogicalPlanner.js,v diff -u -r1.13.6.1 -r1.13.6.2 --- lams_central/web/includes/javascript/pedagogicalPlanner.js 25 Feb 2010 19:26:51 -0000 1.13.6.1 +++ lams_central/web/includes/javascript/pedagogicalPlanner.js 12 Mar 2010 16:48:43 -0000 1.13.6.2 @@ -8,7 +8,7 @@ var startPreviewUrl; //Url to start preview var learningDesignId; //ID of the design to open - var ACTION_DO_NOTHING = 0; //After successful submit do nothing + var ACTION_SAVE_AS_SEQUENCE = 0; //After successful submit save learning design in user's personal folder var ACTION_PREVIEW = 1; //After successful submit start preview var ACTION_OPEN_AUTHOR = 2; //After successful submit open full authoring var ACTION_EXPORT = 3; //After successful submit export the learning design @@ -22,7 +22,7 @@ if (actionAfterCompleted==ACTION_PREVIEW){ startPreviewUrl=additionalParameter; } - else if (actionAfterCompleted==ACTION_OPEN_AUTHOR || actionAfterCompleted==ACTION_EXPORT){ + else if (actionAfterCompleted==ACTION_SAVE_AS_SEQUENCE || actionAfterCompleted==ACTION_OPEN_AUTHOR || actionAfterCompleted==ACTION_EXPORT){ learningDesignId=additionalParameter; } callAttemptedID++; @@ -138,12 +138,24 @@ $('#pedagogicalPlannerBusy').hide(); if (sequenceDetailsValid && activitiesValid==activitiesResponded){ $('#pedagogicalPlannerInfoArea').show(); - if (actionAfterCompleted==ACTION_PREVIEW){ + if (actionAfterCompleted==ACTION_SAVE_AS_SEQUENCE){ + $.ajax({ + url: saveDetailsUrl, + cache: false, + data: "method=copyLearningDesign&ldId="+learningDesignId + }); + } + else if (actionAfterCompleted==ACTION_PREVIEW){ startPreview(startPreviewUrl); } else if (actionAfterCompleted==ACTION_OPEN_AUTHOR){ window.resizeTo(authoring_width,authoring_height); - document.location.href="home.do?method=author&learningDesignID="+learningDesignId; + $.ajax({ + url: saveDetailsUrl, + cache: false, + data: "method=copyLearningDesign&ldId="+learningDesignId + }); + document.location.href="home.do?method=author&learningDesignID="+learningDesignId; } else if (actionAfterCompleted==ACTION_EXPORT){ document.getElementById("downloadFileDummyIframe").src="pedagogicalPlanner.do?method=exportTemplate&ldId="+learningDesignId;