Index: lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java =================================================================== diff -u -r01fa7b9ff8bf04b7dbe1056d1e9e8fdd1a113410 -re15d2e51298e68fff7ee35cd7d85e34faf1951a2 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision 01fa7b9ff8bf04b7dbe1056d1e9e8fdd1a113410) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/AuthoringService.java (.../AuthoringService.java) (revision e15d2e51298e68fff7ee35cd7d85e34faf1951a2) @@ -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 =================================================================== diff -u -rfe06d16b234341fc965d9b40494e6a2fb4cb9438 -re15d2e51298e68fff7ee35cd7d85e34faf1951a2 --- lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java (.../IAuthoringService.java) (revision fe06d16b234341fc965d9b40494e6a2fb4cb9438) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/service/IAuthoringService.java (.../IAuthoringService.java) (revision e15d2e51298e68fff7ee35cd7d85e34faf1951a2) @@ -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 =================================================================== diff -u -r9234cb75efd86c137c56366bc5b0e2f93aad05ea -re15d2e51298e68fff7ee35cd7d85e34faf1951a2 --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java (.../AuthoringAction.java) (revision 9234cb75efd86c137c56366bc5b0e2f93aad05ea) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java (.../AuthoringAction.java) (revision e15d2e51298e68fff7ee35cd7d85e34faf1951a2) @@ -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 =================================================================== diff -u -r0a66b57371500a885e7d2ad77907b4bee705f46b -re15d2e51298e68fff7ee35cd7d85e34faf1951a2 --- lams_central/web/includes/javascript/authoring/authoringActivity.js (.../authoringActivity.js) (revision 0a66b57371500a885e7d2ad77907b4bee705f46b) +++ lams_central/web/includes/javascript/authoring/authoringActivity.js (.../authoringActivity.js) (revision e15d2e51298e68fff7ee35cd7d85e34faf1951a2) @@ -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 =================================================================== diff -u -rb5f9c6df8c12ecc62e27fab71c6b3e8d8c3d499b -re15d2e51298e68fff7ee35cd7d85e34faf1951a2 --- lams_central/web/includes/javascript/authoring/authoringMenu.js (.../authoringMenu.js) (revision b5f9c6df8c12ecc62e27fab71c6b3e8d8c3d499b) +++ lams_central/web/includes/javascript/authoring/authoringMenu.js (.../authoringMenu.js) (revision e15d2e51298e68fff7ee35cd7d85e34faf1951a2) @@ -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);