Exposed frontend JavaScript API

This has been deprecated since version 7.1 (it is no longer GWT; it is currently Vue.js)

OpenKM UI is developed with the GWT framework, which helps call Java methods from JavaScript.

The UI frontend Java methods are publicly exposed as JavaScript functions and can be used in the frontend context.

More information about GWT JSNI can be found at GWT Dev Coding 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 the js-equivalent ones.

 

FunctionReturnDescriptionDeprecated

jsI18n(String)

void

Retrieve a frontend translation.

The parameter is the translation key.

no

jsOpenUserTaskInstance(String)

void

Open the dashboard workflow to view a user task.

The parameter is the task instance id.

no

jsOpenPath(String, String)

void

Open some node in OpenKM UI.

The first parameter is the folder path.

The second parameter is the document path.

When the document path parameter is empty, a folder will be opened.

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 the UI (like the toolbar refresh button action).

no

jsWizard(String, String)

void

Execute wizard.

The first parameter is a document path.

The second parameter is a JSON string serialization of a GWTFileUploadResponse bean.

The wizard should usually be called after 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.

The first parameter is the folder path.

The second parameter is the document path.

When the document path parameter is empty, a folder will be opened.

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 the UI (like the toolbar refresh button action).

yes

jsCancelCheckout()

void

Cancel checkout of the selected document in the UI.

no

jsGetActualPath()

String

Return the path of the selected tree node in the navigator.

no

jsGetActualNodePath()

String

Return the path of the selected node in the navigator or file browser.

no

jsGetActualNodeUUID()

String

Return the UUID of the selected node in the navigator or file browser.

no

jsGetUser()

String

Return the 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 the workspace tab.

Allowed values:

  • 0 for Desktop.
  • 1 for Search.
  • 2 for Dashboard.
  • 3 for Administration.

no

Cryptography functions

FunctionReturnDescriptionDeprecated

cryptographyLoaded()

void

Hide the UI popup status that indicates the cryptography applet is not yet loaded.

no

digitalSignatureEnded()

void

Indicate that the digital signature has finished.

no

digitalSignatureCanceled()

void

The digital signature has been canceled.

no

startDigitalSignature()

void

Start the digital signature.

no

Applet functions

FunctionReturnDescriptionDeprecated

destroyScannerApplet()

void

Clean the scanner applet.

no

destroyUploaderApplet()

void

Clean the bulk upload applet.

no

HTML Editor functions

FunctionReturnDescriptionDeprecated

jsSearchDocumentHTMLEditorPopup()

void

Show the find document popup.

no

jsSearchFolderHTMLEditorPopup()

void

Show the find folder popup.

no

Wiki functions

FunctionReturnDescriptionDeprecated

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 the jsRefreshFolder function:

In the Toolbar Java class, 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 can be found at GWT Dev Coding Basics.

Integration sample

Create a "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 the "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 that you must enable the extension from the Profiles.

Configure the parameter extension.external.tab.document with the value below.

Field / PropertyTypeDescription

extension.external.tab.document

List

Each row is a pair of values with a tab content declaration; the format is: name;url

Sample;http://localhost:8180/openkm/test.jsp


More information at Configuration parameters.