-
Define and configure the Show-Custom-Message action
This action is just executing some JavaScript code that shows a message, it will not call a repository action or a repository web script. It just demonstrates how to invoke some JavaScript code on the client side without involving the repository and the server side.
Open the add-doclib-actions-extension-modules.xml Surf Extension module file that we have used so far in this tutorial, it is located in the aio/aio-share-jar/src/main/resources/alfresco/web-extension/site-data/extensions directory.
Then define the Show-Custom-Message DocLib action as follows:
<extension> <modules> <module> <id>Add Document Library Actions (Send-as-Email, Call WS, Show Msg, Go to Google)</id> <version>1.0</version> <auto-deploy>true</auto-deploy> <configurations> <config evaluator="string-compare" condition="DocLibActions"> <actions> ... <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> </config> </configurations> </module> </modules> </extension>
This action is also of type javascript in the same way the previous actions have been.This action will call a custom JavaScript function called onShowCustomMessage. The showmsg-16.png icon for this action should already be available if you implemented the Send-As-Email action above.
-
Add labels and messages for the Show-Custom-Message to the i18n resource file.
Open up the aio-share-jar.properties file locate din the aio/aio-share-jar/src/main/resources/alfresco/web-extension/messages directory. Then add the following properties to it:
alfresco.tutorials.doclib.action.showCustomMessage.text=Showing custom message for {0} and {1} alfresco.tutorials.doclib.action.showCustomMessage.label=Show Message
-
Define where in the user interface the Show-Custom-Message action should be displayed.
This is done in the add-doclib-actions-extension-modules.xml file in the section called actionGroups::
<extension> <modules> <module> <id>Add Document Library Actions (Send-as-Email, Call WS, Show Msg, Go to Google)</id> <version>1.0</version> <auto-deploy>true</auto-deploy> <configurations> <config evaluator="string-compare" condition="DocLibActions"> <actions> ... </actions> <actionGroups> <actionGroup id="document-browse"> ... <action index="402" id="alfresco.tutorials.doclib.action.showCustomMessage" /> </actionGroup> <actionGroup id="document-details"> ... <action index="402" id="alfresco.tutorials.doclib.action.showCustomMessage" /> </actionGroup> </actionGroups> </config> </configurations> </module> </modules> </extension>
The Show-Custom-Message action will be displayed in the same views as the other actions that we have implemented. We give it an index of 402 so it is displayed just after the Call-Web-Script action.
-
Implement the custom JavaScript function that is invoked by the Show-Custom-Message
action.
This JavaScript function can go into the same file as the Call-Web-Script function, open the custom-doclib-actions.js file located in the aio/aio-share-jar/src/main/resources/META-INF/resources/aio-share-jar/components/documentlibrary directory and add the code as follows:
(function () { YAHOO.Bubbling.fire("registerAction", { actionName: "onShowCustomMessage", fn: functionorg_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", ... }); })();
The only thing we do in this action code is to display a message with the help of the Alfresco.util.PopupManager.displayMessage function.
-
The implementation of the Show-Custom-Message DocLib action is now complete. This is
probably the smallest DocLib action backed by JavaScript code that you might
come across. To try it out build and start the application server as follows:
/all-in-one$ ./run.sh build_start
-
Now, log in to Share (http://localhost:8080/share). You will see the new
Show-Custom-Message action in the Browse view when hovering over a file and
clicking More… in the pop-up menu:
Note that the Send-As-Email action is not displayed in the pop-up menu as it has already been invoked, see the indicator. Invoking the “Show Message” action will display the following message temporary: