cancel
Showing results for 
Search instead for 
Did you mean: 

Create custom DocLib action

itzamna
Confirmed Champ
Confirmed Champ
Hi,

I'm trying to create a custom DocLib action on Share that opens a new window with an URL that needs to be created by a webscript before (based on the node-ref).
I followed this example: http://ecmstuff.blogspot.de/2012/04/adding-document-library-actions-in.html
It works fine so far and it seems to be exactly what I'm looking for. But the example sends only an email and return with a message. What I need is, that the webscript should return a result that includes already the full URL. And based on this URL a new window has to be opened.
It fails on my missing knowledge in creating the custom javascript with the Yahoo stuff… 😞

The DocLib (share-config-custom.xml) that creates the new action is defined as:
   <config evaluator="string-compare" condition="DocLibActions">        <actions>            <action id="myCompany.doclib.action.openExternal"                    icon="myCompanyIcon"                    type="javascript"                    label="actions.myCompany.openExternal">                <param name="function">onActionOpenExternal</param>                <param name="successMessage">message.openExternal.success</param>                <param name="failureMessage">message.openExternal.failure</param>                <evaluator>myCompany.doclib.action.openExternal</evaluator>            </action>        </actions>        <actionGroups>            <actionGroup id="document-browse">                <action index="400" id="myCompany.doclib.action.openExternal" />            </actionGroup>            <actionGroup id="document-details">                <action index="400" id="myCompany.doclib.action.openExternal" />            </actionGroup>        </actionGroups>    </config>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


And this is the custom javascript that creates the current result and invokes the webscript:
  (function() {    YAHOO.Bubbling.fire("registerAction",    {        actionName: "onActionopenExternal",        fn: function myCompany_onActionOpenExternalProgram(file) {            this.modules.actions.genericAction(            {                success:                {                    //window.open('<URL based on the webscript response below>') ???                    message: this.msg("message.openExternal.success", file.displayName, Alfresco.constants.USERNAME)                },                failure:                {                    message: this.msg("message.openExternal.failure", file.displayName, Alfresco.constants.USERNAME)                },                webscript:                {                    name: "myCompany/openExternal?nodeRef={nodeRef}&userName={userName}",                    stem: Alfresco.constants.PROXY_URI,                    method: Alfresco.util.Ajax.GET,                    params:                    {                        nodeRef: file.nodeRef,                        userName: Alfresco.constants.USERNAME                    }                },                config:                {                }            });        }    });})();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

As I mentioned, it works fine. My Java backed webscript on the repository tier will be invoked and I get the "message.openExternal.success" after clicking my new action in the Share GUI.

Maybe anyone of you would be so kind to give me some tips on how I can solve this issue? Is this an adequate approach at all? Or are the other / better approaches? If not, how can I get the result of the webscript section and open a new popup with the result value?

Many thanks! 🙂
3 REPLIES 3

rjohnson
Star Contributor
Star Contributor
If you give your success option a callback rather than a message you should be able to navigate in that. So

               success:               {                  callback:                  {                     fn: function DL_oAEO_success(data)                     {                       // Navigate here                     }                   }                }‍‍‍‍‍‍‍‍‍‍‍‍

soldiertt
Champ in-the-making
Champ in-the-making
Hi,

I'm facing a similar issue, i would like to run a back-end action but then need to call a custom javascript function on success.
Looking at :
http://sharextras.org/jsdoc/share/community-head/symbols/Alfresco.doclib.Actions.html#onActionSimple...

I see i can use this declaration in share-config-custom.xml, right ?
 <action id="document-workitem" type="javascript" label="actions.document.addtoworkitem" icon="toworkitem">       <param name="function">onActionSimpleRepoAction</param>       <param name="action">imaging.toworkitem</param>       <param name="success">goToWorkItem</param>       <param name="failureMessage">message.addtoworkitem.failure</param>       <evaluator negate="true">evaluator.doclib.metadata.hasAspectWorkItem</evaluator>  </action>‍‍‍‍‍‍‍‍‍


But it displays the failure message when i run the action.
When i use a successMessage instead of success callback it works.
So, where the callback javascript function need to declared or register somewhere ? For now i just declare it in js file.

Thank you.

Thank you Bob!

I'm now able to execute with the callback option my own javascript function:

…this.modules.actions.genericAction({    success:    {       callback :       {           scope: this,           fn: function(object)           {               //var result = eval("(" +object.serverResponse.responseText+")");               window.open(object.serverResponse.responseText, "_new");           }        },        event:        {            name: "metadataRefresh"        }    },    failure:    {        message: this.msg("message.openExternal.failure", file.displayName, Alfresco.constants.USERNAME)    },    webscript:    {        …‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍