Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java,v diff -u -r1.108 -r1.109 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java 3 Sep 2014 07:10:14 -0000 1.108 +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java 23 Oct 2014 13:16:43 -0000 1.109 @@ -1796,12 +1796,9 @@ return contentIDGenerator.getNextToolContentIDFor(tool); } - /** @see org.lamsfoundation.lams.authoring.service.IAuthoringService#copyToolContent(java.lang.Long) */ @Override - public String copyToolContent(Long toolContentID, String customCSV) throws IOException { - Long newContentID = lamsCoreToolService.notifyToolToCopyContent(toolContentID, customCSV); - FlashMessage flashMessage = new FlashMessage("copyToolContent", newContentID); - return flashMessage.serializeMessage(); + public Long copyToolContent(Long toolContentID, String customCSV) throws IOException { + return lamsCoreToolService.notifyToolToCopyContent(toolContentID, customCSV); } /** Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java,v diff -u -r1.44 -r1.45 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java 20 Jun 2014 17:35:08 -0000 1.44 +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java 23 Oct 2014 13:16:43 -0000 1.45 @@ -271,8 +271,7 @@ public Long insertToolContentID(Long toolID); /** - * Calls an appropriate tool to copy the content indicated by toolContentId. Returns a string representing the new - * tool content id in WDDX format. + * Calls an appropriate tool to copy the content indicated by toolContentId. Returns the new tool content id. * * The is called when the user copies and pastes a tool activity icon in authoring. It should only be called on a * ToolActivity - never a Gate or Grouping or Complex activity. @@ -281,9 +280,9 @@ * The toolContentID indicating the content to copy * @param customCSV * The customCSV if this is a tool adapter tool. - * @return String The new tool content id in WDDX Format + * @return Long the new content id */ - public String copyToolContent(Long toolContentID, String customCSV) throws IOException; + public Long copyToolContent(Long toolContentID, String customCSV) throws IOException; /** * Calls an appropriate tools to copy the content indicated by toolContentIds. Batch version of String Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java,v diff -u -r1.54 -r1.55 --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java 20 Oct 2014 09:27:07 -0000 1.54 +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java 23 Oct 2014 13:16:43 -0000 1.55 @@ -345,12 +345,33 @@ String customCSV = WebUtil.readStrParam(request, AttributeNames.PARAM_CUSTOM_CSV, true); try { long toolContentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID, false); - wddxPacket = authoringService.copyToolContent(toolContentID, customCSV); + Long newToolContentID = authoringService.copyToolContent(toolContentID, customCSV); + FlashMessage flashMessage = new FlashMessage("copyToolContent", newToolContentID); + wddxPacket = flashMessage.serializeMessage(); } catch (Exception e) { wddxPacket = handleException(e, "copyToolContent", authoringService, true).serializeMessage(); } return outputPacket(mapping, request, response, wddxPacket, "details"); + } + /** + * Copy some existing content. Used when the user copies an activity in authoring. Expects one parameters - + * toolContentId (the content to be copied) + */ + public ActionForward copyToolContentPlain(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + IAuthoringService authoringService = getAuthoringService(); + try { + String customCSV = WebUtil.readStrParam(request, AttributeNames.PARAM_CUSTOM_CSV, true); + long toolContentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID, false); + Long newToolContentID = authoringService.copyToolContent(toolContentID, customCSV); + response.setContentType("text/plain;charset=utf-8"); + response.getWriter().write(newToolContentID.toString()); + } catch (Exception e) { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + + return null; } /** @@ -430,10 +451,13 @@ HttpServletResponse response) throws IOException, ServletException, JSONException { IAuthoringService authoringService = getAuthoringService(); Long toolID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_ID); - // generate the next unique content ID for the tool - Long toolContentID = authoringService.insertToolContentID(toolID); + Long toolContentID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID, true); + if (toolContentID == null) { + // if the tool content ID was not provided, generate the next unique content ID for the tool + toolContentID = authoringService.insertToolContentID(toolID); + } + if (toolContentID != null) { - String contentFolderID = request.getParameter(AttributeNames.PARAM_CONTENT_FOLDER_ID); if (StringUtils.isBlank(contentFolderID)) { contentFolderID = FileUtil.generateUniqueContentFolderID(); Index: lams_central/web/includes/javascript/authoring/authoringActivity.js =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/javascript/authoring/authoringActivity.js,v diff -u -r1.41 -r1.42 --- lams_central/web/includes/javascript/authoring/authoringActivity.js 22 Oct 2014 10:53:36 -0000 1.41 +++ lams_central/web/includes/javascript/authoring/authoringActivity.js 23 Oct 2014 13:16:43 -0000 1.42 @@ -1039,11 +1039,15 @@ data : { 'method' : 'createToolContent', 'toolID' : activity.toolID, + // if toolContentID exists, a new content will not be created, only authorURL will be fetched + 'toolContentID' : activity.toolContentID, 'contentFolderID' : layout.ld.contentFolderID }, success : function(response) { activity.authorURL = response.authorURL; - activity.toolContentID = response.toolContentID; + if (!activity.toolContentID) { + activity.toolContentID = response.toolContentID; + } if (!layout.ld.contentFolderID) { // if LD did not have contentFolderID, it was just generated // so remember it Index: lams_central/web/includes/javascript/authoring/authoringMenu.js =================================================================== RCS file: /usr/local/cvsroot/lams_central/web/includes/javascript/authoring/authoringMenu.js,v diff -u -r1.34 -r1.35 --- lams_central/web/includes/javascript/authoring/authoringMenu.js 9 Jul 2014 09:37:57 -0000 1.34 +++ lams_central/web/includes/javascript/authoring/authoringMenu.js 23 Oct 2014 13:16:43 -0000 1.35 @@ -751,10 +751,28 @@ } }; + var toolContentID = null; + // tool content ID can be null if the activity had the default content, i.e. was not edited yet + if (activity.toolContentID) { + $.ajax({ + cache : false, + async : false, + url : LAMS_URL + "authoring/author.do", + data : { + 'method' : 'copyToolContentPlain', + 'toolContentID' : activity.toolContentID + }, + dataType : 'text', + success : function(response) { + toolContentID = response; + } + }); + } + // draw the new activity next to the existing one var x = activity.items.shape.getBBox().x + 10, y = activity.items.shape.getBBox().y + 10, - newActivity = new ActivityDefs.ToolActivity(null, null, null, activity.toolID, activity.learningLibraryID, + newActivity = new ActivityDefs.ToolActivity(null, null, toolContentID, activity.toolID, activity.learningLibraryID, null, x, y, title); layout.activities.push(newActivity);