The vSphere HTML Client SDK offers a set of JavaScript APIs which facilitate the building of HTML Client-only plugins, fully compatible with the HTML-based vSphere Client.
These JavaScript APIs are documented here as if they have TypeScript signatures, but they run as pure JavaScript, and all complex types are plain old Javascript objects.
The JavaScript APIs may be used by the plugin to communicate with the HTML Client and to execute a number of operations. Each plugin will have access to the JavaScript APIs within its own iframe which eliminates the possibility of plugin conflicts. Please refer to the Plug-in Architecture Diagram in the online vSphere Client SDK documentation.
WARNING: Do not access the window.parent (the Client window), as this is unsupported and if your plugin relies on this it might break in a future release of the vSphere Client.
The JavaScript APIs are organized in several domains depending on their functionality. This improves readability and communicates clearly the API functionality scope:
The JavaScript APIs can be accessed by getting the API object directly from the extension's iframe, such as:
window.frameElement.htmlClientSdk
Note: For practical examples on how to use the JS APIs for local plugins, see the "html-sample" plugin. In order to make the following examples more readable, we will use a shortcut for the JS API object, namely
"htmlClientSdk" which will be equal to "window.frameElement.htmlClientSdk".
The client application APIs are related to the HTML Client application. The client application APIs can be accessed with the
htmlClientSdk.app.{API}
| APIs | Description | Example usage |
|---|---|---|
| getContextObjects() => any[] |
Returns current context objects:
|
htmlClientSdk.app.getContextObjects();
for example: [ { id: "urn:vmomi:Datacenter:datacenter-1" } ] |
| navigateTo(configObj: NavigationOptions) => void | Navigates to a specified view with an optional custom data which will be passed to the view.
If just objectId is passed, then the default object view will be displayed.
The configuration object should contain the following information: interface NavigationOptions { targetViewId?: string; objectId?: string; customData?: any; } Where:
When navigating to a global view, the "objectId" property can be skipped. |
htmlClientSdk.app.navigateTo({
targetViewId: "acme-plugin-monitor-view", objectId: "urn:vmomi:Datacenter:datacenter-1", customData: {name: "test", filter: true} }); |
| navigateToRemotePluginView(configObj: RemotePluginViewNavigationOptions) => void | Navigates to the specified view defined by a remote plugin with an optional custom data which will be passed to the view.
The valid values for the targetViewId parameter are the ones returned by the
htmlClientSdk.app.getRemotePluginNavigationMap() call for the given plugin.
The configuration object should contain the following information: interface RemotePluginViewNavigationOptions { pluginId: string; targetViewId: string; vcGuid: string; objectId?: string; customData?: any; } Where:
Note: When navigating to a global view, the objectId property should be skipped. |
htmlClientSdk.app.navigateToRemotePluginView({
pluginId: "acme-plugin", targetViewId: "acme-plugin-monitor-view", vcGuid: "vc-guid-0", objectId: "urn:vmomi:Datacenter:datacenter-1:vc-guid-0", customData: {name: "test", filter: true} }); |
| getNavigationData() => any | Retrieves the navigation data passed to the current view by the navigateTo() API.
|
If the following is called: htmlClientSdk.app.navigateTo({ targetViewId: "acme-plugin-monitor-view", objectId: "urn:vmomi:Datacenter:datacenter-1", customData: {name: "test", filter: true} }); Then, any call to: htmlClientSdk.app.getNavigationData(); will return: {name: "test", filter: true} |
| getClientInfo() => ClientInfo | Returns information about the current vSphere Client, such as "version", "type" etc.
interface ClientInfo { type?: string; version?: string; } Where:
|
htmlClientSdk.app.getClientInfo();
for example: {type: "HTML", version: "6.5.1"} |
| getClientLocale() => string | Returns the current locale of the vSphere Client. |
htmlClientSdk.app.getClientLocale();
for example: "de-DE" |
| getTheme() => PluginTheme |
Returns information about the theme the plugin should use. The returned
PluginTheme type is defined as follows:
interface PluginTheme { name: "light" | "dark" } |
htmlClientSdk.app.getTheme();
for example: { name: "dark" } |
| formatDateTime(instant: number, options?: PluginDateTimeFormatOptions) => string |
Formats the specified date-time instant using the provided options. Returns a string which represents the formatted date. The instant should be a Unix Time Stamp, an integer value that is the number of milliseconds since 1 January 1970 UTC. PluginDateTimeFormatOptions type is defined as follows: interface PluginDateTimeFormatOptions { format?: "DATE" | "TIME" | "DATE_AND_TIME"; } Where:
|
htmlClientSdk.app.formatDateTime(1557735887313); Returns: "05/13/2019, 11:24:47 AM" htmlClientSdk.app.formatDateTime(1557735887313, {format: "DATE"}); Returns: "05/13/2019" htmlClientSdk.app.formatDateTime(1557735887313, {format: "TIME"}); Returns: "11:24:47 AM" htmlClientSdk.app.formatDateTime(1557735887313, {format: "DATE_AND_TIME"}); Returns: "05/13/2019, 11:24:47 AM" |
| getRemotePluginNavigationMap(targetPluginId: string, callback: ((navigationInfo: RemotePluginNavigationMap | null) => void)) => void |
Retrieves a navigation map that contains the public views' navigation IDs
of the target remote plugin per vCenter Server. The result will contain information
about all vCenter Servers with which an enabled version of the target remote plugin
is registered.
Parameters:
RemotePluginNavigationMap type is defined as follows: interface RemotePluginNavigationMap { // A map of vCenter Server GUID to the relevant remote plugin navigation information about that vCenter Server. navigationInfoByVcGuid: { [vcGuid: string]: RemotePluginVcNavigationInfo }; } RemotePluginVcNavigationInfo type is defined as follows: interface RemotePluginVcNavigationInfo { // The remote plugin version registered with the particular vCenter Server. pluginVersion: string; // The particular remote plugin version views' navigation IDs. viewsIds: string[]; } |
Consider that a remote plugin with ID com.acme.remote
has a single registration within the environment. The registration is done
on vCenter with GUID vc-guid-0 for plugin instance with version 1.0.0.0.
Also consider that the plugin has a single public view within Host -> Monitor with navigationId mon.
Then the following API invocation: htmlClientSdk.app.getRemotePluginNavigationMap("com.acme.remote", function(map) { console.log(map); }); would yield the following result: { navigationInfoByVcGuid: { vc-guid-0: { pluginVersion: "1.0.0.0", viewsIds: ["mon"] } } } |
The event APIs provide means for plugins to subscribe and respond to events. These APIs can be accessed via htmlClientSdk.event.{API}
| API | Description | Example usage |
|---|---|---|
| onGlobalRefresh(callback: () => void) => void | Subscribes to a global refresh event and when such an event occurs, the callback function will be executed. |
function updateData() {
alert("Data is updated after a global refresh."); } htmlClientSdk.event.onGlobalRefresh(updateData); |
| onThemeChanged((theme: PluginTheme) => void) => void |
Subscribes for plugin theme changed events. When such an event occurs,
the callback argument function will be
invoked with a single argument - the new plugin theme in the form of
PluginTheme object.
The PluginTheme type is defined as follows: interface PluginTheme { name: "light" | "dark"; } |
function showCurrentThemeName(theme) { alert(theme.name); } htmlClientSdk.event.onThemeChanged(showCurrentThemeName); |
| onDateTimeFormatChanged(callback: () => void) => void | Subscribes to date-time format change events. When the date-time format changes, the provided callback function will be invoked without arguments. |
function onTimeFormatPreferencesChange() { alert("The time format preferences have changed."); } htmlClientSdk.event.onDateTimeFormatChanged(onTimeFormatPreferencesChange); |
The modal APIs are used to perform various actions for a modal dialog such as open, close and configure. The modal APIs can be accessed with the htmlClientSdk.modal.{API}
| API | Description | Example usage |
|---|---|---|
| open(configObj: ModalConfig) => void | Opens a modal dialog and accepts for parameter a configuration object, which contains:
interface ModalConfig { url: string; title?: string; accessibilityTitle?: string; size?: { width: number, height: number }; closable?: boolean; onClosed?: (result?: any) => void; contextObjects?: any[]; customData?: any; } Where:
|
var config = { url: "resources/editDatacenter.html", title: "Edit Datacenter", accessibilityTitle: "Edit Datacenter", size: { width: 490, height: 240 }, onClosed: function(id) { alert("Modal " + id + " closed."); }, contextObjects: [{ id: "urn:vmomi:Datacenter:datacenter-1" }, { id: "urn:vmomi:Datacenter:datacenter-2" }], customData: {idsRange: [1, 9]} }; htmlClientSdk.modal.open(config); |
| openConfirmationModal(configObj: ConfirmationModalConfig) => void | Opens a simplified modal dialog dedicated to showing confirmation messages. The API offers:
interface ConfirmationModalConfig { content: string; buttons: ModalButton[]; size?: ModalSize; alertLevel?: AlertLevel; title?: string; accessibilityTitle?: string; secondaryTitle?: string; closable?: boolean; onClosed?: () => void; } interface ModalSize { width: number; } interface ModalButton { label: string; type?: ButtonType; style?: ButtonStyle; callback?: () => void; } enum ButtonType { PRIMARY = "PRIMARY", SECONDARY = "SECONDARY" } enum ButtonStyle { SUCCESS = "SUCCESS", INFO = "INFO", WARNING = "WARNING", DANGER = "DANGER" } enum AlertLevel { SUCCESS = "SUCCESS", INFO = "INFO", WARNING = "WARNING", DANGER = "DANGER" } Where:
|
var confirmationModalConfig = { content: "Deleting a chassis can cause failures in your environment?", size: { width: 490 }, alertLevel: "DANGER", title: "Delete chassis.", accessibilityTitle: "Delete chassis. Chassis-1", secondaryTitle: "Chassis-1", buttons: [{ label: "DELETE", callback: () => {//some delete callback actions} }, label: "CANCEL", callback: () => {//some cancel callback actions} }], closable: false, onClosed: function() {//Default onClosed handler. Invoked on ESC / X button press} }; htmlClientSdk.modal.openConfirmationModal(confirmationModalConfig); |
| close(data?: any) => void | Closes the already opened modal. The modal is the one corresponding to the iframe from which this API was called from.
If data has been provided it will be passed to the onClose callback function if such was specified in the parameter of the modal.open API. |
var modalId = 2;
htmlClientSdk.modal.close(modalId); |
| setOptions(configObj: DynamicModalConfig) => void | Changes the configuration of the modal with properties specified in the parameter object.
The configObj type is defined as follows: interface DynamicModalConfig { title?: string; accessibilityTitle?: string; height?: number; } Where:
|
htmlClientSdk.modal.setOptions({
title: "New Title", accessibilityTitle: "New Accessibility Title", height: 450 }); |
| getCustomData() => any | Returns the custom data that was provided upon opening the modal through customData property or null if the customData property was not set. |
htmlClientSdk.modal.getCustomData();
for example: {idsRange: [1, 9]} |