From 1adffd1e4ed75f38c2d1d85267e472ca6653e16f Mon Sep 17 00:00:00 2001 From: Mike Hatfield Date: Tue, 14 Jul 2009 15:42:38 +0000 Subject: [PATCH] Pop-up with opportunity to edit metadata if Declare as Record action fails. ScriptNode.parentAssocs() API. Multi-parent indicator in DocLib (placeholder icon). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15181 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/jscript/ScriptNode.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/source/java/org/alfresco/repo/jscript/ScriptNode.java b/source/java/org/alfresco/repo/jscript/ScriptNode.java index c4e9fa02ee..5ca59a5867 100644 --- a/source/java/org/alfresco/repo/jscript/ScriptNode.java +++ b/source/java/org/alfresco/repo/jscript/ScriptNode.java @@ -172,7 +172,9 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol protected TemplateImageResolver imageResolver = null; protected ScriptNode parent = null; private ChildAssociationRef primaryParentAssoc = null; + private ScriptableQNameMap parentAssocs = null; // NOTE: see the reset() method when adding new cached members! + // ------------------------------------------------------------------------------ @@ -581,7 +583,55 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol { return getChildAssocs(); } + + /** + * Return the parent associations to this Node. As a Map of assoc name to a JavaScript array of Nodes. + * The Map returned implements the Scriptable interface to allow access to the assoc arrays via JavaScript + * associative array access. This means associations of this node can be access thus: + * node.parentAssocs["contains"][0] + * + * @return parent associations as a Map of assoc name to a JavaScript array of Nodes. + */ + @SuppressWarnings("unchecked") + public Map getParentAssocs() + { + if (this.parentAssocs == null) + { + // this Map implements the Scriptable interface for native JS syntax property access + this.parentAssocs = new ScriptableQNameMap(this); + + // get the list of child assoc nodes for each association type + List refs = this.nodeService.getParentAssocs(nodeRef); + for (ChildAssociationRef ref : refs) + { + String qname = ref.getTypeQName().toString(); + List nodes = (List)this.parentAssocs.get(qname); + if (nodes == null) + { + // first access of the list for this qname + nodes = new ArrayList(4); + this.parentAssocs.put(ref.getTypeQName().toString(), nodes); + } + nodes.add(newInstance(ref.getParentRef(), this.services, this.scope)); + } + + // convert each Node list into a JavaScript array object + for (String qname : this.parentAssocs.keySet()) + { + List nodes = (List)this.parentAssocs.get(qname); + Object[] objs = nodes.toArray(new Object[nodes.size()]); + this.parentAssocs.put(qname, Context.getCurrentContext().newArray(this.scope, objs)); + } + } + + return this.parentAssocs; + } + public Map getParentAssociations() + { + return getParentAssocs(); + } + /** * Return all the properties known about this node. The Map returned implements the Scriptable interface to * allow access to the properties via JavaScript associative array access. This means properties of a node can @@ -2530,6 +2580,7 @@ public class ScriptNode implements Serializable, Scopeable, NamespacePrefixResol this.parent = null; this.primaryParentAssoc = null; this.activeWorkflows = null; + this.parentAssocs = null; } /**