Skip to content

@serenity-is/corelib / ImageUploadEditor

Class: ImageUploadEditor<P>

Defined in: src/ui/editors/uploadeditors.tsx:482

An editor that uploads and displays a single image.

Extends

Type Parameters

P

P extends ImageUploadEditorOptions = ImageUploadEditorOptions

Widget props type.

Constructors

Constructor

new ImageUploadEditor<P>(props): ImageUploadEditor<P>

Defined in: src/ui/editors/uploadeditors.tsx:489

Creates an image upload editor.

Parameters

props

EditorProps<P>

Widget props.

Returns

ImageUploadEditor<P>

Overrides

FileUploadEditor.constructor

Properties

compact

protected compact: boolean

Defined in: src/ui/editors/uploadeditors.tsx:475

Whether the editor has no toolbar, but the drop box and the menu on the corner of the file.

Inherited from

FileUploadEditor.compact


domNode

readonly domNode: HTMLElement

Defined in: src/ui/widgets/widget.ts:98

The DOM node this widget is bound to.

Inherited from

FileUploadEditor.domNode


dropHint

protected dropHint: HTMLButtonElement

Defined in: src/ui/editors/uploadeditors.tsx:473

Inherited from

FileUploadEditor.dropHint


entity

protected entity: UploadedFile

Defined in: src/ui/editors/uploadeditors.tsx:467

Inherited from

FileUploadEditor.entity


fileSymbols

protected fileSymbols: HTMLElement

Defined in: src/ui/editors/uploadeditors.tsx:470

Inherited from

FileUploadEditor.fileSymbols


hiddenInput

protected hiddenInput: HTMLInputElement

Defined in: src/ui/editors/uploadeditors.tsx:472

Inherited from

FileUploadEditor.hiddenInput


idPrefix

readonly idPrefix: string

Defined in: src/ui/widgets/widget.ts:96

The id prefix used for this widget's child element ids.

Inherited from

FileUploadEditor.idPrefix


options

protected readonly options: WidgetProps<EditorProps<P>>

Defined in: src/ui/widgets/widget.ts:92

The widget's options/props.

Inherited from

FileUploadEditor.options


progress

protected progress: HTMLElement

Defined in: src/ui/editors/uploadeditors.tsx:469

Inherited from

FileUploadEditor.progress


toolbar

protected toolbar: Toolbar

Defined in: src/ui/editors/uploadeditors.tsx:468

Inherited from

FileUploadEditor.toolbar


uniqueName

readonly uniqueName: string

Defined in: src/ui/widgets/widget.ts:94

A unique name for this widget instance, used for event namespacing.

Inherited from

FileUploadEditor.uniqueName


uploadInput

protected uploadInput: Fluent

Defined in: src/ui/editors/uploadeditors.tsx:471

Inherited from

FileUploadEditor.uploadInput


[typeInfo]

static [typeInfo]: EditorTypeInfo<"Serenity.">

Defined in: src/ui/editors/uploadeditors.tsx:483

Overrides

FileUploadEditor.[typeInfo]


defaultDeferInit

static defaultDeferInit: boolean = false

Defined in: src/ui/widgets/widget.ts:106

Whether the classes that neither have a DeferInitAttribute (see Attributes.deferInit) nor override deferredInit, nor have a base class that says true or false, defer their initialization; false by default. An application whose widgets are written for deferred initialization turns it on in its script init, before any widget is created.

Inherited from

FileUploadEditor.defaultDeferInit


defaults

static defaults: Pick<FileUploadEditorOptions, "toolbar"> = {}

Defined in: src/ui/editors/uploadeditors.tsx:91

The defaults of the options of the single file and image upload editors, e.g. toolbar, which an option of an editor overrides.

Inherited from

FileUploadEditor.defaults


isComponent

readonly static isComponent: true = true

Defined in: src/ui/widgets/widget.ts:530

Inherited from

FileUploadEditor.isComponent

Accessors

element

Get Signature

get element(): Fluent

Defined in: src/ui/widgets/widget.ts:216

Returns a Fluent(this.domNode) object

Returns

Fluent

Inherited from

FileUploadEditor.element


initialized

Get Signature

get protected initialized(): boolean

Defined in: src/ui/widgets/widget.ts:137

Whether the widget is initialized: always for one that initializes in its constructor, and for one that defers its initialization (see isDeferredInit), once its deferredInit is done.

Returns

boolean

Inherited from

FileUploadEditor.initialized


props

Get Signature

get props(): WidgetProps<P>

Defined in: src/ui/widgets/widget.ts:503

Returns the widget's props/options.

Returns

WidgetProps<P>

Inherited from

FileUploadEditor.props


readOnly

Get Signature

get readOnly(): boolean

Defined in: src/ui/editors/editorwidget.ts:42

Returns whether the editor is read-only.

Returns

boolean

True when read-only.

Set Signature

set readOnly(value): void

Defined in: src/ui/editors/editorwidget.ts:48

Sets whether the editor is read-only.

Parameters
value

boolean

Returns

void

Inherited from

FileUploadEditor.readOnly


usesDeferredInit

Get Signature

get protected usesDeferredInit(): boolean

Defined in: src/ui/widgets/widget.ts:129

Whether this widget defers its initialization, see isDeferredInit.

Returns

boolean

Inherited from

FileUploadEditor.usesDeferredInit


value

Get Signature

get value(): UploadedFile

Defined in: src/ui/editors/uploadeditors.tsx:386

Returns the current uploaded file.

Returns

UploadedFile

The uploaded file.

Set Signature

set value(v): void

Defined in: src/ui/editors/uploadeditors.tsx:426

Sets the uploaded file.

Parameters
v

UploadedFile

The uploaded file to set.

Returns

void

Inherited from

FileUploadEditor.value

Methods

addCssClass()

protected addCssClass(): void

Defined in: src/ui/widgets/widget.ts:223

Adds the widget's CSS class to its DOM node.

Returns

void

Inherited from

FileUploadEditor.addCssClass


addFileButtonText()

protected addFileButtonText(): string

Defined in: src/ui/editors/uploadeditors.tsx:202

Returns the text for the add-file button.

Returns

string

The button text.

Inherited from

FileUploadEditor.addFileButtonText


addValidationRule()

Call Signature

addValidationRule(rule, uniqueName?): void

Defined in: src/ui/widgets/widget.ts:267

Adds a validation rule to the widget's DOM node.

Parameters
rule

(input) => string

The validation rule function, or a unique name when the two-argument overload is used.

uniqueName?

string

A unique name for the rule, or the rule function when the two-argument overload is used.

Returns

void

Inherited from

FileUploadEditor.addValidationRule

Call Signature

addValidationRule(uniqueName, rule): void

Defined in: src/ui/widgets/widget.ts:268

Adds a validation rule to the widget's DOM node.

Parameters
uniqueName

string

A unique name for the rule, or the rule function when the two-argument overload is used.

rule

(input) => string

The validation rule function, or a unique name when the two-argument overload is used.

Returns

void

Inherited from

FileUploadEditor.addValidationRule


afterRender()

protected afterRender(callback): void

Defined in: src/ui/widgets/widget.ts:359

Queues a callback to run after the widget's contents are rendered.

Parameters

callback

() => void

The callback to run after rendering.

Returns

void

Inherited from

FileUploadEditor.afterRender


byId()

protected byId<TElement>(id): Fluent<TElement>

Defined in: src/ui/widgets/widget.ts:279

Finds a child element by its prefix-relative id.

Type Parameters

TElement

TElement extends HTMLElement = HTMLElement

Parameters

id

string

The id relative to the widget's id prefix.

Returns

Fluent<TElement>

A Fluent wrapper for the matching element.

Inherited from

FileUploadEditor.byId


change()

change(handler): void

Defined in: src/ui/widgets/widget.ts:310

Registers a change handler on the widget's DOM node.

Parameters

handler

(e) => void

The change event handler.

Returns

void

Inherited from

FileUploadEditor.change


changeSelect2()

changeSelect2(handler): void

Defined in: src/ui/widgets/widget.ts:319

Registers a change handler that ignores changes originating from combobox setting values.

Parameters

handler

(e) => void

The change event handler.

Returns

void

Inherited from

FileUploadEditor.changeSelect2


chooseFile()

protected chooseFile(): void

Defined in: src/ui/editors/uploadeditors.tsx:225

Opens the file chooser, as the add file button does.

Returns

void

Inherited from

FileUploadEditor.chooseFile


deferredInit()

protected deferredInit(): void | PromiseLike<void>

Defined in: src/ui/widgets/widget.ts:440

Does the initialization of a widget that defers it (see isDeferredInit), once, when init or initAsync is called after all its constructors are done. The base classes initialize what their constructors would, e.g. the contents, the form or the columns, and a subclass does the work its constructor would do after await super.deferredInit(), which may wait too. The part before its first await runs at once, so a widget that is made and inited has its contents.

Returns

void | PromiseLike<void>

Inherited from

FileUploadEditor.deferredInit


destroy()

destroy(): void

Defined in: src/ui/widgets/widget.ts:195

Destroys the widget, removing its association with the DOM node, its CSS classes and its event handlers.

Returns

void

Inherited from

FileUploadEditor.destroy


dropHintDetail()

protected dropHintDetail(): string

Defined in: src/ui/editors/uploadeditors.tsx:218

Returns the line under the text of the drop box, if any.

Returns

string

The detail of the drop hint, from the dropHintDetail option.

Inherited from

FileUploadEditor.dropHintDetail


dropHintText()

protected dropHintText(): string

Defined in: src/ui/editors/uploadeditors.tsx:210

Returns the text that the editor shows while it has no file.

Returns

string

The text of the drop hint.

Inherited from

FileUploadEditor.dropHintText


findById()

protected findById<TElement>(id): TElement

Defined in: src/ui/widgets/widget.ts:291

Finds a child element by its prefix-relative id.

Type Parameters

TElement

TElement extends HTMLElement = HTMLElement

Parameters

id

string

The id relative to the widget's id prefix.

Returns

TElement

The matching element, or null if not found.

Inherited from

FileUploadEditor.findById


get_readOnly()

get_readOnly(): boolean

Defined in: src/ui/editors/uploadeditors.tsx:324

Returns whether the editor is read-only.

Returns

boolean

True when read-only.

Inherited from

FileUploadEditor.get_readOnly


get_required()

get_required(): boolean

Defined in: src/ui/editors/uploadeditors.tsx:358

Returns whether the field is required.

Returns

boolean

True when required.

Inherited from

FileUploadEditor.get_required


get_value()

get_value(): UploadedFile

Defined in: src/ui/editors/uploadeditors.tsx:374

Returns the current uploaded file.

Returns

UploadedFile

The uploaded file, or null.

Inherited from

FileUploadEditor.get_value


getCssClass()

protected getCssClass(): string

Defined in: src/ui/widgets/widget.ts:231

Returns the CSS class(es) applied to the widget's DOM node.

Returns

string

The space-separated CSS class string.

Inherited from

FileUploadEditor.getCssClass


getCustomAttribute()

protected getCustomAttribute<TAttr>(attrType, inherit): TAttr

Defined in: src/ui/widgets/widget.ts:351

Returns a custom attribute applied to the widget's type.

Type Parameters

TAttr

TAttr extends CustomAttribute

Parameters

attrType

(...args) => TAttr

The attribute type to look up.

inherit

boolean = true

Whether to search inherited types; defaults to true.

Returns

TAttr

The matching attribute, or null.

Inherited from

FileUploadEditor.getCustomAttribute


getDefaultAllowNonImage()

protected getDefaultAllowNonImage(): boolean

Defined in: src/ui/editors/uploadeditors.tsx:499

Whether non-image files are allowed.

Returns

boolean

False for image editors.

Overrides

FileUploadEditor.getDefaultAllowNonImage


getEditValue()

getEditValue(property, target): void

Defined in: src/ui/editors/uploadeditors.tsx:435

Gets the edit value into a target object.

Parameters

property

PropertyItem

The property item.

target

any

The target object.

Returns

void

Inherited from

FileUploadEditor.getEditValue


getGridField()

getGridField(): Fluent

Defined in: src/ui/widgets/widget.ts:302

Returns the closest .field element containing the widget's DOM node.

Returns

Fluent

A Fluent wrapper for the grid field.

Inherited from

FileUploadEditor.getGridField


getToolButtons()

protected getToolButtons(): ToolButton[]

Defined in: src/ui/editors/uploadeditors.tsx:234

Returns the toolbar buttons for the editor.

Returns

ToolButton[]

Tool button definitions.

Inherited from

FileUploadEditor.getToolButtons


getUploadInputOptions()

protected getUploadInputOptions(): UploadInputOptions

Defined in: src/ui/editors/uploadeditors.tsx:165

Returns the upload input options.

Returns

UploadInputOptions

Upload input options.

Inherited from

FileUploadEditor.getUploadInputOptions


init()

init(): this

Defined in: src/ui/widgets/widget.ts:375

Initializes the widget: one that defers its initialization (see isDeferredInit) starts it, and it may end later, see initAsync; others are initialized by their constructors already.

Returns

this

This widget instance.

Inherited from

FileUploadEditor.init


initAsync()

initAsync(): Promise<ImageUploadEditor<P>>

Defined in: src/ui/widgets/widget.ts:388

Initializes the widget once and waits until it is initialized: one that defers its initialization (see isDeferredInit) runs its deferredInit, the first time it is called; others are initialized by their constructors.

Returns

Promise<ImageUploadEditor<P>>

A promise of this widget, which is rejected when its initialization fails.

Inherited from

FileUploadEditor.initAsync


initNow()

protected initNow(): boolean

Defined in: src/ui/widgets/widget.ts:146

Starts the initialization of a widget that defers it, if it hasn't started, and tells whether it is initialized now, e.g. as it had nothing to wait for. A method that needs the widget initialized waits for initAsync when it is not, e.g. if (!this.initNow()) return void this.initAsync().then(...).

Returns

boolean

Inherited from

FileUploadEditor.initNow


internalRenderContents()

internalRenderContents(): void

Defined in: src/ui/widgets/widget.ts:462

Renders the widget's contents and runs any queued after-render callbacks.

Returns

void

Inherited from

FileUploadEditor.internalRenderContents


legacyTemplateRender()

protected legacyTemplateRender(): boolean

Defined in: src/ui/widgets/widget.ts:487

Renders the widget from a legacy getTemplate string, if defined.

Returns

boolean

True if a legacy template was rendered.

Inherited from

FileUploadEditor.legacyTemplateRender


populate()

protected populate(): void

Defined in: src/ui/editors/uploadeditors.tsx:264

Populates the file symbols from the current entity.

Returns

void

Inherited from

FileUploadEditor.populate


removeFile()

protected removeFile(): void

Defined in: src/ui/editors/uploadeditors.tsx:151

Removes the file, as the delete button and the remove button by the file do.

Returns

void

Inherited from

FileUploadEditor.removeFile


render()

render(): any

Defined in: src/ui/widgets/widget.ts:449

Returns the main element for this widget or the document fragment. As widgets may get their elements from props unlike regular JSX widgets, this method should not be overridden. Override renderContents() instead.

Returns

any

Inherited from

FileUploadEditor.render


renderContents()

protected renderContents(): any

Defined in: src/ui/widgets/widget.ts:477

Renders the widget's contents. Override this to provide custom content.

Returns

any

The rendered contents.

Inherited from

FileUploadEditor.renderContents


renderFileMenu()

protected renderFileMenu(): HTMLElement

Defined in: src/ui/editors/uploadeditors.tsx:290

Renders the menu on the corner of the file, when the editor has no toolbar, which replaces and removes it. It is a dropdown of Bootstrap, like the field selection of the quick search.

Returns

HTMLElement

The menu.

Inherited from

FileUploadEditor.renderFileMenu


set_readOnly()

set_readOnly(value): void

Defined in: src/ui/editors/uploadeditors.tsx:332

Sets whether the editor is read-only.

Parameters

value

boolean

True to enable read-only mode.

Returns

void

Inherited from

FileUploadEditor.set_readOnly


set_required()

set_required(value): void

Defined in: src/ui/editors/uploadeditors.tsx:366

Sets whether the field is required.

Parameters

value

boolean

True when required.

Returns

void

Inherited from

FileUploadEditor.set_required


set_value()

set_value(value): void

Defined in: src/ui/editors/uploadeditors.tsx:394

Sets the uploaded file.

Parameters

value

UploadedFile

The uploaded file to set.

Returns

void

Inherited from

FileUploadEditor.set_value


setEditValue()

setEditValue(source, property): void

Defined in: src/ui/editors/uploadeditors.tsx:444

Sets the edit value from a source object.

Parameters

source

any

The source object.

property

PropertyItem

The property item.

Returns

void

Inherited from

FileUploadEditor.setEditValue


syncOrAsyncThen()

protected syncOrAsyncThen<T>(syncMethod, asyncMethod, then): void

Defined in: src/ui/widgets/widget.ts:514

Runs a method synchronously or asynchronously depending on the widget's useAsync flag, then invokes a continuation.

Type Parameters

T

T

Parameters

syncMethod

() => T

The synchronous method to run.

asyncMethod

() => PromiseLike<T>

The asynchronous method to run.

then

(v) => void

The continuation invoked with the result.

Returns

void

Inherited from

FileUploadEditor.syncOrAsyncThen


updateInterface()

protected updateInterface(): void

Defined in: src/ui/editors/uploadeditors.tsx:308

Updates the interface to reflect the current state.

Returns

void

Inherited from

FileUploadEditor.updateInterface


useIdPrefix()

protected useIdPrefix(): IdPrefixType

Defined in: src/ui/widgets/widget.ts:525

Returns an id prefix helper for resolving child element ids.

Returns

IdPrefixType

An IdPrefixType proxy for this widget's id prefix.

Inherited from

FileUploadEditor.useIdPrefix


useToolbar()

protected useToolbar(buttons): boolean

Defined in: src/ui/editors/uploadeditors.tsx:144

Returns whether the editor shows its toolbar instead of the drop box and the buttons by the file, see FileUploadEditorOptions.toolbar.

Parameters

buttons

ToolButton[]

The buttons of the toolbar, from getToolButtons.

Returns

boolean

True to show the toolbar.

Inherited from

FileUploadEditor.useToolbar


create()

static create<TWidget, P>(params): TWidget

Defined in: src/ui/widgets/widget.ts:333

Creates a widget instance from the given params, appending its element to the container and invoking the init/init callbacks.

Type Parameters

TWidget

TWidget extends Widget<P>

P

P

Parameters

params

CreateWidgetParams<TWidget, P>

The widget creation params.

Returns

TWidget

The created widget instance.

Inherited from

FileUploadEditor.create


createDefaultElement()

static createDefaultElement(): HTMLElement

Defined in: src/ui/widgets/widget.ts:209

Creates the default DOM element for a widget.

Returns

HTMLElement

A new div element.

Inherited from

FileUploadEditor.createDefaultElement


getWidgetName()

static getWidgetName(type): string

Defined in: src/ui/widgets/widget.ts:256

Returns the widget name for a type, used for association and unique names.

Parameters

type

Function

The widget type.

Returns

string

The widget name.

Inherited from

FileUploadEditor.getWidgetName


isDeferredInit()

static isDeferredInit(type, requested?): boolean

Defined in: src/ui/widgets/widget.ts:118

Gets whether a widget of a type defers its initialization to deferredInit, which init or initAsync runs once all the constructors are done, and which may wait. It is as the DeferInitAttribute (see Attributes.deferInit) of the type or a base class says, true for a class that overrides deferredInit, else as defaultDeferInit says. It throws when the type and its base classes say conflicting things, e.g. a class has false but overrides deferredInit.

Parameters

type

Function

The widget type.

requested?

boolean

Whether the creator of the widget asks for it, see WidgetProps.deferInit, which counts only for a class whose own attribute says "optional".

Returns

boolean

Inherited from

FileUploadEditor.isDeferredInit


registerClass()

protected static registerClass<TypeName>(typeName, intfAndAttr?): ClassTypeInfo<TypeName>

Defined in: src/ui/widgets/widget.ts:538

Registers this type as a class with the given type name.

Type Parameters

TypeName

TypeName

Parameters

typeName

StringLiteral<TypeName>

The type name to register.

intfAndAttr?

(InterfaceType | AttributeSpecifier)[]

Optional interfaces and attributes.

Returns

ClassTypeInfo<TypeName>

The class type info.

Inherited from

FileUploadEditor.registerClass


registerEditor()

protected static registerEditor<TypeName>(typeName, intfAndAttr?): EditorTypeInfo<TypeName>

Defined in: src/ui/widgets/widget.ts:553

Registers this type as an editor with the given type name.

Type Parameters

TypeName

TypeName

Parameters

typeName

StringLiteral<TypeName>

The type name to register.

intfAndAttr?

(InterfaceType | AttributeSpecifier)[]

Optional interfaces and attributes.

Returns

EditorTypeInfo<TypeName>

The editor type info.

Inherited from

FileUploadEditor.registerEditor