cancel
Showing results for 
Search instead for 
Did you mean: 

how to register custom js action

nancyaggarwal
Champ in-the-making
Champ in-the-making
Hi All

I am making a custom archive action and for that i have written a javascript action and make all the changes for the action but when i click on my action in document library it doesn't do anything. I think my js action is not registered properly.

Please anyone can help me with this as soon as possible.


Below is my js action.



(function() {
   YAHOO.Bubbling.fire("registerAction",{
      actionName: "onActionArchive",
      onActionArchive: function dlA__onActionArchive(record) {
         var fnSuccess = function dlA_onActionArchive_success(p_data) {
            this._inFlight = false;
            Alfresco.util.PopupManager.displayMessage({
               text: this.msg("message.archive.success", record.displayName)
            });
            this._updateDocList.call(this);
            
            
            
            var moved = toMoveRecord.getData();
            if (moved.node.isContainer)
               {
               YAHOO.Bubbling.fire("folderMoved",
               {
                  multiple: true,
                  nodeRef: moved.nodeRef,
                  destination: path
               });      
               }
            YAHOO.Bubbling.fire("metadataRefresh");
         };
         
         this.modules.actions.genricAction({
            success: {
               callback: {
                  fn: fnSuccess,
                  scope: this
               }
            },
            webscript: {
               name:"slingshot/archive?nodeRef={nodeRef}",
               stem: Alfresco.constants.PROXY_URI,
               method: Alfresco.util.Ajax.GET,
               params: {
                  nodeRef: record.nodeRef
               }
            },
            config: {
               }
            });
         }
      });
   })();
   





Thanks

Nancy
14 REPLIES 14

niketapatel
Star Contributor
Star Contributor
Hi Nancy, Can you please define your alfresco version as well I would suggest to post here your custom action configurations.

Please try to register your action as below


YAHOO.Bubbling.fire("registerAction", {
    actionName: "onActionArchive",
    fn: function custom_onActionArchive(asset)
    {
      //Your custom code
      
    }
});

Hi Niketa, Thanks for your reply.

My alfresco version is 4.2b and below is my custom action configuration.

In added my action configuration as:


<action id="document-archive" type="javascript" label="actions.document.archive">
            <param name="function">onActionArchive</param>
            <param name="successMessage">message.archive.success</param>
          <param name="failureMessage">message.archive.failure</param>
             <permissions>
               <permission allow="true">Delete</permission>
            </permissions>
            <evaluator negate="true">evaluator.doclib.action.isLocked</evaluator>
         </action>



In custom.properties file added its label and messages


actions.document.archive = Archive
message.archive.success  = '{0}' successfully archived
message.archive.failure = couldn't archive '{0}'




3. Added archive action webscript in Remote API/source/java/org/alfresco/repo/web/script/action/ArchiveWebscript.java

4. Webscript bean configuration in web-scripts-application-context.xml


<bean id="Archive" class="org.alfresco.repo.web.scripts.action.ArchiveWebscript" parent="webscript">
       <property name="nodeService" ref="NodeService"/>
        <property name="repository" ref="repositoryHelper"/>
        <property name="fileFolderService" ref="FileFolderService"/>
        <property name="permissionService" ref="PermissionService"/>
      </bean>



5. added file archive.get.desc.xml


<webscript>
<shortname>archive</shortname>
<description> Archive Action</description>
<url>/slingshot/archive?nodeRef={node}</url>
<format default="html"/>
<authenticatoin>user</authenticatoin>
</webscript>




But still my action is not showing any result.


Thanks
Nancy


niketapatel
Star Contributor
Star Contributor
Hi Nancy, sorry for late response. Did you define js dependency for your custom action - "onActionArchive". Js file where you are registering this action as below?

 
<config evaluator="string-compare" condition="DocLibCustom" replace="true">
   <dependencies>       
      <js src="/components/extension/documentlibrary/yourCustomFile.js" />
    </dependencies>
</config>

Hi Niketa,

Yes I have defined js dependency. I forgot to mention it earlier.



<config evaluator="string-compare" condition="DocLibCustom">
      <!–
         Custom Code dependencies.

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




Thanks
Nancy

niketapatel
Star Contributor
Star Contributor
Ok Nancy! Now I dont see anything is missing. You will have to debug your code.

I would suggest to use FF's firebug and confirm

1)Your custom js is getting loaded
2)When you click on custom action, your function is being called.

And again I want to confirm did you try to register your action as below


YAHOO.Bubbling.fire("registerAction", {
    actionName: "onActionArchive",
    fn: function custom_onActionArchive(asset)
    {
      //Your custom code

    }
});

Yes Niketa, I have already done with the debugging process using firebug. As a result my custom js is not getting loaded and my function also not being called when i click on it.

One more thing in line
fn: function <b>custom</b>_onActionArchive(asset)

should it be custom or dlA?


thanks
Nancy

niketapatel
Star Contributor
Star Contributor
custom or dla anything should work.

If your js is not getting loaded then first need to solve that. Please check , js file is at same location that you have mentioned in your configurations and also make sure you have both js and -min.js file.

Alfresco automatically doesn't create min.js file? If not then at what location i should put that file?


Thanks
Nancy

niketapatel
Star Contributor
Star Contributor
No, Alfresco doenst.

For all custom js file minification , you can include in your project build file.

Anyway for now, Please create min file at same location where your js resides

archive.js and archive-min.js should be at /components/documentlibrary

Clear your browser cache and try. Hope it works!