diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.desc.xml new file mode 100644 index 0000000000..bca118e4b1 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.desc.xml @@ -0,0 +1,8 @@ + + treenode + Document List Component - treenode data webscript + /slingshot/doclib/treenode?nodeRef={nodeRef?}&path={path?} + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.html.ftl b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.html.ftl new file mode 100644 index 0000000000..00df6880d2 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.html.ftl @@ -0,0 +1 @@ +<#include "treenode.get.json.ftl"> \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.js new file mode 100644 index 0000000000..929df86a3d --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.js @@ -0,0 +1,65 @@ +/** + * Document List Component: treenode + * + * Inputs: + * mandatory: nodeRef = parent space nodeRef + * OR: path = parent space relative path from companyhome + * + * Outputs: + * treenode - object containing list of child folder nodes for a TreeView widget + */ +model.treenode = getTreenode(args["nodeRef"], args["path"]); + +/* Create collection of folders in the given space */ +function getTreenode(nodeRef, path) +{ + var items = new Array(); + + /* nodeRef input */ + var parentSpace = null; + if ((nodeRef !== null) && (nodeRef != "")) + { + parentSpace = search.findNode(nodeRef); + } + else if ((path !== null) && path != "") + { + parentSpace = companyhome.childByNamePath(path); + } + if (parentSpace === null) + { + // return jsonError("Parent space nodeRef not supplied"); + parentSpace = companyhome; + } + + for each(item in parentSpace.children) + { + if (item.isContainer) + { + items.push(item); + } + } + + items.sort(sortByName); + + return ({ + "items": items + }); +} + + +/* Format and return error object */ +function jsonError(errorString) +{ + var obj = + { + "error": errorString + }; + + return obj; +} + +/* Sort the results by case-insensitive name */ +function sortByName(a, b) +{ + return (b.name.toLowerCase() > a.name.toLowerCase() ? -1 : 1); +} \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.json.ftl new file mode 100644 index 0000000000..fef41e6201 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/treenode.get.json.ftl @@ -0,0 +1,25 @@ +{ + "treenode": + { +<#if treenode.error?exists> + "error": "${treenodes.error}" +<#else> + "items": + [ + <#list treenode.items as t> + <#assign hasChildren = false> + <#list t.children as c> + <#if c.isContainer><#assign hasChildren = true><#break> + + { + "nodeRef": "${t.nodeRef}", + "name": "${t.name}", + "description": "${t.properties.description!""}", + "hasChildren": ${hasChildren?string} + } + <#if t_has_next>, + + ] + + } +} \ No newline at end of file