Index: lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java =================================================================== diff -u -rf6359207eef0f47bdd53b51c0b73aea8ec236b64 -r679fe3220201c33cc6396ef0b3c0592f1da293f6 --- lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java (.../HomeAction.java) (revision f6359207eef0f47bdd53b51c0b73aea8ec236b64) +++ lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java (.../HomeAction.java) (revision 679fe3220201c33cc6396ef0b3c0592f1da293f6) @@ -348,7 +348,7 @@ UserDTO userDTO = getUser(); // get all user accessible folders and LD descriptions as JSON - JSONObject learningDesigns = getDeepFolderContents(userDTO.getUserID(), null); + JSONObject learningDesigns = getFolderContents(null, userDTO.getUserID()); req.setAttribute("folderContents", learningDesigns.toString()); Integer organisationID = new Integer(WebUtil.readIntParam(req, "organisationID")); @@ -401,6 +401,20 @@ return mapping.findForward("addLesson"); } + /** + * Gets subfolder contents in Add Lesson screen. + */ + public ActionForward getFolderContents(ActionMapping mapping, ActionForm form, HttpServletRequest req, + HttpServletResponse res) throws UserAccessDeniedException, JSONException, IOException, + RepositoryCheckedException { + Integer folderID = new Integer(WebUtil.readIntParam(req, "folderID")); + JSONObject responseJSON = getFolderContents(folderID, getUser().getUserID()); + + res.setContentType("application/json;charset=utf-8"); + res.getWriter().print(responseJSON.toString()); + return null; + } + public ActionForward createLearningDesignThumbnail(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws JDOMException, IOException, TranscoderException { Long learningDesignId = WebUtil.readLongParam(req, CentralConstants.PARAM_LEARNING_DESIGN_ID); @@ -420,7 +434,7 @@ } @SuppressWarnings("unchecked") - private JSONObject getDeepFolderContents(Integer userID, Integer folderID) throws JSONException, IOException, + private JSONObject getFolderContents(Integer folderID, Integer userID) throws JSONException, IOException, UserAccessDeniedException, RepositoryCheckedException { JSONObject result = new JSONObject(); Vector folderContents = null; @@ -453,7 +467,7 @@ if (folderContents.size() == 1) { FolderContentDTO folder = folderContents.firstElement(); if (folder.getResourceID().equals(WorkspaceAction.ROOT_ORG_FOLDER_ID)) { - return getDeepFolderContents(userID, WorkspaceAction.ROOT_ORG_FOLDER_ID); + return getFolderContents(WorkspaceAction.ROOT_ORG_FOLDER_ID, userID); } } } else { @@ -463,19 +477,20 @@ Collections.sort(folderContents, HomeAction.LD_NAME_COMPARATOR); } - // recursively check folders, building a tree + // fill JSON object with folders and LDs for (FolderContentDTO folderContent : folderContents) { String contentType = folderContent.getResourceType(); if (FolderContentDTO.FOLDER.equals(contentType)) { - JSONObject subfolder = getDeepFolderContents(userID, folderContent.getResourceID().intValue()); - subfolder.put("name", folderContent.getName()); - subfolder.put("isRunSequencesFolder", + JSONObject subfolderJSON = new JSONObject(); + subfolderJSON.put("name", folderContent.getName()); + subfolderJSON.put("isRunSequencesFolder", WorkspaceFolder.RUN_SEQUENCES.equals(folderContent.getResourceTypeID().intValue())); - result.append("folders", subfolder); + subfolderJSON.put("folderID", folderContent.getResourceID().intValue()); + result.append("folders", subfolderJSON); } else if (FolderContentDTO.DESIGN.equals(contentType)) { JSONObject learningDesignJSON = new JSONObject(); - learningDesignJSON.put("learningDesignId", folderContent.getResourceID()); learningDesignJSON.put("name", folderContent.getName()); + learningDesignJSON.put("learningDesignId", folderContent.getResourceID()); result.append("learningDesigns", learningDesignJSON); } else { if (HomeAction.log.isDebugEnabled()) { Index: lams_central/web/includes/javascript/addLesson.js =================================================================== diff -u -r8a6945700087134d2cebe7582998199fbad7e029 -r679fe3220201c33cc6396ef0b3c0592f1da293f6 --- lams_central/web/includes/javascript/addLesson.js (.../addLesson.js) (revision 8a6945700087134d2cebe7582998199fbad7e029) +++ lams_central/web/includes/javascript/addLesson.js (.../addLesson.js) (revision 679fe3220201c33cc6396ef0b3c0592f1da293f6) @@ -3,7 +3,10 @@ var lastSelectedUsers = {}; var sortOrderAscending = {}; var submitInProgress = false; - + +/** + * Sets up widgets in the main tab. + */ function initLessonTab(){ $('#ldScreenshotAuthor').load(function(){ // hide "loading" animation @@ -16,11 +19,35 @@ : CANVAS_RESIZE_OPTION_NONE); }); - // generate LD tree; folderContents is declared in newLesson.jsp - var treeNodes = parseFolderTreeNode(folderContents); + // generate LD initial tree; folderContents is declared in newLesson.jsp + var treeNodes = parseFolderContents(folderContents); // there should be no focus, just highlight YAHOO.widget.TreeView.FOCUS_CLASS_NAME = null; tree = new YAHOO.widget.TreeView('learningDesignTree', treeNodes); + tree.setDynamicLoad(function(node, callback){ + // load subfolder contents + $.ajax({ + url : LAMS_URL + 'home.do', + data : { + 'method' : 'getFolderContents', + 'folderID' : node.data.folderID + }, + cache : false, + async: false, + dataType : 'json', + success : function(result) { + var childNodeData = parseFolderContents(result); + $.each(childNodeData, function(){ + new YAHOO.widget.TextNode(this, node); + }); + } + } + ); + + // required by YUI + callback(); + }); + tree.singleNodeHighlight = true; tree.subscribe('clickEvent', function(event){ if (!event.node.data.learningDesignId){ @@ -43,23 +70,7 @@ tree.subscribe('clickEvent',tree.onEventToggleHighlight); tree.render(); - // if empty folders were empty in the start, they would have been displayed as leafs - // instead, there is a dummy element in the start which is removed - // when user opens the folder - var emptyFolderNodes = tree.getNodesBy(function(node){ - var firstNode = node.children[0]; - return firstNode && firstNode.data.isDummy; - }); - - if (emptyFolderNodes) { - $.each(emptyFolderNodes, function(){ - this.setDynamicLoad(function(node, callback){ - tree.removeChildren(node); - callback(); - }); - }); - } - + // expand the first (user) folder tree.getRoot().children[0].expand(); } @@ -71,6 +82,7 @@ fillUserContainer(users.selectedMonitors, 'selected-monitors'); fillUserContainer(users.unselectedMonitors, 'unselected-monitors'); + // allow dragging of user divs $('.draggableUser').each(function(){ $(this).draggable({ 'scope' : getDraggableScope($(this).parents('.userContainer').attr('id')), 'appendTo' : 'body', @@ -126,6 +138,7 @@ }); }); + // allow putting dragged users into container divs $('.userContainer').each(function(){ var containerId = $(this).attr('id'); @@ -232,6 +245,7 @@ function addLesson(){ + // prevent double clicking of Add button if (submitInProgress) { return; } @@ -312,6 +326,9 @@ } +/** + * Chooses whether LD thumbnail will be shrinked or full size. + */ function toggleCanvasResize(mode) { var toggleCanvasResizeLink = $('#toggleCanvasResizeLink'); switch (mode) { @@ -338,34 +355,30 @@ } -function parseFolderTreeNode(nodeJSON) { +/** + * Parses response in JSON format into readable for YUI. + */ +function parseFolderContents(nodeJSON) { var result = []; - - if (!nodeJSON.folders && !nodeJSON.learningDesigns) { - // add dummy node, otherwise empty folder is displayed as a leaf - result.push({'type' : 'text', - 'label' : '(dummy)', - 'isDummy' : true - }); - } else { - if (nodeJSON.folders) { - $.each(nodeJSON.folders, function(){ - result.push({'type' : 'text', - 'label' : this.isRunSequencesFolder ? - LABEL_RUN_SEQUENCES_FOLDER : this.name, - 'children' : parseFolderTreeNode(this) - }); - }); - } - if (nodeJSON.learningDesigns) { - $.each(nodeJSON.learningDesigns, function(){ - result.push({'type' : 'text', - 'label' : this.name, - 'learningDesignId' : this.learningDesignId - }); - }); - } + + if (nodeJSON.folders) { + $.each(nodeJSON.folders, function(){ + result.push({'type' : 'text', + 'label' : this.isRunSequencesFolder ? + LABEL_RUN_SEQUENCES_FOLDER : this.name, + 'folderID' : this.folderID + }); + }); } + if (nodeJSON.learningDesigns) { + $.each(nodeJSON.learningDesigns, function(){ + result.push({'type' : 'text', + 'label' : this.name, + 'isLeaf' : true, + 'learningDesignId' : this.learningDesignId + }); + }); + } return result; } @@ -376,13 +389,15 @@ if (users) { // create user DIVs $.each(users, function(index, userJSON) { - $('#' + containerId).append($('
').attr({ - 'userId' : userJSON.userID - }) - .addClass('draggableUser') - .text(userJSON.firstName + ' ' + userJSON.lastName - + ' (' + userJSON.login + ')') - ); + $('#' + containerId).append( + $('
').attr({ + 'userId' : userJSON.userID + }) + .addClass('draggableUser') + .text(userJSON.firstName + ' ' + userJSON.lastName + + ' (' + userJSON.login + ')' + ) + ); }); sortUsers('sort-' + containerId);