mahesh
mahesh

Reputation: 597

show/hide action based on type of file

I am using alfresco 3.4 d. I have written document library action to validate the xml file. Now I want to show the action only if my file extension is .xml . Can somebody tell me the steps to achieve this. I was searching this from 2 days. still not found any solution.

Thanks

Upvotes: 2

Views: 845

Answers (1)

Jeff Potts
Jeff Potts

Reputation: 10538

There is not an easy way to do this in 3.4.d but it can be done if you are willing to dive into Alfresco's client-side components and then extend them with your own custom code. To do it I think you'll have to subclass the client-side JavaScript component that is responsible for building the action list. That is Alfresco.DocumentActions and it lives in /components/document-details/document-actions.js. If you use a client-side debugging tool, you should be able to find where the action list component iterates over the list of actions. You could extend this component such that when you come across your action, you'll look at the mimetype of the current object to decide whether or not to show the action. You'll have to look at the data that component knows about the current object to see whether or not the mimetype is in there. If it isn't, you'll have to extend the web scripts to expose that.

You may want to seriously consider whether or not it is worth the effort, though, because in 4.0 this is much easier. In 4, when actions are declared in the share form config, you can specify an evaluator that determines whether or not to show the action. There is already an evaluator based on mimetype called evaluator.doclib.action.isMimetype. So you could configure that to look for text/xml, then go into share-form-config-custom.xml to specify the evaluator in your action declaration.

So in 3.4, it is possible with a good deal of hacking and custom code. In 4.0, it is 100% config.

Upvotes: 4

Related Questions