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_ID = "id";
private static final String ID_PARENT = "parent"; private static final String ID_PARENT = "parent";
private static final String PARAM_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 PARAM_MIMETYPES = "mimetypes";
private static final String FOLDER_IMAGE_PREFIX = "/images/icons/"; 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. * 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. * The 16x16 pixel folder icon path is output as the 'icon' property for each child folder.
*/ */
@@ -217,25 +221,38 @@ public class PickerBean
List<ChildAssociationRef> childRefs; List<ChildAssociationRef> childRefs;
NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc)); NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
NodeRef parentRef = null; NodeRef parentRef = null;
Map params = fc.getExternalContext().getRequestParameterMap(); Map params = fc.getExternalContext().getRequestParameterMap();
String strParentRef = (String)params.get(PARAM_PARENT); String strChildRef = (String)params.get(PARAM_CHILD);
if (strParentRef == null || strParentRef.length() == 0) if (strChildRef != null && strChildRef.length() != 0)
{ {
parentRef = companyHomeRef; // TODO: check permission on the parent
strParentRef = parentRef.toString(); NodeRef childRef = new NodeRef(strChildRef);
parentRef = this.nodeService.getPrimaryParent(childRef).getParentRef();
} }
else 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<FileInfo> folders = this.fileFolderService.listFolders(parentRef); List<FileInfo> folders = this.fileFolderService.listFolders(parentRef);
JSONWriter out = new JSONWriter(fc.getResponseWriter()); JSONWriter out = new JSONWriter(fc.getResponseWriter());
out.startObject(); out.startObject();
out.startValue(ID_PARENT); out.startValue(ID_PARENT);
out.startObject(); out.startObject();
out.writeValue(ID_ID, strParentRef); out.writeValue(ID_ID, parentRef.toString());
out.writeValue(ID_NAME, Repository.getNameForNode(this.internalNodeService, parentRef)); out.writeValue(ID_NAME, Repository.getNameForNode(this.internalNodeService, parentRef));
if (parentRef.equals(companyHomeRef)) 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. * 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. * 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 * 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<ChildAssociationRef> childRefs; List<ChildAssociationRef> childRefs;
NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc)); NodeRef companyHomeRef = new NodeRef(Repository.getStoreRef(), Application.getCompanyRootId(fc));
NodeRef parentRef = null; NodeRef parentRef = null;
Map params = fc.getExternalContext().getRequestParameterMap(); Map params = fc.getExternalContext().getRequestParameterMap();
String strParentRef = (String)params.get(PARAM_PARENT); String strChildRef = (String)params.get(PARAM_CHILD);
if (strParentRef == null || strParentRef.length() == 0) if (strChildRef != null && strChildRef.length() != 0)
{ {
parentRef = companyHomeRef; // TODO: check permission on the parent
strParentRef = parentRef.toString(); NodeRef childRef = new NodeRef(strChildRef);
parentRef = this.nodeService.getPrimaryParent(childRef).getParentRef();
} }
else 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 // look for mimetype restriction parameter
@@ -331,7 +363,7 @@ public class PickerBean
out.startObject(); out.startObject();
out.startValue(ID_PARENT); out.startValue(ID_PARENT);
out.startObject(); out.startObject();
out.writeValue(ID_ID, strParentRef); out.writeValue(ID_ID, parentRef.toString());
out.writeValue(ID_NAME, Repository.getNameForNode(this.internalNodeService, parentRef)); out.writeValue(ID_NAME, Repository.getNameForNode(this.internalNodeService, parentRef));
if (parentRef.equals(companyHomeRef)) if (parentRef.equals(companyHomeRef))
{ {

View File

@@ -125,7 +125,7 @@ var AlfPicker = new Class(
}, this); }, this);
// first ajax request for the children of the start item // 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) childClicked: function(index)
@@ -135,20 +135,22 @@ var AlfPicker = new Class(
// add an extra property to record the scroll position for this item // add an extra property to record the scroll position for this item
item.scrollpos = $(this.id + "-results-list").scrollTop; item.scrollpos = $(this.id + "-results-list").scrollTop;
this.stack.push(item); // ready for the breadcrumb redraw after the child data request 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() upClicked: function()
{ {
this.hidePanels(); this.hidePanels();
// pop the parent off - peek for the grandparent // pop the parent off
var parent = this.stack.pop(); 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; var grandParent = null;
if (this.stack.length != 0) if (this.stack.length != 0)
{ {
grandParent = this.stack[this.stack.length-1]; 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) addItem: function(index)
@@ -273,7 +275,7 @@ var AlfPicker = new Class(
{ {
this.stack.splice(index + 1, removeCount); this.stack.splice(index + 1, removeCount);
} }
this.getChildData(item.id, this.populateChildren); this.getNodeData(item.id, null, this.populateChildren);
}, },
breadcrumbToggle: function() 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 // show ajax wait panel
$(this.id + '-ajax-wait').setStyle('display', 'block'); $(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 // execute ajax service call to retrieve list of child nodes as JSON response
new Ajax(getContextPath() + "/ajax/invoke/" + this.service + new Ajax(getContextPath() + "/ajax/invoke/" + this.service +
"?parent=" + (parent!=null ? parent : "") + "?parent=" + (parent != null ? parent : "") +
(child != null ? ("&child=" + child) : "") +
(this.requestAttributes!=null ? ("&" + this.requestAttributes) : ""), (this.requestAttributes!=null ? ("&" + this.requestAttributes) : ""),
{ {
method: 'get', method: 'get',