cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Document Library Action

alarocca
Champ in-the-making
Champ in-the-making
Hello, following instructions from the wiki (http://wiki.alfresco.com/wiki/Custom_Document_Library_Action), I was able just to make my own action visible.

I have two questions about:
  • Is there any mechanism like the evaluator within Alfresco Explorer that allow me to choise when make this action visible or not? For instance, I don't want the action visible if a specific aspect is already applied to the content.

  • Finally, I would like to know how to execute some operations once I click on my custom action menu item. I wish to apply an aspect to the content and then automatically show the "Edit Metadata" form.
Thanks,
Alessandro
7 REPLIES 7

patil
Champ on-the-rise
Champ on-the-rise
Hi,
You can do this.
Based on the registered evaluator return value, you can decide whether to show or not the link.

In the action you can open the dialog and pass the noderef of the node through actionContext.

<config>
      <actions>
  <!– Update document –>
         <action id="customupdate_doc">
            <permissions>
               <permission allow="true">Write</permission>
            </permissions>
            <evaluator>org.alfresco.web.action.evaluator.UpdateDocEvaluator</evaluator>
            <label-id>update</label-id>
            <image>/images/icons/update.gif</image>
            <action-listener>#{CheckinCheckoutDialog.setupContentAction}</action-listener>
            <action>dialog:updateFile</action>
            <params>
              <param name="id">#{actionContext.id}</param>
            </params>
         </action>

   <!– Actions Menu for a document in the Browse screen –>
         <action-group id="document_browse_menu">
            <action idref="preview_doc" />
            <action idref="update_doc" />
  <action idref="customupdate_doc" />
           
            <!– Remove this action if you don't want old style Checkin/Checkout to appear at all –>
            <action idref="checkout_doc" />
           
            <action idref="approve_doc" />
            <action idref="reject_doc" />
            <action idref="cut_node" />
            <action idref="copy_node" />
         </action-group>

   </actions>
   </config>

From the actioncontext get the nodeid and perform the tasks required.

Thanks,
Patil
Cignex Technologies
Bangalore

alarocca
Champ in-the-making
Champ in-the-making
Thanks Patil, I guess your configuration is related to Alfresco Explorer (ie, Web Client). I used that a lot of time for my custom action on that GUI. Now I need to do something like that in Alfresco Share.

pitzalis
Champ in-the-making
Champ in-the-making
Hi Alessandro,
here the instruction for a new custom action in Share repository document details form (Alfresco Community 3.4.c):

1) Copy the files:
    repo-document-actions.get.config.xml
    repo-document-actions.get.head.ftl
    repo-document-actions.get.properties
from:
    \tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\document-details\
to shared area (were you will add the customizations):
    \tomcat\shared\classes\alfresco\web-extension\site-webscripts\org\alfresco\components\document-details\

2) Add your custom action in repo-document-actions.get.config.xml:

<actionSet id="document">
   …..
   <action type="action-link" id="onActionMyCustomAction" permission="myCustomPermission" label="actions.document.myCustomAction" />
</actionSet>

3) Add the css reference to repo-document-actions.get.head.ftl:

<@link rel="stylesheet" type="text/css" href="${page.url.context}/components/documentlibrary/myCustomAction.css" />

4) Add custom action related labels and messages in repo-document-actions.get.properties:

actions.document.actions.document.myCustomAction=My custom action label
message.myCustomAction.success='{0}' successfully executed myCustomAction
message.myCustomAction.failure=Couldn't execute myCustomAction for '{0}'
….
….

5) Create the css file \tomcat\webapps\share\components\documentlibrary\myCustomAction.css:

.doclist .onActionMyCustomAction a
{
   background-image: url(images/myCustomAction.png);
}

6) Add the custom action icon:
\tomcat\webapps\share\components\documentlibrary\images\myCustomAction.png

7) Add your custom evaluator (permission) in \webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\slingshot\documentlibrary\evaluator.lib.js


// Get relevant actions set
switch (nodeType)
{
   …..
   case "document":
    ……..

   /* myCustomAction action evaluator */
   if ( <here your condition> )
   {
      permissions["myCustomPermission"] = true;
   }
   break;
}

8 ) Add the client side javascript code for manage the custom action, in file \tomcat\webapps\share\components\documentlibrary\action.js (in this exmple I open a popup window for action confirmation and then I call a custom web-script):

      
/**
* MyCustomAction.
*
* @method onActionMyCustomAction
* @param asset {object} Object literal representing the file to be actioned upon
*/
onActionMyCustomAction: function dlA_onActionMyCustomAction(asset)
{
   var displayName = asset.displayName;
   var nodeRef = new Alfresco.util.NodeRef(asset.nodeRef);
   var me = this;

   Alfresco.util.PopupManager.displayPrompt(
   {
      title: this.msg("message.confirm.myCustomAction.title"),
      text: this.msg("message.confirm.myCustomAction", asset.displayName),
      buttons: [
      {
         text: this.msg("button.myCustomAction"),
         handler: function dlA_onActionMyCustomAction_create()
         {
            this.destroy();
            me._onActionMyCustomActionConfirm.call(me, asset);
         }
      },
      {
         text: this.msg("button.cancel"),
         handler: function dlA_onActionMyCustomAction_cancel()
         {
            this.destroy();
         },
         isDefault: true
      }]
   });      
},


/**
* MyCustomAction confirmed.
*
* @method _onActionMyCustomActionConfirm
* @param asset {object} Object literal representing the file or folder to be actioned
* @private
*/
_onActionMyCustomActionConfirm: function dlA__onActionMyCustomActionConfirm(asset)
{
   var displayName = asset.displayName,
   nodeRef = new Alfresco.util.NodeRef(asset.nodeRef);

   this.modules.actions.genericAction(
   {
      success:
      {
         event:
         {
             name: "metadataRefresh"
         },
         message: this.msg("message.myCustomAction.success", displayName)
      },
      failure:
      {
         message: this.msg("message.myCustomAction.failure", displayName)
      },
       webscript:
      {
         method: Alfresco.util.Ajax.POST,
         name: "mycustomactionwebscript/node/{nodeRef}",
         params:
         {
            nodeRef: nodeRef.uri
         }
      }
   });    
},


Bye,
GP

alarocca
Champ in-the-making
Champ in-the-making
Thanks a lot pitzalis, I will try soon.

Have a nice weekend,
Alessandro

alarocca
Champ in-the-making
Champ in-the-making
Thanks again pitzalis, it worked with the following modifications to your instructions:

[3] css reference (href) is "${page.url.context}/res/components/documentlibrary/myCustomAction.css"

[8] javascript code added to \tomcat\weabpps\share\components\document-details\document-actions.js. Finally, I generated and replaced the compressed variant of this javascript (document-actions-min.js).

Best regards,
Alessandro

csabee
Champ in-the-making
Champ in-the-making
8 ) Add the client side javascript code for manage the custom action, in file \tomcat\webapps\share\components\documentlibrary\action.js (in this exmple I open a popup window for action confirmation and then I call a custom web-script):

Hi,

I have been trying to make my custom action working. Your quote helped me a lot, but I'm using alfresco community 3.4.d, and modifying action.js didn't work for me.
Instead of it, I had to modify documentlibrary-actions.js (and regenerate the -min version), that can be found at \tomcat\webapps\share\js

Thank you!

(Also do you have any idea how to make the event handler independent from the original alfresco files? I have wrote down my problems at the following topic: http://forums.alfresco.com/en/viewtopic.php?f=48&t=36719 )

mikeh
Star Contributor
Star Contributor