Javascript Return

cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript Return

resplin
Intermediate
0 0 1,739

Obsolete Pages{{Obsolete}}

The official documentation is at: http://docs.alfresco.com



Web Client CustomizationJavaScript_API


Introduction


This page aims to expand a little bit on what is described in the script section of Externalised_Client_Actions#Action_Definition_Config_Elements.  What this particularly addresses is that when a script is executed using the command servlet, such as the javascript actions you expose in the Alfresco Explorer UI, the return is often of the following:

org.mozilla.javascript.Undefined@1607a8a

What this really amounts to is the Javascript engine supplying a default return, which is essentially an http response back to the browser.  This is obviously not what an end user would expect after selecting an action on a document.  They would expect to be taken back to where they originally executed the action from i.e. space browse, space details, document details, etc.  Since the response is html, we can use this to our advantage.


A Basic Sample


// my javascript code to execute...
var goBack = '<script>history.back();</script>';
goBack;

This shows the easiest way to achieve the the effect of returning the user back to their original location.  However, there are some limitations to this:


  1. If there are any changes to the node you're referencing such as changes to properties, they will not be visible as this simply relies on the browser's cache to redirect the user back. It effectively is the same as hitting the 'Back' button in the browser.
  2. Depending on the last browser action taken, it may try to repost data, which could potentially have some undesirable effects, too.

Using External Access Servlet


The remaining sample shows various ways to return to different views of the Alfresco Explorer for spaces and documents utilizing the URL_Addressability#ExternalAccessServlet.  The ExternalAccessServlet takes URLs of the form

 /alfresco/navigate/<outcome>[<workspace>/<store>/<nodeId>]

where outcome can be several appropriate strings.  In the below examples, we use browse, showDocDetails, and showSpaceDetails, which are the most common redirections you would need.


Return to Space Browse


var result = '<script>location.href = '/alfresco/navigate/browse/workspace/SpacesStore/' + document.parent.id + '';</script>';
result;

This will return you to the space indicated in the argument.  You should be able to see the document you acted upon within this space, as well as all pre-existing documents.


Return to Doc Details


var result = '<script>location.href = '/alfresco/navigate/showDocDetails/workspace/SpacesStore/' + document.id + '';</script>';
result;

This will return you to the details view of the document so that if any changes were made to properties, they would be viewed immediately in the UI.  Additionally, you can perform other actions now on the document.


Return to Space Details


var result = '<script>location.href = '/alfresco/navigate/showSpaceDetails/workspace/SpacesStore/' + document.parent.id + '';</script>';
result;

This will return you to the details view of the space for the document.