cancel
Showing results for 
Search instead for 
Did you mean: 

Restricting a menu item to a specific Space

vasuki
Champ in-the-making
Champ in-the-making
Hi, I have added a new menu item (using web-client-config-custom.xml) that will trigger a Javascript. Now, I would like to limit the Spaces that this menu item shows up…
I assume I need to use the "evaluator" and "condition" attributes (config tag) to do this, but I cannot find any documentation on how these are used. Should I be using the "string-compare" evaluator, and if so, how do I specify that I want this action restricted to a single space (and all documents and subspaces within it)?
31 REPLIES 31

rivarola
Champ on-the-rise
Champ on-the-rise
Hello,

You can use either use the evaluator/condition couple in the config element (see http://wiki.alfresco.com/wiki/Web_Client_Configuration_Guide) or the evaluator tag inside the action element (see http://wiki.alfresco.com/wiki/Externalised_Client_Actions#Action_Definition_Config_Elements) depending on how complex your visibility rule is.

vasuki
Champ in-the-making
Champ in-the-making
Hi rivarola,
Yes, I have seen those documents, but there is not much information on what evaluators are available (other than string-compare), and how to use them. For example, how exactly does string-compare work? Can it be used to restrict the config to a specific path? If yes, how can it be done?
Thanks!

gavinc
Champ in-the-making
Champ in-the-making
There are 2 types of evaluators, one for config and one for actions.

The evaluator for config determines whether the whole config block should be used depending on the object used when a config lookup is done. There is a small amount of information on this here: http://wiki.alfresco.com/wiki/Config_Service

For your scenario though it sounds like an action evaluator is more suited, documentation on these can be found here: http://wiki.alfresco.com/wiki/Externalised_Client_Actions#Action_Definition_Config_Elements. For some real examples of action evaluators look in the 'org.alfresco.web.action.evaluator' package.

elenaor
Champ in-the-making
Champ in-the-making
Hi, I would like to restrict an action to a specific space too. Did you finally achieve your purpose?
Thanks in advance. Elena

vasuki
Champ in-the-making
Champ in-the-making
Hi Elena,

No, I was not able to achieve my goal using the Alfresco UI or XML customization out-of-the-box. As Gavin wrote, I needed to write a custom ActionEvaluator (Java class) that gets executed to check whether to display the menu item or not. Writing that Java class was easy enough, and once I put the .jar in the /WEB-INF/lib folder, I was able to use my custom ActionEvaluator without any problems. Let me know if you need more help…

Thanks,
Vasuki.

elenaor
Champ in-the-making
Champ in-the-making
Hi, vasuki.
I'm going to try it. I hope not to have so much problems.
Thanks for your reply

elenaor
Champ in-the-making
Champ in-the-making
Hi vasuki,

actually, what I  can't understand is what Java class do I have to use in order to get the space name. If I had the space name, I would be able of comparing this name with my current space name.

I would like that "Firmar" action appears only in Firmado space:
I have tried this CompareSpace.java:

package org.alfresco.web.action.evaluator;

import org.alfresco.web.action.ActionEvaluator;
import org.alfresco.web.bean.repository.Node;

public class CompareSpace implements ActionEvaluator{

   public boolean evaluate(Node node) {
      return (node.getName().equals("Firmado"));
   }
   
}

but it doesn't show anything.
Thanks in advance, Elena.

rivarola
Champ on-the-rise
Champ on-the-rise
Hello,

Your "evaluate" method is OK if the action is attached to the space itself (i.e. in the Create menu for instance) but if it is attached to a document in the space (like the "Edit" or "Show document details" actions), the node passed to the evaluate method is the document and not the parent space.
In this case you can test either the name of the primary parent of the node (first option) or the name of the current space using the navigation bean (second option) :
  public boolean evaluate(Node node) {
    FacesContext fc = FacesContext.getCurrentInstance();
    ServiceRegistry services = Repository.getServiceRegistry(fc);
    NavigationBean navigator = (NavigationBean) FacesHelper.getManagedBean(fc, NavigationBean.BEAN_NAME);

    NodeRef space = navigator.getCurrentNode().getNodeRef();
    // check the current space name is "Firmado"
    return "Firmado".equalsIgnoreCase((String) services.getNodeService().getProperty(space, ContentModel.PROP_NAME));
  }

vasuki
Champ in-the-making
Champ in-the-making
Hi Elena,

Sounds like rivarola knows a lot more about this stuff than I do. Here is the code I used since I wanted to restrict the action to a space and all of its subspaces:


public class MySpaceEvaluator implements ActionEvaluator
{
    public boolean evaluate(Node node)
    {
        return (node.getPath().contains("MySpace"));
    }
}