Exposed frontend JavaScript API
OpenKM UI is developed with GWT framework what helps on calling Java methods from JavaScript.
The UI frontend Java methods are public exposed as JavaScript functions an can be used in frontend context.
More information about GWT JSNI at GWT Dev Codings Basics.
General functions
The methods that do not start with "js" will no longer be supported in the near future, we encourage you to move to js equivalent ones.
Function | Return | Description | Deprecated |
---|---|---|---|
jsI18n(String) |
void |
Retrieve a frontend translation. The parameter is the translation key. |
no |
jsOpenUserTaskInstance(String) |
void |
Open dashboard workflow to view with user tas. The parameter is the taskinstance id. |
no |
jsOpenPath(String, String) |
void |
Open some node in OpenKM UI. First parameter is folder path. Second parameter is document path. When document path parameter is empty will be opened a folder. |
no |
jsOpenPathByUuid(String) |
void |
Open some node in OpenKM UI. The parameter is a valid node uuid ( document, folder, mail or record ). |
no |
jsRefreshFolder() |
void |
Refresh UI ( like toolbar refresh button action ). |
no |
jsWizard(String, String) |
void |
Execute wizard. First parameter is a document path. Second parameter is a JSON to String serialization of GWTFileUploadResponse bean. The wizard usually should be called after a uploading a document. |
no |
i18n(String) |
void |
Retrieve a frontend translation. The parameter is the translation key. |
yes |
openPath(String, String) |
void |
Open some node in OpenKM UI. First parameter is folder path. Second parameter is document path. When document path parameter is empty will be opened a folder. |
yes |
openPathByUuid(String) |
void |
Open some node in OpenKM UI. The parameter is a valid node uuid ( document, folder, mail or record ). |
yes |
refreshFolder() |
void |
Refresh UI ( like toolbar refresh button action ). |
yes |
jsCancelCheckout() |
void |
Cancel document checkout of the selected document in UI. |
no |
jsGetActualPath() |
String |
Return the path of selected tree node in navigator. |
no |
jsGetActualNodePath() |
String |
Return the path of the selected node in navigator or file brower. |
no |
jsGetActualNodeUUID() |
String |
Return the uuid of the selected node in navigator or file brower. |
no |
jsGetUser() |
String |
Return GWTUser object serialized to JSON. |
no |
jsDownloadByUuid(String) |
void |
Download a document. The parameter is the uuid of the document. |
no |
jsChangeSelectedTab(int) |
void |
Change workspace tab. Allowed values:
|
no |
Cryptography functions
Function | Return | Description | Deprecated |
---|---|---|---|
cryptographyLoaded() |
void |
Hide UI popup status that indicates cryptography applet is not yet loaded. |
no |
digitalSignatureEnded() |
void |
Indicate the digital signature has finished. |
no |
digitalSignatureCanceled() |
void |
Cancelling digital signature has been canceled. |
no |
startDigitalSignature() |
void |
Start digital signature. |
no |
Applet functions
Function | Return | Description | Deprecated |
---|---|---|---|
destroyScannerApplet() |
void |
Cleaned the scanner applet. |
no |
destroyUploaderApplet() |
void |
Clean the bulk upload applet. |
no |
HTML Editor functions
Function | Return | Description | Deprecated |
---|---|---|---|
jsSearchDocumentHTMLEditorPopup() |
void |
Show find document popup. |
no |
jsSearchFolderHTMLEditorPopup() |
void |
Show find folder popup. |
no |
Wiki functions
Function | Return | Description | Deprecated |
---|---|---|---|
jsOpenWikiPage(String) |
void |
Open a wiki page The parameter is the unique wiki title. |
no |
openWikiPage(String) |
void |
Open a wiki page The parameter is the unique wiki title. |
yes |
How to expose Java methods to JavaScript
Static method sample
Expose static method named i18n(String property) to JavaScript as "jsI18n(String)" function:
/**
* initJavaScriptApi
*/
native void initJavaScriptApi() /*-{
$wnd.jsI18n = function(s) {
return @com.openkm.frontend.client.Main::i18n(Ljava/lang/String;)(s);
};
}-*/;
Non Static method sample
Expose non static method "executeRefresh()" from class Toolbar.java to JavaScript as jsRefreshFolder function:
In the Toolbar Java create a method named "initJavaScriptApi()":
public native void initJavaScriptApi(ToolBar toolBar) /*-{
$wnd.jsRefreshFolder = function() {
toolBar.@com.openkm.frontend.client.widget.toolbar.ToolBar::executeRefresh()();
return true;
}
}-*/;
After creating a new Toolbar object call the "initJavaScriptApi()" method:
ToolBar toolBar = new ToolBar();
mainPanel.topPanel.toolBar.initJavaScriptApi(mainPanel.topPanel.toolBar);
Complete information about GWT JSNI at GWT Dev Codings Basics.
Integration sample
Create "sample.jsp" file:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<html>
<head>
<title>Sample test</title>
<script>
function refresh() {
alert('executing refresh');
parent.parent.refreshFolder();
alert('done');
}
</script>
</head>
<body>
<a href="#" onclick="refresh()">Refresh UI</a>
</body>
</html>
Copy "sample.jsp" file into your "$TOMCAT_HOME/webapps/openkm/" folder.
Enable the extension named "External Tab Document", take a look at Enable extensions and External tab document extension. Remember you must enable the extension from the Profiles.
Configure the parameter extension.external.tab.document with the value below.
Field / Property | Type | Description |
---|---|---|
extension.external.tab.document |
List |
Each row is a couple of values with a tab content declaration, the format is: name;url Sample;http://localhost:8180/openkm/test.jsp |
More information at Configuration parameters.