x4js - v2.3.33
    Preparing search index...

    Class Application<E>

    The main application class, acting as a singleton. It manages the main view, environment variables, keyboard navigation, and provides utilities for local storage and WebSocket communication.

    Assertions ensure only one instance of Application can exist.

    Type Parameters

    Hierarchy (View Summary)

    Index
    process: Process = ...

    Provides access to process-related information, such as touch capabilities.

    • Adds a keyboard shortcut to the whole application: it works wherever the focus is, even in a dialog. A key typed in a field is not a shortcut, unless editable is set.

      Parameters

      Returns void

      Component.addShortcut for the shortcuts of a view

    • Clears all timeouts and intervals currently managed by this instance. This stops all scheduled callbacks and removes their references.

      Returns void

      setTimeout

    • Dispatches an event with a given name and payload to all registered listeners. If no listeners are registered for the event name, or if no EventSource has been initialized, this method does nothing.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event to fire.

      • ev: E[K]

        The payload (event object) to pass to the listeners.

      Returns void

      • on
      • off
    • Moves focus to the next or previous focusable element within the application. Handles Tab and Shift+Tab key presses.

      Parameters

      • next: boolean

        If true, focus moves to the next element; if false, to the previous.

      Returns boolean

      true if focus was successfully moved, false otherwise.

    • Retrieves an environment variable from the application's environment map.

      Type Parameters

      • T = any

      Parameters

      • name: string

        The name of the environment variable.

      • Optionaldef_value: T

        An optional default value to return if the variable is not found.

      Returns T

      The value of the environment variable, or def_value if not found.

    • Retrieves a value from the browser's local storage.

      Parameters

      • name: string

        The key of the value to retrieve.

      Returns string

      The stored value as a string, or null if not found.

    • Retrieves and parses a JSON value from the browser's local storage.

      Parameters

      • name: string

        The key of the JSON value to retrieve.

      Returns any

      The parsed JSON object, or undefined if not found or parsing fails.

    • Removes a previously registered event listener. If the listener was not found or no events were registered, this method does nothing.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event from which to remove the listener.

      • listener: (ev: E[K]) => void

        The specific listener function to remove.

      Returns void

      • on
      • fire
    • Registers an event listener for a specific event name. The listener will be invoked when an event with the given name is fired. Returns an object with an off() method, which can be used to conveniently remove this specific listener.

      Type Parameters

      • K extends string | number | symbol

      Parameters

      • name: K

        The name of the event to listen for.

      • listener: (ev: E[K]) => void

        The callback function to execute when the event is fired.

      Returns { off: () => void }

      An object containing an off() method to unsubscribe the listener.

      fire attach to an event

    • Sets an environment variable in the application's environment map.

      Type Parameters

      • T = any

      Parameters

      • name: string

        The name of the environment variable.

      • value: T

        The value to store for the environment variable.

      Returns void

    • Sets an interval that repeatedly executes a callback function after a specified delay. If a timeout with the same name already exists, it will be cleared before the new one is set.

      Parameters

      • name: string

        A unique string identifier for this timeout.

      • ms: number

        The delay in milliseconds before the callback is executed.

      • callback: () => void

        The function to execute after the delay.

      Returns void

    • Sets the main view component for the application. This component will be mounted to the DOM, in mountPoint. Called once: each call sets up the keyboard (Tab, shortcuts) again.

      Parameters

      • view: Component

        The component to set as the main view.

      Returns void

    • Stores a string or number value in the browser's local storage. The value will be converted to a string before storage.

      Parameters

      • name: string

        The key under which to store the value.

      • value: string | number

        The value to store.

      Returns void

    • Stores an object as a JSON string in the browser's local storage.

      Parameters

      • name: string

        The key under which to store the JSON value.

      • value: any

        The object to serialize and store.

      Returns void

    • Sets a timeout that executes a callback function after a specified delay. If a timeout with the same name already exists, it will be cleared before the new one is set.

      Parameters

      • name: string

        A unique string identifier for this timeout.

      • ms: number

        The delay in milliseconds before the callback is executed.

      • callback: () => void

        The function to execute after the delay.

      Returns void

    • Sets up WebSocket messaging for the application. All 'global' messages fired via the application will be sent over the WebSocket, and messages received from the WebSocket will be re-fired as 'global' messages.

      Parameters

      • Optionalpath: string

        Optional WebSocket path. If not provided, it defaults to ws://hostname:port/ws.

      • OptionallooseCallback: () => void

        A callback function to be executed when the WebSocket connection is closed unexpectedly.

      Returns void

    • The locale of the formats: the one forced by setLocale, else the one of the language.

      Returns string

    • The name of the theme of the page, as setTheme got it: "" for the light theme of x4, "dark" for its dark theme, or the name of a theme of the application.

      Returns string

    • Forces the locale of the formats of numbers, amounts and dates (formatNumber, formatMoney, formatDate, formatDateTime), and the currency of the amounts. Without it, the locale is the one of the language (_tr.global.locale: "fr-FR" for fr, "en-US" for en...) and the currency "EUR". A field of type number is shown by the browser, in its own locale, whatever this one.

      Parameters

      • locale: string

        "fr-CH", "en-GB"...; null: the one of the language again

      • Optionalcurrency: string

        "CHF", "USD"...; not given: the currency does not change

      Returns void

      Application.setLocale( "fr-CH", "CHF" );
      
    • Selects the theme of the page: the class x4theme-<name> on <html>, in place of the one of the theme before.

      • "": the light theme of x4, the one by default: no class.
      • "dark": the dark theme of x4, like the theme Dark Modern of VS Code (html.x4theme-dark in themes.scss).
      • any other name: a theme of the application, defined in its own css under html.x4theme-<name>, with the variables of themes.scss it changes.

      Parameters

      • name: string

        the name of the theme; "" for the light theme.

      Returns void

      Application.setTheme( "dark" );		// the dark theme of x4
      Application.setTheme( "pink" ); // html.x4theme-pink { --color-primary-a0: ...; } in the css of the application
      Application.setTheme( "" ); // back to the light theme