Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Utils

Index

Type Aliases

RequestFailure<E>: ((errorInfo: E, response: XMLHttpRequest) => any)

Type Parameters

  • E = any

Type declaration

    • (errorInfo: E, response: XMLHttpRequest): any
    • Parameters

      • errorInfo: E
      • response: XMLHttpRequest

      Returns any

RequestSuccess<D>: ((data: D, request: ExtendedXMLHttpRequest, config: RequestOptions) => any)

Type Parameters

  • D = any

Type declaration

Functions

  • alert(title: string, msg: string): void
  • apply(object: any, config: any): any
  • Applies config properties to the specified object.

    Parameters

    • object: any
    • config: any

    Returns any

  • applyTranslated(target: any, source: any, translationMap: any, applyOthers?: boolean, applyFunctions?: boolean): void
  • Applies properties from the source object to the target object, translating the property names based on the translation map. The translation map should have an entry per property that you wish to rename when it is applied on the target object. The key should be the name of the property on the source object and the value should be the desired name on the target object. The value may also be set to null or false to prohibit that property from being applied. By default, this function will also apply all other properties on the source object that are not listed in the translation map, but you can override this by supplying false for the applyOthers parameter.

    Parameters

    • target: any

      The target object

    • source: any

      The source object

    • translationMap: any

      A map listing property name translations

    • Optional applyOthers: boolean

      Set to false to prohibit application of properties not explicitly mentioned in the translation map.

    • Optional applyFunctions: boolean

      Set to false to prohibit application of properties that are functions

    Returns void

  • capitalize(value: string): string
  • Returns the string value with the first char capitalized.

    Parameters

    • value: string

      The string value to capitalize

    Returns string

  • caseInsensitiveEquals(a: any, b: any): boolean
  • Returns true if the arguments are case-insensitive equal. Note: the method converts arguments to strings for the purposes of comparing numbers, which means that it will return odd behaviors with objects (ie. LABKEY.Utils.caseInsensitiveEquals({t: 3}, '[object Object]') returns true)

    Parameters

    • a: any

      The first item to test

    • b: any

      The second item to test

    Returns boolean

    True if arguments are case-insensitive equal, false if not

  • decode(data: any): any
  • deleteCookie(name: string, pageOnly: boolean): void
  • Deletes a cookie. Note that 'name' and 'pageOnly' should be exactly the same as when the cookie was set.

    Parameters

    • name: string

      The name of the cookie to be deleted.

    • pageOnly: boolean

      Whether the cookie is scoped to the entire site, or just this page. Deleting a site-level cookie has no impact on page-level cookies, and deleting page-level cookies has no impact on site-level cookies, even if the cookies have the same name.

    Returns void

  • displayAjaxErrorResponse(response?: any, exception?: any, showExceptionClass?: any, msgPrefix?: any): void
  • Shows an error dialog box to the user in response to an error from an AJAX request, including any error messages from the server.

    Parameters

    • Optional response: any

      The XMLHttpRequest object containing the response data.

    • Optional exception: any

      A JavaScript Error object caught by the calling code.

    • Optional showExceptionClass: any

      Flag to display the java class of the exception.

    • Optional msgPrefix: any

      Prefix to the error message (defaults to: 'An error occurred trying to load:')

    Returns void

  • encode(data: any): string
  • encodeHtml(html: string, retainEmptyValueTypes?: boolean): string
  • Encodes the html passed in and converts it to a String so that it will not be interpreted as HTML by the browser. For example, if your input string was "<p>Hello</p>" the output would be "&lt;p&gt;Hello&lt;/p&gt;". If you set an element's innerHTML property to this string, the HTML markup will be displayed as literal text rather than being interpreted as HTML. By default this function will return an empty string if a value of undefined or null is passed it. To prevent this default, you can pass in a second optional parameter value of true to retain the empty value's type.

    Parameters

    • html: string

      The HTML to encode and return as a String value. If the value of this parameter is null or undefined, an empty string will be returned by default.

    • Optional retainEmptyValueTypes: boolean

      Optional boolean parameter indicating that the empty values (null and undefined) should be returned as is from this function.

    Returns string

    The encoded HTML

  • endsWith(value: string, ending: string): boolean
  • Returns true if value ends with ending

    Parameters

    • value: string

      the value to examine

    • ending: string

      the ending to look for

    Returns boolean

  • ensureRegionName(regionName?: string): string
  • escapeRe(s: string): string
  • generateUUID(): string
  • Returns a universally unique identifier, of the general form: "92329D39-6F5C-4520-ABFC-AAB64544E172" NOTE: Do not use this for DOM id's as it does not meet the requirements for DOM id specification. Based on original Math.uuid.js (v1.4) http://www.broofa.com mailto:robert@broofa.com Copyright (c) 2010 Robert Kieffer Dual licensed under the MIT and GPL licenses.

    Returns string

  • getCallbackWrapper<T>(fn: Function, scope?: any, isErrorCallback?: boolean, responseTransformer?: ((json?: any) => T)): AjaxHandler
  • This is used to automatically parse returned JSON and call another success function passing that parsed JSON.

    Type Parameters

    • T = any

    Parameters

    • fn: Function

      The callback function to wrap.

    • Optional scope: any

      The scope for the callback function.

    • Optional isErrorCallback: boolean

      Set to true if the function is an error callback. If true, and you do not provide a separate callback, alert will popup showing the error message.

    • Optional responseTransformer: ((json?: any) => T)

      Function to be invoked to transform the response object before invoking the primary callback function.

        • (json?: any): T
        • Parameters

          • Optional json: any

          Returns T

    Returns AjaxHandler

  • getCookie(name: string, defaultValue: string): string
  • Retrieves a cookie. Useful for retrieving non-essential state to provide a better user experience. Note that some browser settings may prevent cookies from being saved, and users can clear browser cookies at any time, so previously saved cookies should not be assumed to be available.

    Parameters

    • name: string

      The name of the cookie to be retrieved.

    • defaultValue: string

      The value to be returned if no cookie with the specified name is found on the client.

    Returns string

  • getDateAltFormats(): string
  • Returns date formats for use in an Ext.form.DateField. Useful when using a DateField in an Ext object, it contains a very large set of date formats, which helps make a DateField more robust. For example, a user would be allowed to enter dates like 6/1/2011, 06/01/2011, 6/1/11, etc.

    Returns string

  • getDateTimeFormatWithMS(): string
  • Returns date format with timestamp including milliseconds. Useful for parsing the date in "yyyy-MM-dd HH:mm:ss.SSS" format as returned by DateUtil.getJsonDateTimeFormatString(). ex. Ext4.Date.parse("2019-02-15 17:15:10.123", 'Y-m-d H:i:s.u')

    Returns string

  • getFileIconUrl(fileName: string): string
  • Returns a URL to the appropriate file icon image based on the specified file name. Note that file name can be a full path or just the file name and extension. If the file name does not include an extension, the URL for a generic image will be returned

    Parameters

    • fileName: string

    Returns string

    The URL suitable for use in the src attribute of an img element.

  • getMeasureAlias(measure: any, override?: boolean): string
  • getMsgFromError(response: XMLHttpRequest, exceptionObj: any, config: any): string
  • Generates a display string from the response to an error from an AJAX request

    Parameters

    • response: XMLHttpRequest
    • exceptionObj: any
    • config: any

    Returns string

  • getOnFailure(config: { errorCallback?: any; failure?: any; failureCallback?: any }): any
  • Standard documented name for error callback arguments is "failure" but various other names have been employed in past. This function provides reverse compatibility by picking the failure callback argument out of a config object be it named failure, failureCallback or errorCallback.

    Parameters

    • config: { errorCallback?: any; failure?: any; failureCallback?: any }
      • Optional errorCallback?: any
      • Optional failure?: any
      • Optional failureCallback?: any

    Returns any

  • getOnSuccess(config: { success?: any; successCallback?: any }): any
  • Standard documented name for success callback arguments is "success" but various names have been employed in past. This function provides reverse compatibility by picking the success callback argument out of a config object, be it named success or successCallback.

    Parameters

    • config: { success?: any; successCallback?: any }
      • Optional success?: any
      • Optional successCallback?: any

    Returns any

  • getSessionID(): string
  • Retrieves the current LabKey Server session ID. Note that this may only be made available when the session ID cookie is marked as httpOnly = false.

    see

    OWASP HttpOnly

    see

    Tomcat Attributes

    Returns string

    The current session id. Defaults to ''.

  • id(prefix?: string): string
  • Will generate a unique id. If you provide a prefix, consider making it DOM safe so it can be used as an element id.

    Parameters

    • Optional prefix: string

      Optional prefix to start the identifier. Defaults to "lk-gen".

    Returns string

  • isArray(value: any): boolean
  • isBoolean(value: any): boolean
  • Tests whether the passed value can be used as boolean, using a loose definition. Acceptable values for true are: 'true', 'yes', 1, 'on' or 't'. Acceptable values for false are: 'false', 'no', 0, 'off' or 'f'. Values are case-insensitive.

    Parameters

    • value: any

      The value to test

    Returns boolean

  • isDate(value: any): boolean
  • isDefined(value: any): boolean
  • isEmptyObj(obj: any): boolean
  • Returns true if the passed object is empty (ie. {}) and false if not.

    Parameters

    • obj: any

      The object to test

    Returns boolean

    the result of the test

  • isFunction(value: any): boolean
  • isNumber(value: any): boolean
  • isObject(value: any): boolean
  • isString(value: any): value is string
  • Returns true if the passed value is a string.

    Parameters

    • value: any

    Returns value is string

  • merge(...props: any[]): any
  • Apply properties from b, c, ... to a. Properties of each subsequent object overwrites the previous.

    The first object is modified.

    Use merge({}, o) to create a deep copy of o.

    Parameters

    • Rest ...props: any[]

    Returns any

  • mergeIf(...props: any[]): any
  • onError(error: any): void
  • onReady(config: any): void
  • Iteratively calls a tester function you provide, calling another callback function once the tester function returns true. This function is useful for advanced JavaScript scenarios, such as cases where you are including common script files dynamically using the requiresScript() method, and need to wait until classes defined in those files are parsed and ready for use.

    Parameters

    Returns void

  • padString(input: string | number, length: number, padChar: string): string
  • Will pad the input string with zeros to the desired length.

    Parameters

    • input: string | number

      The input string / number

    • length: number

      The desired length

    • padChar: string

      The character to use for padding.

    Returns string

    The padded string

  • parseDateString(dateString: string): Date
  • pluralBasic(count: number, singlar: string): string
  • pluralize(count: number, singular: string, plural: string): string
  • requiresCSS(filePath: string): void
  • Includes a Cascading Style Sheet (CSS) file into the page. If the file was already included by some other code, this function will simply ignore the call. This may be used to include CSS files defined in your module's web/ directory.

    Parameters

    • filePath: string

      The path to the script file to include. This path should be relative to the web application root. So for example, if you wanted to include a file in your module's web/mymodule/styles/ directory, the path would be "mymodule/styles/mystyles.css"

    Returns void

  • requiresScript(file: string | string[], callback: Function, scope?: any, inOrder?: boolean): void
  • Loads JavaScript file(s) from the server.

    Parameters

    • file: string | string[]

      A file or Array of files to load.

    • callback: Function

      Callback for when all dependencies are loaded.

    • Optional scope: any

      Scope of callback.

    • Optional inOrder: boolean

      True to load the scripts in the order they are passed in. Default is false.

      <script type="text/javascript">
      LABKEY.Utils.requiresScript("myModule/myScript.js", function() {
      // your script is loaded
      });
      </script>

    Returns void

  • roundNumber(input: number, dec: number): number
  • Rounds the passed number to the specified number of decimals

    Parameters

    • input: number

      The number to round

    • dec: number

      The number of decimal places to use

    Returns number

    The rounded number

  • setCookie(name: string, value: string, pageOnly: boolean, days: number): void
  • Sets a client-side cookie. Useful for saving non-essential state to provide a better user experience. Note that some browser settings may prevent cookies from being saved, and users can clear browser cookies at any time, so cookies are not a substitute for database persistence.

    Parameters

    • name: string

      The name of the cookie to be saved.

    • value: string

      The value of the cookie to be saved.

    • pageOnly: boolean

      Whether this cookie should be scoped to the entire site, or just this page. Page scoping considers the entire URL without parameters; all URL contents after the '?' are ignored.

    • days: number

      The number of days the cookie should be saved on the client.

    Returns void

  • Returns a string containing a well-formed html anchor that will apply theme specific styling. The configuration takes any property value pair and places them on the anchor.

    Parameters

    Returns string

Generated using TypeDoc