cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Share 4.0 Client Side Js

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi,

I  have create custom action to be added in the Document Library Browse view . Below is the code.
<config evaluator="string-compare" condition="DocLibActions" >
           <actions>
        <action id="content" type="javascript" label="content" >
            <param name="function" >onActionContentDetail</param>
         </action>
      </actions>
           <actionGroups >
             <actionGroup id="folder-browse" >
             <action index="100" id="content" />
            </actionGroup>
            </actionGroups>
        </config>
Now I want to call client side JS. As per Alfresco 4.0 ,  there is  option to  definecustom Java script  through configuration.
The DocLibCustom config section is where dependencies on custom client-side assets can be defined.
<config evaluator="string-compare" condition="DocLibCustom" replace="true">
      <!–
         Custom Code dependencies.
         Note: files specified in the "src" attribute resolve relative to the /share/res/ servlet context.
         –>
         <dependencies>
                 <js src="/custom-documentlibrary-actions.js" />
         </dependencies>
      </config>

I have created this js file directly under <install-app>/tomcat/webapps/share folder .
On click of custom action , the Java script method  is not called.

Can anyone please help in this.

Thanks,
6 REPLIES 6

mikeh
Star Contributor
Star Contributor
I don't think anybody's going to be able to help you without posting at least some of your code.

Also, what have you tried already? For example, a simple "alert" when you register the action and another when the action is called..?

Thanks,
Mike

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi Mike ,

Please find below code snippets:

Changes made in share-config-custom.xml—-

<config evaluator="string-compare" condition="DocLibActions" >
           <actions>
        <action id="content" type="javascript" label="content" >
            <param name="function" >onActionContentDetail</param>
         </action>
      </actions>
           <actionGroups >
             <actionGroup id="folder-browse" >
             <action index="100" id="content" />
            </actionGroup>
           </actionGroups>
        </config>
  
    <config evaluator="string-compare" condition="DocLibCustom" replace="true">
      <!–
         Custom Code dependencies.

         Note: files specified in the "src" attribute resolve relative to the /share/res/ servlet context.
         –>
         <dependencies>
                <js src="/custom-documentlibrary-actions.js" />
         </dependencies>
        </config>


Below is the code for  Client side Javascript file located at <install-app>/tomcat/webapps/share

/**
* DocumentList "Backup" action
*
* @namespace Alfresco
* @class Alfresco.DocumentList
*/
(function()
{

/**
       * Get detail information of content
       *
       * @method onActionContentDetail
       * @param asset {object} represents the file to be actioned
       */
      Alfresco.doclib.Actions.prototype.onActionContentDetail = function dlA_onActionContentDetail(asset)
      {
         //Get asset-content nodeRef
         var nodeRef = asset.nodeRef,
         actionUrl = " ";
         //Create a new instance of dialog
         this.modules.contentDetail = new Alfresco.module.SimpleDialog(this.id +
                               "-contentDetail").setOptions(
         {
            width: "30em",
            //Define share webscripts for module pop-up
            templateUrl: Alfresco.constants.URL_SERVICECONTEXT +
                      "modules/content-detail?contentRef=" + nodeRef,
            actionUrl: actionUrl,
         });
         //Display module
         this.modules.contentDetail.show();           
      };
})();

mikeh
Star Contributor
Star Contributor

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi Mike,

You have written very nice blog.
I have followed similar steps what you have defined.
Can you please  have a look at my code and let me know if anything is missing.

Same code works when I  include  same javascript in   documentlist.get.head.ftl and  actions-common.get.head.ftl

Thanks,

mikeh
Star Contributor
Star Contributor
Sorry, I linked you to the wrong thing. You need to use the "registerAction" API:

YAHOO.Bubbling.fire("registerAction",
{
   actionName: "onActionContentDetail",
   fn: onActionContentDetail
});

http://docs.alfresco.com/4.0/topic/com.alfresco.enterprise.doc/concepts/doclib-client-side-template-...

Thanks,
Mike

amitabhandari1
Champ in-the-making
Champ in-the-making
Thanks Mike!!!
It worked..