diff --git a/source/java/org/alfresco/web/bean/ajax/PickerBean.java b/source/java/org/alfresco/web/bean/ajax/PickerBean.java index 8a905d6244..5a83eb30f8 100644 --- a/source/java/org/alfresco/web/bean/ajax/PickerBean.java +++ b/source/java/org/alfresco/web/bean/ajax/PickerBean.java @@ -73,6 +73,7 @@ public class PickerBean private static final String ID_ID = "id"; private static final String ID_PARENT = "parent"; private static final String PARAM_PARENT = "parent"; + private static final String PARAM_CHILD = "child"; private static final String PARAM_MIMETYPES = "mimetypes"; private static final String FOLDER_IMAGE_PREFIX = "/images/icons/"; @@ -200,7 +201,10 @@ public class PickerBean /** * Return the JSON objects representing a list of cm:folder nodes. * - * IN: "parent" - null for Company Home child folders, else the parent noderef of the folders to retrieve. + * IN: "parent" - noderef (can be null) of the parent to retrieve the child folder nodes for. Null is valid + * and specifies the Company Home root as the parent. + * IN: "child" - non-null value of the child noderef to retrieve the siblings for - the parent value returned + * in the JSON response will be the parent of the specified child. * * The 16x16 pixel folder icon path is output as the 'icon' property for each child folder. */ @@ -217,25 +221,38 @@ public class PickerBean List childRefs; NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc)); + NodeRef parentRef = null; Map params = fc.getExternalContext().getRequestParameterMap(); - String strParentRef = (String)params.get(PARAM_PARENT); - if (strParentRef == null || strParentRef.length() == 0) + String strChildRef = (String)params.get(PARAM_CHILD); + if (strChildRef != null && strChildRef.length() != 0) { - parentRef = companyHomeRef; - strParentRef = parentRef.toString(); + // TODO: check permission on the parent + NodeRef childRef = new NodeRef(strChildRef); + parentRef = this.nodeService.getPrimaryParent(childRef).getParentRef(); } else { - parentRef = new NodeRef(strParentRef); + // TODO: check permission on the parent + String strParentRef = (String)params.get(PARAM_PARENT); + if (strParentRef == null || strParentRef.length() == 0) + { + parentRef = companyHomeRef; + strParentRef = parentRef.toString(); + } + else + { + parentRef = new NodeRef(strParentRef); + } } + List folders = this.fileFolderService.listFolders(parentRef); JSONWriter out = new JSONWriter(fc.getResponseWriter()); out.startObject(); out.startValue(ID_PARENT); out.startObject(); - out.writeValue(ID_ID, strParentRef); + out.writeValue(ID_ID, parentRef.toString()); out.writeValue(ID_NAME, Repository.getNameForNode(this.internalNodeService, parentRef)); if (parentRef.equals(companyHomeRef)) { @@ -274,7 +291,10 @@ public class PickerBean /** * Return the JSON objects representing a list of cm:folder and cm:content nodes. * - * IN: "parent" - null for Company Home child nodes, else the parent noderef of the folders to retrieve. + * IN: "parent" - noderef (can be null) of the parent to retrieve the child nodes for. Null is valid + * and specifies the Company Home root as the parent. + * IN: "child" - non-null value of the child noderef to retrieve the siblings for - the parent value returned + * in the JSON response will be the parent of the specified child. * IN: "mimetypes" (optional) - if set, a comma separated list of mimetypes to restrict the file list. * * It is assumed that only files should be selectable, all cm:folder nodes will be marked with the @@ -299,17 +319,29 @@ public class PickerBean List childRefs; NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc)); + NodeRef parentRef = null; Map params = fc.getExternalContext().getRequestParameterMap(); - String strParentRef = (String)params.get(PARAM_PARENT); - if (strParentRef == null || strParentRef.length() == 0) + String strChildRef = (String)params.get(PARAM_CHILD); + if (strChildRef != null && strChildRef.length() != 0) { - parentRef = companyHomeRef; - strParentRef = parentRef.toString(); + // TODO: check permission on the parent + NodeRef childRef = new NodeRef(strChildRef); + parentRef = this.nodeService.getPrimaryParent(childRef).getParentRef(); } else { - parentRef = new NodeRef(strParentRef); + // TODO: check permission on the parent + String strParentRef = (String)params.get(PARAM_PARENT); + if (strParentRef == null || strParentRef.length() == 0) + { + parentRef = companyHomeRef; + strParentRef = parentRef.toString(); + } + else + { + parentRef = new NodeRef(strParentRef); + } } // look for mimetype restriction parameter @@ -331,7 +363,7 @@ public class PickerBean out.startObject(); out.startValue(ID_PARENT); out.startObject(); - out.writeValue(ID_ID, strParentRef); + out.writeValue(ID_ID, parentRef.toString()); out.writeValue(ID_NAME, Repository.getNameForNode(this.internalNodeService, parentRef)); if (parentRef.equals(companyHomeRef)) { diff --git a/source/web/scripts/ajax/picker.js b/source/web/scripts/ajax/picker.js index 261cf9c5f5..f503ad5c35 100644 --- a/source/web/scripts/ajax/picker.js +++ b/source/web/scripts/ajax/picker.js @@ -125,7 +125,7 @@ var AlfPicker = new Class( }, this); // first ajax request for the children of the start item - this.getChildData(this.startId, this.populateChildren); + this.getNodeData(this.startId, null, this.populateChildren); }, childClicked: function(index) @@ -135,20 +135,22 @@ var AlfPicker = new Class( // add an extra property to record the scroll position for this item item.scrollpos = $(this.id + "-results-list").scrollTop; this.stack.push(item); // ready for the breadcrumb redraw after the child data request - this.getChildData(item.id, this.populateChildren) + this.getNodeData(item.id, null, this.populateChildren) }, upClicked: function() { this.hidePanels(); - // pop the parent off - peek for the grandparent + // pop the parent off var parent = this.stack.pop(); + // peek for the grandparent - we may not have a grandparent (depending on start location) - so use the + // getNodeData(parent, child, ...) call to pass in the child rather than the parent and let server calculate it var grandParent = null; if (this.stack.length != 0) { grandParent = this.stack[this.stack.length-1]; } - this.getChildData(grandParent != null ? grandParent.id : null, this.populateChildren, parent.scrollpos); + this.getNodeData(grandParent != null ? grandParent.id : null, grandParent == null ? parent.id : null, this.populateChildren, parent.scrollpos); }, addItem: function(index) @@ -273,7 +275,7 @@ var AlfPicker = new Class( { this.stack.splice(index + 1, removeCount); } - this.getChildData(item.id, this.populateChildren); + this.getNodeData(item.id, null, this.populateChildren); }, breadcrumbToggle: function() @@ -475,7 +477,7 @@ var AlfPicker = new Class( } }, - getChildData: function(parent, callback, scrollpos) + getNodeData: function(parent, child, callback, scrollpos) { // show ajax wait panel $(this.id + '-ajax-wait').setStyle('display', 'block'); @@ -485,7 +487,8 @@ var AlfPicker = new Class( // execute ajax service call to retrieve list of child nodes as JSON response new Ajax(getContextPath() + "/ajax/invoke/" + this.service + - "?parent=" + (parent!=null ? parent : "") + + "?parent=" + (parent != null ? parent : "") + + (child != null ? ("&child=" + child) : "") + (this.requestAttributes!=null ? ("&" + this.requestAttributes) : ""), { method: 'get',