utils
Utils : d2/sdk/utils/utils
Utility functions.
Extends: Object
- Utils :
d2/sdk/utils/utils- .getAppContext() ⇒
string - .getStoreKey(key) ⇒
string - .getLocalStore(key) ⇒
NamedStorage - .getSessionStore(key) ⇒
NamedStorage - .isMobile() ⇒
boolean - .isAppworks() ⇒
boolean - .openUrlInWindow(url, [wnd], [focus], [keepLink]) ⇒
void - .makeBatchAjaxCall(options) ⇒
jQuery.Promise - .buildLinkUrl(link, isTemplate) ⇒
string - .parseAjaxError(xhr, [textStatus], [errorThrown], [includeDetails]) ⇒
ParsedErrorType - .parseAjaxErrorAsString(xhr, [textStatus], [errorThrown], [includeDetails]) ⇒
string - .parseError(responseType, responseData) ⇒
ParsedErrorType - .parseErrorAsString(responseType, responseData) ⇒
string - .copyToClipboard(clipboardText) ⇒
boolean - .isJqueryPromise(value) ⇒
boolean - .isNonEmptyString(str) ⇒
boolean - .areSameFunctions(fn1, fn2) ⇒
boolean
- .getAppContext() ⇒
Utils.getAppContext() ⇒ string
Get context path name of D2 Smart View deployment
Kind: static method of Utils
Returns: string - the context path name
Utils.getStoreKey(key) ⇒ string
Get a properly namespaced storage name for the given key. Used while creating a boundary within localStorage or sessionStorage.
See getLocalStore and getSessionStore below.
Kind: static method of Utils
Returns: string - namespaced key name
| Param | Type | Description |
|---|---|---|
| key | string | original key name |
Utils.getLocalStore(key) ⇒ NamedStorage
Get a local storage area identified by the given key. A new storage area gets created if doesn't exist already.
Kind: static method of Utils
Returns: NamedStorage - local store instance
| Param | Type | Description |
|---|---|---|
| key | string | Storage identifier |
Utils.getSessionStore(key) ⇒ NamedStorage
Get a session storage area identified by the given key. A new storage area gets created if doesn't exist already.
Kind: static method of Utils
Returns: NamedStorage - session store instance
| Param | Type | Description |
|---|---|---|
| key | string | Storage identifier |
Utils.isMobile() ⇒ boolean
Detects whether the D2 Smart View runtime platform is a mobile
Kind: static method of Utils
Returns: boolean - true if it's being run on mobile, false otherwise.
Utils.isAppworks() ⇒ boolean
Detects whether the D2 Smart View runtime platform is appworks.
Kind: static method of Utils
Returns: boolean - true if it's Appworks.
Utils.openUrlInWindow(url, [wnd], [focus], [keepLink]) ⇒ void
Open the given URL in window.
Kind: static method of Utils
| Param | Type | Default | Description |
|---|---|---|---|
| url | string | The URL to open | |
| [wnd] | Window | The window where | |
| [focus] | boolean | false | Whether to focus the window |
| [keepLink] | boolean | false | Whether to keep the |
Utils.makeBatchAjaxCall(options) ⇒ jQuery.Promise
Make a single D2-REST AJAX call with a batch of operations.
Kind: static method of Utils
Returns: jQuery.Promise - The returned promise fails on AJAX error. It resolves otherwise invoking BatchDoneCallback as documented below.
| Param | Type | Default | Description |
|---|---|---|---|
| options | object | Holder of different options | |
| options.connector | Connector | Transport for the AJAX call. See Connector. | |
| options.operations | Array.<BatchOperationRequest> | Operations to be perfomred in this batch. | |
| [options.transactional] | boolean | false | Whether this batch is to be executed as a transaction. A transactional batch operates with 'Either all or none' paradigm. |
| [options.sequential] | boolean | false | For a non-transactional batch, whether the operations are to be run sequentially or parrallely. |
| [options.continueOnError] | boolean | false | Whether remaining operations are to be run if one fails. |
Example
define([
'd2/sdk/utils/contexts/context.utils',
'd2/sdk/utils/utils',
'd2/sdk/utils/contexts/factories/connector'
], function(contextUtil, util, ConnectorFactory){
'use strict';
// Retrieve document menu actions and favorited status for object '0c0015fa8000291e' in a single batch call
util.makeBatchAjaxCall({
connector: contextUtil.getPerspectiveContext().getObject(ConnectorFactory),
continueOnError: true,
operations: [
{
id: 'favorites',
request: {
method: 'GET',
uri: '/repositories/d2repo/favorites-checker?object-ids=0c0015fa8000291e'
}
},
{
id: 'actions',
request: {
method: 'GET',
uri: '/repositories/d2repo/actions?type=MenuContext&widgetType=DoclistWidget&include-subtype=true&object-ids=0c0015fa8000291e'
}
}
]
})
.done(function(){
console.log('batch call success');
})
.fail(function(){
console.log('batch call failed');
});
});
Utils.buildLinkUrl(link, isTemplate) ⇒ string
Build complete URL from a D2-REST link
Kind: static method of Utils
Returns: string - the complete URL.
| Param | Type | Description |
|---|---|---|
| link | Object | The link as is from a D2-REST response |
| isTemplate | boolean | Is this D2-REST link a templated one or regular. |
Utils.parseAjaxError(xhr, [textStatus], [errorThrown], [includeDetails]) ⇒ ParsedErrorType
Parse AJAX error happened as a result of D2-REST API call and return a normalized error structure.
Kind: static method of Utils
Returns: ParsedErrorType - the parsed error
| Param | Type | Default | Description |
|---|---|---|---|
| xhr | external:XMLHttpRequest | The XHR transport | |
| [textStatus] | string | Textual status associated with the error | |
| [errorThrown] | string | Custom error message in case the XHR response could not be parsed. | |
| [includeDetails] | boolean | false | Whether to include a |
Utils.parseAjaxErrorAsString(xhr, [textStatus], [errorThrown], [includeDetails]) ⇒ string
Parse AJAX error happened as a result of D2-REST API call and return a compact string representing it.
Kind: static method of Utils
Returns: string - the parsed error
| Param | Type | Default | Description |
|---|---|---|---|
| xhr | external:XMLHttpRequest | The XHR transport | |
| [textStatus] | string | Textual status associated with the error | |
| [errorThrown] | string | Custom error message in case the XHR response could not be parsed. | |
| [includeDetails] | boolean | false | Whether to include a |
Utils.parseError(responseType, responseData) ⇒ ParsedErrorType
Extract error from custom object and format it similar to return format of parseAjaxError.
Kind: static method of Utils
Returns: ParsedErrorType - the parsed error
| Param | Type | Description |
|---|---|---|
| responseType | string | Hint of how to parse |
| responseData | JSON | string | If |
Utils.parseErrorAsString(responseType, responseData) ⇒ string
Extract error from custom object and return a compact string representing it.
Kind: static method of Utils
Returns: string - the parsed error
| Param | Type | Description |
|---|---|---|
| responseType | string | Hint of how to parse |
| responseData | JSON | string | If |
Utils.copyToClipboard(clipboardText) ⇒ boolean
Set some text content to the browser clipboard
Kind: static method of Utils
Returns: boolean - true indicates the copy is successful.
| Param | Type | Description |
|---|---|---|
| clipboardText | string | The content to be copied. |
Utils.isJqueryPromise(value) ⇒ boolean
Checks whether a given value is a jQuery.Promise instance or not
Kind: static method of Utils
Returns: boolean - true if it's a jQuery.Promise, false otherwise.
| Param | Type | Description |
|---|---|---|
| value | * | The test value |
Utils.isNonEmptyString(str) ⇒ boolean
Checks whether a given value is a non-empty string
Kind: static method of Utils
Returns: boolean - true if it's a string
| Param | Type | Description |
|---|---|---|
| str | * | The test value |
Utils.areSameFunctions(fn1, fn2) ⇒ boolean
Compare two functions for equality
Kind: static method of Utils
Returns: boolean - true only if Left hand side is equal to right hand side.
| Param | Type | Description |
|---|---|---|
| fn1 | function | Left hand side |
| fn2 | function | Right hand side |