AnsweredAssumed Answered

Custom Javascript action is not executed

Question asked by qwertz on Jun 23, 2017
Latest reply on Jun 24, 2017 by qwertz

Hey guys!

I want that some javascript code is executed on the client side through a custom action. To gain some knowledge about this I went through the official documentation and tried the tutorial: Adding new actions to the Document Library | Alfresco Documentation. I am using the alfresco sdk 3 and need to generate a jar file instead of an AMP, so the file paths in the documentation are different from mine (at least as far as I know, I am new to all of this).

 

Where exactly do I need to put my custom javascript file? For now I have put it to src\main\resources\META-INF\resources\components\documentlibrary. In this directory I've also put a directory action/ where the icons for the custom share action are located. The problem is: I can see the custom action and even the icon in share but when I click on it, nothing happens. I assume I've used the wrong directory for the javascript file.

 

add-doclib-actions-extension-modules.xml:

<extension>
    <modules>
        <module>
            <id>Call Webscript</id>
            <version>1.0</version>
            <auto-deploy>true</auto-deploy>
            <configurations>
                <config evaluator="string-compare" condition="DocLibActions">
                    <actions>
                        <action id="alfresco.tutorials.doclib.action.callWebScript"
                                icon="callws"
                                type="javascript"
                                label="alfresco.tutorials.doclib.action.callWebScript.label">

                            <param name="function">onActionCallWebScript</param>
                            <param name="successMessage">alfresco.tutorials.doclib.action.callWebScript.msg.success</param>
                            <param name="failureMessage">alfresco.tutorials.doclib.action.callWebScript.msg.failure</param>
                        </action>
                              <action id="alfresco.tutorials.doclib.action.showCustomMessage"
                                icon="showmsg"
                                type="javascript"
                                label="alfresco.tutorials.doclib.action.showCustomMessage.label">

                            <param name="function">onShowCustomMessage</param>
                              </action>
                    </actions>
                         <actionGroups>
                              <actionGroup id="document-browse">
                                    <action index="400" id="alfresco.tutorials.doclib.action.callWebScript" />
                                    <action index="401" id="alfresco.tutorials.doclib.action.showCustomMessage" />
                              </actionGroup>
                              <actionGroup id="document-details">
                                   <action index="400" id="alfresco.tutorials.doclib.action.callWebScript" />
                                   <action index="401" id="alfresco.tutorials.doclib.action.showCustomMessage" />
                              </actionGroup>
                         </actionGroups>
                </config>
            </configurations>
        </module>
    </modules>
</extension>

 

custom-doclib-actions.js:

YAHOO.Bubbling.fire("registerAction",
     {
          actionName: "onShowCustomMessage",
          fn: function org_alfresco_training_onShowCustomMessage(file) {
               Alfresco.util.PopupManager.displayMessage(
                    {
                         text: this.msg("alfresco.tutorials.doclib.action.showCustomMessage.text",
                              file.displayName, Alfresco.constants.USERNAME)
                    });
          }
     });
    
    YAHOO.Bubbling.fire("registerAction",
        {
            actionName: "onActionCallWebScript",
            fn: function org_alfresco_training_onActionCallWebScript(file) {
                    console.log("js called");
                this.modules.actions.genericAction(
                    {

                        success: {
                            callback: {
                                fn: function org_alfresco_training_onActionCallWebScriptSuccess(response) {
                                    Alfresco.util.PopupManager.displayPrompt(
                                        {
                                            title: this.msg("alfresco.tutorials.doclib.action.callWebScript.msg.success"),
                                            text: JSON.stringify(response.json),
                                            buttons: [
                                                {
                                                    text: this.msg("button.ok"),
                                                    handler: function org_alfresco_training_onActionCallWebScriptSuccess_success_ok() {
                                                        this.destroy();
                                                    },
                                                    isDefault: true
                                                },
                                                {
                                                    text: this.msg("button.cancel"),
                                                    handler: function org_alfresco_training_onActionCallWebScriptSuccess_cancel() {
                                                        this.destroy();
                                                    }
                                                }]
                                        });

                                },
                                scope: this
                            }
                        },
                        failure: {
                            message: this.msg("alfresco.tutorials.doclib.action.callWebScript.msg.failure",
                                file.displayName, Alfresco.constants.USERNAME)
                        },
                        webscript: {
                            name: "sample/fileinfo?nodeRef={nodeRef}",
                            stem: Alfresco.constants.PROXY_URI,
                            method: Alfresco.util.Ajax.GET,
                            params: {
                                nodeRef: file.nodeRef
                            }
                        },
                        config: {}
                    });
            }
        });

 

I've tried enclosing custom-doclib-actions.js with

(function () { /* code from above */  })();

but that didn't work either (I've read in some post that removing this enclosure solves the problem).

 

I would appreciate it a lot if someone had any tips for me.

Outcomes