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.
Solved! Go to Solution.
Have you even included your custom file as a dependency so that it is loaded at runtime? The documentation you referenced is missing that important detail, though it is contained in another section of the same dev extension chapter. As you can see from "Adding new metadata templates" you need to add a section for "CustomDoclib" to load your custom JavaScript file.
Have you even included your custom file as a dependency so that it is loaded at runtime? The documentation you referenced is missing that important detail, though it is contained in another section of the same dev extension chapter. As you can see from "Adding new metadata templates" you need to add a section for "CustomDoclib" to load your custom JavaScript file.
That was the solution, thanks a lot!
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.