formcycle 8.3.6 - JavaScript for forms
    Preparing search index...

    Interface AjaxUploadManager

    Manages all AJAX uploads and provides an API for checking the available uploads, as well as allowing for new uploads to be added programmatically.

    interface AjaxUploadManager {
        abortAll: (container?: ElementReference) => Promise<void>;
        addUpload: (
            element: ElementReference,
            data: Blob,
            fileName: string,
        ) => Promise<void>;
        awaitAll: (container?: ElementReference) => Promise<void>;
        disable: (container: ElementReference) => Promise<void>;
        enable: (container: ElementReference) => void;
        events: {
            begin: EventSource<
                ElementReference,
                { data: Blob; field: JQuery; fileName: string; id: string },
            >;
            cancel: EventSource<ElementReference, { field: JQuery; id: string }>;
            clearError: EventSource<ElementReference, { field: JQuery }>;
            complete: EventSource<
                ElementReference,
                { container: JQuery; field: JQuery },
            >;
            error: EventSource<
                ElementReference,
                { error: Error; field: JQuery; id: string },
            >;
            progress: EventSource<
                ElementReference,
                { field: JQuery; id: string; progress: UploadRatio },
            >;
            remove: EventSource<ElementReference, { field: JQuery; id: string }>;
            restore: EventSource<
                ElementReference,
                { field: JQuery; id: string; item: FileItem },
            >;
            success: EventSource<
                ElementReference,
                { field: JQuery; id: string; item: FileItem },
            >;
        };
        getPendingUploadCount: (container?: ElementReference) => number;
        getUpload: (container?: ElementReference) => FileItem;
        getUploads: (container?: ElementReference) => FileItem[];
        isAjaxUploadEnabled: (container: ElementReference) => boolean;
        removeUpload: (element: ElementReference) => Promise<void>;
        restoreUploads: (container: ElementReference) => void;
        stop: (container: ElementReference) => void;
    }
    Index

    Properties

    abortAll: (container?: ElementReference) => Promise<void>

    Type declaration

      • (container?: ElementReference): Promise<void>
      • Parameters

        • Optionalcontainer: ElementReference

          An optional container. When given, only abort all uploads within that element. Can be the upload element itself.

        Returns Promise<void>

        A promise that resolves once all uploads are done.

    addUpload: (
        element: ElementReference,
        data: Blob,
        fileName: string,
    ) => Promise<void>

    Type declaration

      • (element: ElementReference, data: Blob, fileName: string): Promise<void>
      • Parameters

        • element: ElementReference

          One or multiple upload elements.

        • data: Blob

          Data to upload.

        • fileName: string

          Name of the file.

        Returns Promise<void>

        An promise that resolves when alls uploads were added and uploaded successfully.

    awaitAll: (container?: ElementReference) => Promise<void>

    Type declaration

      • (container?: ElementReference): Promise<void>
      • Parameters

        • Optionalcontainer: ElementReference

          An optional container. When given, only waits until all uploads within that element have finished. Can be the upload element itself.

        Returns Promise<void>

        A promise that resolves when all uploads are done.

    disable: (container: ElementReference) => Promise<void>

    Disables the AJAX upload feature. Aborts all pending uploads, removes all finished uploads, and removes all listeners so that no new AJAX uploads are started.

    This must be called with the same container that was passed to AjaxUploadManager.enable.

    Type declaration

      • (container: ElementReference): Promise<void>
      • Parameters

        Returns Promise<void>

        A promise that resolves once all uploads are done.

    enable: (container: ElementReference) => void

    Registers the appropriate listeners for all AJAX enabled upload fields inside the given container. This uses event delegation, so you can add elements inside the container dynamically after calling this function.

    Type declaration

    events: {
        begin: EventSource<
            ElementReference,
            { data: Blob; field: JQuery; fileName: string; id: string },
        >;
        cancel: EventSource<ElementReference, { field: JQuery; id: string }>;
        clearError: EventSource<ElementReference, { field: JQuery }>;
        complete: EventSource<
            ElementReference,
            { container: JQuery; field: JQuery },
        >;
        error: EventSource<
            ElementReference,
            { error: Error; field: JQuery; id: string },
        >;
        progress: EventSource<
            ElementReference,
            { field: JQuery; id: string; progress: UploadRatio },
        >;
        remove: EventSource<ElementReference, { field: JQuery; id: string }>;
        restore: EventSource<
            ElementReference,
            { field: JQuery; id: string; item: FileItem },
        >;
        success: EventSource<
            ElementReference,
            { field: JQuery; id: string; item: FileItem },
        >;
    }

    An object with the event sources provided by the AJAX upload manager, such as when an upload begins, progresses, or was successful. You can subscribe or unsubscribe from these events.

    Type declaration

    • begin: EventSource<
          ElementReference,
          { data: Blob; field: JQuery; fileName: string; id: string },
      >

      When an upload was selected and the AJAX upload was started.

    • cancel: EventSource<ElementReference, { field: JQuery; id: string }>

      When a pending AJAX upload was cancelled, such as when the user presses the cancel button.

    • clearError: EventSource<ElementReference, { field: JQuery }>

      When the error message of failed upload was cleared.

    • complete: EventSource<ElementReference, { container: JQuery; field: JQuery }>

      When all pending AJAX uploads are complete, irrespective of how they completed (via success, failure, or by being aborted). Whenever an AJAX upload completes, this event is triggered with the closest parent DOM element of the completed AJAX upload that contains only completed AJAX uploads.

    • error: EventSource<ElementReference, { error: Error; field: JQuery; id: string }>

      When a file upload failed, such as due to a network failure or checksum mismatch.

    • progress: EventSource<
          ElementReference,
          { field: JQuery; id: string; progress: UploadRatio },
      >

      When a pending upload made progress. This event is triggered in semiregular intervals, but no guarantees are made as to the exact timing.

    • remove: EventSource<ElementReference, { field: JQuery; id: string }>

      When an uploaded AJAX file was removed, such as when the user presses the remove button.

    • restore: EventSource<ElementReference, { field: JQuery; id: string; item: FileItem }>

      When the AJAX file upload item was restored. This happens e.g. during server validation when the form is returned by the server.

    • success: EventSource<ElementReference, { field: JQuery; id: string; item: FileItem }>

      When a file was uploaded successfully.

    getPendingUploadCount: (container?: ElementReference) => number

    Type declaration

      • (container?: ElementReference): number
      • Parameters

        • Optionalcontainer: ElementReference

          An optional container. When given, only returns the count for the upload within that element. Can be the upload element itself.

        Returns number

        The number of pending uploads.

    getUpload: (container?: ElementReference) => FileItem

    Type declaration

      • (container?: ElementReference): FileItem
      • Parameters

        • Optionalcontainer: ElementReference

          An optional container. When given, restricts the search to that element. Can be an upload element itself.

        Returns FileItem

        The first upload item in the given container, or undefined when no such element exists.

    getUploads: (container?: ElementReference) => FileItem[]

    Type declaration

      • (container?: ElementReference): FileItem[]
      • Parameters

        • Optionalcontainer: ElementReference

          An optional container. When given, only returns the uploads within that element. Can be an upload element itself.

        Returns FileItem[]

        All upload items in the given container.

    isAjaxUploadEnabled: (container: ElementReference) => boolean

    Checks whether the AJAX feature is enabled for a given upload element. When this returns false, other methods such as getUpload should not be used.

    Type declaration

      • (container: ElementReference): boolean
      • Parameters

        • container: ElementReference

          A container with the upload, or the upload element itself.

        Returns boolean

        true when the element is an upload element and the AJAX upload feature is enabled for that element, false otherwise.

    removeUpload: (element: ElementReference) => Promise<void>

    Stops the upload if any upload is any progress, or removes the uploaded file if a file was uploaded.

    Type declaration

      • (element: ElementReference): Promise<void>
      • Parameters

        Returns Promise<void>

        A promise that resolves once all uploads were removed.

    restoreUploads: (container: ElementReference) => void

    Type declaration

    stop: (container: ElementReference) => void

    Removes all listeners so that no new AJAX uploads are started, keep pending and finished uploads. Useful e.g. when you want to wait until all uploads have finished, but do not want to allow new uploads to be initiated.

    This must be called with the same container that was passed to AjaxUploadManager.enable.

    Type declaration