cancel
Showing results for 
Search instead for 
Did you mean: 

custom view for all spaces in sub tree

itayh
Champ in-the-making
Champ in-the-making
Hi,

I want to use the audit view as custom view for all my spaces in certain sub tree. Can I do it in one time or do I need to go space by space and add to every space custom view?

Thx,
  Itay
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
This is a perfect case for the JavaScript API. As the admin user, you can execute a script that walked all spaces (from a known start location or ALL spaces) and set the custom view to each space. A custom view is just an aspect (cm:templatable) and a d:noderef property on that aspect (cm:template) that points to the template to be displayed for the custom view. So if you get the noderef to your template (from it's details page) then you can write a script that does this.
http://wiki.alfresco.com/wiki/JavaScript_API

Thanks,

Kevin

itayh
Champ in-the-making
Champ in-the-making
Thank you kevin,

One more question.
There all changes in the repository all the times. We are adding and deleting spaces all the time.

So After  running the java script when I add new spaces I will need to run it again, correct?

Thanks in advance,
  Itay

kevinr
Star Contributor
Star Contributor
If you set up a rule, you will not need to to run it again. Simply create a Rule on the root Company Home space (or User Homes or whatever) and make that Rule "inherit" (to apply to all subspaces) and make it fire when new cm:folder types are created. Then the script for the rule can add the custom view to just the new space as it is created.

Thanks,

Kevin

alrice
Champ in-the-making
Champ in-the-making
Thank you this thread was helpful for me in solving the same requirement.  However, one oddity (bug?) I ran across and was able to workaround with the javascript debugger, is that when a rule 's script is firing and being applied to sub-spaces, the space object is always set to the toplevel space. the document object is set to whatever the current space is. this is different than if you run the script by going into the sub-space and run action / execute a script. maybe that's a feature and it's probably documented somewhere, but it was a surprise to me.

here is some code that I am using. hopefully it will help 


    var tTemplatePath = "Data Dictionary/path/to…/custom-view.ftl";
    var tTemplateNode = companyhome.childByNamePath( tTemplatePath );
    var tProps = new Array(1);
    tProps["cm:template"] = tTemplateNode.nodeRef;
    document.addAspect("cm:templatable", tProps);