You can access the Web platform APIs through the WEB_PLATFORM variable that is defined in the web-platform.js generated for each plug-in.

Following is a list of the JavaScript APIs provided with the vSphere Client development kit.

vSphere Client JavaScript APIs

JavaScript Function

Description

callActionsController(url, jsonData)

Use this function to invoke a headless action from within a user interface action dialog. Pass to the function the following parameters:

url - The value of this parameter has the following form: /<plugin_context_path>/rest/actions.html?actionUid=<action_Uid>.

jsonData - The optional data that is used by the headless action.

The target objectIds are added automatically to the url parameter.

For more information about how to create headless actions, see Creating Actions Extensions.

closeDialog()

Close a dialog that was opened through a user interface action such as when a form is submitted.

getActionUid()

Get the ID of the action that is invoked to open a user interface action or wizard. You can use the returned action ID in the url parameter of the callActionsController(url, jsonData) function.

getActionTargets()

Retrieve a comma-separated list of object IDs selected for an action. This function returns null for a global action. Use this function only within a user interface action dialog.

getObjectId()

Get the context object ID within an object view or a modal dialog. You can use this object ID to retrieve the vSphere object data from the vCenter Server system.

getString(bundleName, key, params)

Retrieve the localized value of a string that is defined in the plug-in resource bundle. Pass to the function the following parameters:

bundleName - The name of the plug-in resource bundle.

key - The string resource key.

params - Optional array of values that must replace the placeholders in the string.

getVcSelectorInfo()

Retrieve information that is provided within a global view by using the vCenter Server selector. The retrieved properties are serviceGuid, sessionId, and serviceUrl. For more information about how to enable the vCenter Server selector option, see Adding a vCenter Server Selector.

getUserSession()

Retrieve information about the current user session. The function returns the following properties:

userName

locale

serversInfo

You can use also the getUserSession() method of the UserSessionService Java service to retrieve details about the user session.

setGlobalRefreshHandler(callback)

Invoke this function to refresh your HTML views when the user clicks on the global Refresh button. Pass as argument the function that refreshes your HTML view.

openModalDialog(title, url, width, height, objectId, scrollPolicy, showCloseButton)

Invoke this function to open a modal dialog from within an HTML view, such as a wizard. The modal dialog blocks the rest of the user interface and is not limited to the HTML view. Because the dialog is modal, the content of the HTML view disappears temporarily until the dialog is closed.

Pass to the function the following parameters:

title - The title of the dialog.

url - The URL to the HTML content of the dialog.

width - The width of the dialog in pixels.

height - The height of the dialog in pixels.

objectId - Optional. The ID of the target object.

scrollPolicy - Optional. The scroll policy of the dialog that can be one of the following values: yes, no, or auto.

showCloseButton - Optional. The option to display a close button on the modal dialog. You can pass as a parameter to the function one of the following values: true or false.

sendModelChangeEvent(objectId, opType)

Trigger an event that results in the update of the object model when something in the vSphere inventory changes.

The function accepts the following parameters:

objectId - The ID of the vSphere object if the change must be applied to an object view.

opType - The type of the triggered event. You can pass as parameter one of the following values: add, change, delete, or relationshipChange.

sendNavigationRequest(targetViewId, objectId)

Invoke this function to open a global view or an object view.

The function accepts the following parameters:

targetViewId - The ID of the extension view.

objectId - The object ID in case the function is invoked on an object view.

setDialogTitle(title)

Change the title of the dialog at runtime. This function overrides the value of the <dialogTitle> property defined in the plugin.xml manifest file.

The function takes as parameter the title of the dialog.

Following is a list of the additional utility APIs that are defined in the plug-in namespace variable inside the web-platform.js file.

Utility JavaScript APIs

JavaScript Function

Description

buildDataUrl(objectId, propList)

Invoke this function to create the REST URL that is used to retrieve a set of object properties through the DataAccessController class.

The function accepts the following parameters:

objectId - The object ID that is passed as a parameter to the view. You can use the WEB_PLATFORM.getObjectId() function to retrieve the value of the objectId parameter.

propList - An array of property names that must be retrieved.

getString(key, params)

Retrieve the localized value of a key defined in the plug-in resource bundle.

The function accepts the following parameters:

key - The string value of the resource key.

params - Optional array of values that must replace the placeholders in the string.