Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace ActionURL

Index

Functions

  • buildURL(controller: string, action: string, containerPath?: string, parameters?: Record<string, any>): string
  • Builds a URL from a controller and an action. Uses the current container and context path.

    Examples

    1. Build the URL for the 'getWebPart' action in the 'reports' controller within the current container
      var url = LABKEY.ActionURL.buildURL("project", "getWebPart");
      
    1. Build the URL for the 'updateRows' action in the 'query' controller within the container "My Project/My Folder"

      var url = LABKEY.ActionURL.buildURL("query", "updateRows", "My Project/My Folder");
      
    2. Navigate the browser to the study controller's begin action in the current container

      window.location = LABKEY.ActionURL.buildURL("study", "begin");
      
    3. Navigate the browser to the study controller's begin action in the folder "/myproject/mystudyfolder"

      window.location = LABKEY.ActionURL.buildURL("study", "begin", "/myproject/mystudyfolder");
      
    4. Navigate to the list controller's insert action, passing a returnUrl parameter that points back to the current page:

      window.location = LABKEY.ActionURL.buildURL("list", "insert", LABKEY.ActionURL.getContainer(), {listId: 50, returnUrl: window.location});
      

    Parameters

    • controller: string

      The controller to use in building the URL

    • action: string

      The action to use in building the URL

    • Optional containerPath: string

      The container path to use (defaults to the current container)

    • Optional parameters: Record<string, any>

      An object with properties corresponding to GET parameters to append to the URL. Parameters will be encoded automatically. Parameter values that are arrays will be appended as multiple parameters with the same name. (Defaults to no parameters)

    Returns string

    URL constructed from the current container and context path, plus the specified controller and action.

  • getAction(): string
  • getBaseURL(noContextPath?: boolean): string
  • Get the current base URL, which includes context path by default for example: http://labkey.org/labkey/

    Parameters

    • Optional noContextPath: boolean

      Set true to omit the context path. Defaults to false.

    Returns string

    Current base URL.

  • getContainer(): string
  • getContainerName(): string
  • Gets the current container's name. For example, if you are in the /Project/SubFolder/MyFolder container, this method would return 'MyFolder' while getContainer() would return the entire path.

    Returns string

    Current container name.

  • getContextPath(): string
  • Gets the current context path. The default context path for LabKey Server is '/labkey'.

    Returns string

    Current container path.

  • getController(): string
  • getParameter(parameterName: string): any
  • Gets a URL parameter by name. Note that if the given parameter name is present more than once in the query string, the returned value will be the first occurrence of that parameter name. To get all instances of the parameter, use getParameterArray().

    Parameters

    • parameterName: string

      The name of the URL parameter.

    Returns any

    The value of the named parameter, or undefined of the parameter is not present.

  • getParameterArray(parameterName: string): string[]
  • Gets a URL parameter by name. This method will always return an array of values, one for each instance of the parameter name in the query string. If the parameter name appears only once this method will return a one-element array.

    Parameters

    • parameterName: string

      The name of the URL parameter.

    Returns string[]

    An Array of parameter values.

  • getParameters(url?: string): Record<string, any>
  • Returns an object mapping URL parameter names to parameter values. If a given parameter appears more than once on the query string, the value in the map will be an array instead of a single value. Use LABKEY.Utils.isArray() to determine if the value is an array or not, or use getParameter() or getParameterArray() to retrieve a specific parameter name as a single value or array respectively.

    Parameters

    • Optional url: string

      The URL to parse. If not specified, the browser's current location will be used.

    Returns Record<string, any>

    Object of parameter names to values.

  • getPathFromLocation(pathname?: string, contextPath?: string): ActionPath
  • Parses a location pathname of a LabKey URL into its constituent parts (e.g. controller, action, etc). Defaults to the current location's pathname and context path. The parsed parts of the ActionPath are URI decoded.

    Example

    // 1. First example shows the default values as retrieved for the pathname and context path.
    // window.location.pathname = "/labkey/folder/tree/study-participants.view"
    // LABKEY.contextPath = "/labkey"
    const path = ActionURL.getPathFromLocation();

    console.log(path.contextPath); // "/labkey"
    console.log(path.containerPath); // "/folder/tree"
    console.log(path.controller); // "study"
    console.log(path.action); // "participants"

    // 2. Second example when the "pathname" parameter is supplied. The default value for context path is utilized.
    // LABKEY.contextPath = "/labkey"
    const pathname = "/labkey/home/with/folder/project-begin.view";
    const path = ActionURL.getPathFromLocation(pathname);

    console.log(path.contextPath); // "/labkey"
    console.log(path.containerPath); // "/home/with/folder"
    console.log(path.controller); // "project"
    console.log(path.action); // "begin"

    Parameters

    Returns ActionPath

  • getReturnUrl(): string
  • queryString(parameters?: Record<string, string | string[]>): string
  • Turn the parameter object into a query string (e.g. {x:'fred'} -> "x=fred"). The returned query string is not prepended by a question mark ('?').

    Parameters

    • Optional parameters: Record<string, string | string[]>

      An object with properties corresponding to GET parameters to append to the URL. Parameters will be encoded automatically. Parameter values that are arrays will be appended as multiple parameters with the same name. (Defaults to no parameters.)

    Returns string

Generated using TypeDoc