Ajax pickers now support navigating up parent hierarchies from any start location

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7753 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-01-04 14:47:02 +00:00
parent 1b466e3f12
commit f5738eee4d
2 changed files with 56 additions and 21 deletions

View File

@@ -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,8 +221,19 @@ public class PickerBean
List<ChildAssociationRef> childRefs;
NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
NodeRef parentRef = null;
Map params = fc.getExternalContext().getRequestParameterMap();
String strChildRef = (String)params.get(PARAM_CHILD);
if (strChildRef != null && strChildRef.length() != 0)
{
// TODO: check permission on the parent
NodeRef childRef = new NodeRef(strChildRef);
parentRef = this.nodeService.getPrimaryParent(childRef).getParentRef();
}
else
{
// TODO: check permission on the parent
String strParentRef = (String)params.get(PARAM_PARENT);
if (strParentRef == null || strParentRef.length() == 0)
{
@@ -229,13 +244,15 @@ public class PickerBean
{
parentRef = new NodeRef(strParentRef);
}
}
List<FileInfo> 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,8 +319,19 @@ public class PickerBean
List<ChildAssociationRef> childRefs;
NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
NodeRef parentRef = null;
Map params = fc.getExternalContext().getRequestParameterMap();
String strChildRef = (String)params.get(PARAM_CHILD);
if (strChildRef != null && strChildRef.length() != 0)
{
// TODO: check permission on the parent
NodeRef childRef = new NodeRef(strChildRef);
parentRef = this.nodeService.getPrimaryParent(childRef).getParentRef();
}
else
{
// TODO: check permission on the parent
String strParentRef = (String)params.get(PARAM_PARENT);
if (strParentRef == null || strParentRef.length() == 0)
{
@@ -311,6 +342,7 @@ public class PickerBean
{
parentRef = new NodeRef(strParentRef);
}
}
// look for mimetype restriction parameter
Set<String> mimetypes = null;
@@ -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))
{

View File

@@ -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');
@@ -486,6 +488,7 @@ 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 : "") +
(child != null ? ("&child=" + child) : "") +
(this.requestAttributes!=null ? ("&" + this.requestAttributes) : ""),
{
method: 'get',