Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java =================================================================== diff -u -rfd6ade152cf877cecaa63d3cb59d3bc53d60ca45 -r51c6e431368c11396aafddf0e3b37c92da2f5edc --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java (.../AuthoringAction.java) (revision fd6ade152cf877cecaa63d3cb59d3bc53d60ca45) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringAction.java (.../AuthoringAction.java) (revision 51c6e431368c11396aafddf0e3b37c92da2f5edc) @@ -29,6 +29,7 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.text.ParseException; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Vector; @@ -73,6 +74,7 @@ import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.Role; import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.usermanagement.exception.UserException; import org.lamsfoundation.lams.usermanagement.exception.WorkspaceFolderException; @@ -83,6 +85,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.web.WorkspaceAction; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -195,8 +198,27 @@ response.setContentType("application/json;charset=utf-8"); JSONObject responseJSON = new JSONObject(); Gson gson = new GsonBuilder().create(); - responseJSON.put("ld", new JSONObject(gson.toJson(learningDesignDTO))); + JSONObject ldJSON = new JSONObject(gson.toJson(learningDesignDTO)); + // get all parent folders of the LD + List folderPath = new LinkedList(); + WorkspaceFolder folder = (WorkspaceFolder) getUserManagementService().findById(WorkspaceFolder.class, + learningDesignDTO.getWorkspaceFolderID()); + while (folder != null) { + Integer folderID = folder.getWorkspaceFolderId(); + if (folderID.equals(WorkspaceAction.ROOT_ORG_FOLDER_ID)) { + // we reached the top folder, finish + folder = null; + } else { + folderPath.add(folderID); + folder = folder.getParentWorkspaceFolder(); + } + } + // we'll go from top to bottom + Collections.reverse(folderPath); + ldJSON.put("folderPath", new JSONArray(gson.toJson(folderPath))); + responseJSON.put("ld", ldJSON); + List accessList = getAuthoringService().updateLearningDesignAccessByUser(userId); accessList = accessList.subList(0, Math.min(accessList.size(), AuthoringAction.LEARNING_DESIGN_ACCESS_ENTRIES_LIMIT - 1)); Index: lams_central/web/includes/javascript/authoring/authoringGeneral.js =================================================================== diff -u -ree55f2ffca34d972bb176fb91d65d91cf2ed0e04 -r51c6e431368c11396aafddf0e3b37c92da2f5edc --- lams_central/web/includes/javascript/authoring/authoringGeneral.js (.../authoringGeneral.js) (revision ee55f2ffca34d972bb176fb91d65d91cf2ed0e04) +++ lams_central/web/includes/javascript/authoring/authoringGeneral.js (.../authoringGeneral.js) (revision 51c6e431368c11396aafddf0e3b37c92da2f5edc) @@ -743,11 +743,10 @@ }, 'close' : null, 'data' : { - 'prepareForOpen' : function(dialogTitle, learningDesignTitle, shownElementIDs, highlightFirstTreeChild){ - var tree = MenuLib.loadLearningDesignTree(); - if (highlightFirstTreeChild) { - tree.getRoot().children[0].highlight(); - } + 'prepareForOpen' : function(dialogTitle, learningDesignTitle, shownElementIDs, highlightFolder){ + // only Save As uses highlightFolder; otherwise the first folder in top level gets expanded and highlighted + layout.folderPathCurrent = highlightFolder && layout.ld.folderPath ? layout.ld.folderPath.slice() : []; + MenuLib.loadLearningDesignTree(); $('#ldStoreDialogNameContainer input', layout.ldStoreDialog).val(learningDesignTitle); $('.modal-title', layout.ldStoreDialog).text(dialogTitle); @@ -934,6 +933,9 @@ }); } + // expand the folder where existing LD resides, if applicable + MenuLib.highlightFolder(node); + // required by YUI callback(); }); @@ -1657,6 +1659,7 @@ layout.ld = { 'learningDesignID' : ld.learningDesignID, 'folderID' : ld.workspaceFolderID, + 'folderPath' : ld.folderPath, 'contentFolderID' : ld.contentFolderID, 'title' : ld.title, 'maxUIID' : 0, Index: lams_central/web/includes/javascript/authoring/authoringMenu.js =================================================================== diff -u -r922ee8d48aa70d56c24a802f8e68c6dde4bef8ae -r51c6e431368c11396aafddf0e3b37c92da2f5edc --- lams_central/web/includes/javascript/authoring/authoringMenu.js (.../authoringMenu.js) (revision 922ee8d48aa70d56c24a802f8e68c6dde4bef8ae) +++ lams_central/web/includes/javascript/authoring/authoringMenu.js (.../authoringMenu.js) (revision 51c6e431368c11396aafddf0e3b37c92da2f5edc) @@ -381,9 +381,44 @@ return result; }, - /** + * Highlights the folder where existing LD already resides + * or the user folder otherwise. + */ + highlightFolder : function(folder) { + // if there are no children or stop condition (no path) was reached + if (folder.children.length === 0 || layout.folderPathCurrent === null) { + return; + } + var chosenFolder = null; + // are there any steps left? + if (layout.folderPathCurrent.length > 0) { + // look for target folder in children + var folderID = layout.folderPathCurrent.shift(); + $.each(folder.children, function(index, child){ + if (folderID == child.data.folderID) { + chosenFolder = child; + return false; + } + }); + } + // if last piece of folder path was consumed, set stop condition + if (layout.folderPathCurrent.length === 0) { + layout.folderPathCurrent = null; + } + // no folder found or path was empty from the beginning + if (!chosenFolder) { + chosenFolder = folder.children[0]; + } + // if folder, highlight and expand + if (!chosenFolder.isLeaf) { + chosenFolder.expand(); + chosenFolder.highlight(); + } + }, + + /** * Opens a pop up for importing LD. Loads the imported LD to canvas. */ importLearningDesign : function(){ @@ -456,8 +491,8 @@ tree.buildTreeFromObject(MenuLib.getFolderContents()); tree.render(); - // expand the first (user) folder - tree.getRoot().children[0].expand(); + // expand the first folder or the one where existing LD resides + MenuLib.highlightFolder(tree.getRoot()); return tree; },