Class: Modal

(protected) jrt.Modal(elementopt, nullable)

Base class for modal dialogs (or simply "dialogs"), backed by a DIALOG element. A dialog can be opened by following a hash URL, but it does not participate in URL navigation (it's not saved the browser's history).

A dialog is normally closed by submitting a form with the "dialog" method. In this base implementation, the returnValue property receives the value of the submit buttonthat was activated. Subclasses can change this by implementing setReturnValue.

A dialog can also be closed with the #back URL, with the close method and with the jrt.App#navigateBack method.

Constructor

Creates a dialog object for the specifed DIALOG element. If no element is specified, one is created and added to the BODY element (and removed when the dialog is closed).

Parameters:
Name Type Attributes Description
element HTMLDialogElement <optional>
<nullable>

Extends

Members

(protected, constant, non-null) app :jrt.App

Reference to the app instance, just for convenience.

Type:
Overrides:

(protected, constant) dynamic :boolean

Type:
  • boolean

(constant, non-null) element :HTMLDialogElement

The HTML element represented by this instance.

Type:
  • HTMLDialogElement
Overrides:

(nullable) form :jrt.Form

The first FORM element present in this view.

Type:
Overrides:

(constant) id :string

The view id, which is the same as the element id.

Type:
  • string
Overrides:

(nullable) parent :jrt.View

The view that opened this dialog (which is also the view that lays behind it).

Type:

(nullable) returnValue :jrt.DialogReturnValue

The return value for the dialog. It can be set with close or by submitting a form with the "dialog" method from within the dialog. If not set, it will be null.

Type:

Methods

(static) close(returnValueopt, nullable) → {boolean}

Closes the topmost open modal dialog, if there is one. If no return value is specified, the closed dialog's current return value remains.

Parameters:
Name Type Attributes Description
returnValue jrt.DialogReturnValue <optional>
<nullable>

The return value for the dialog.

Returns:

True if a dialog has been actually closed, false if no dialog was open.

Type
boolean

close(returnValueopt, nullable) → {boolean}

Closes the modal dialog. If no return value is specified, the current return value remains.

Parameters:
Name Type Attributes Description
returnValue jrt.DialogReturnValue <optional>
<nullable>

The return value for the dialog.

Returns:

true If the dialog was actually closed.

Type
boolean

(protected) handleEvent(enon-null, labelnullable)

This method is called when an event registered with listenToEvent is triggered.

Parameters:
Name Type Attributes Description
e Event

The event object.

label string <nullable>

The label specified when registering the event.

Overrides:

(protected) ignoreEvent(eventType, elementopt, nullable)

Stops listenig to the specified event type on the specified element.

Parameters:
Name Type Attributes Description
eventType string

The event type to listen to.

element Element <optional>
<nullable>

The HTML element to stop listening to. Defaults to this element.

Overrides:

isVisible() → {boolean}

Returns whether the view is currently visible.

Overrides:
Returns:
Type
boolean

(protected) listenToEvent(eventType, elementopt, nullable, labelopt, nullable, useCaptureopt)

Sets this object as the event listener for the specified event type and element. The handleEvent method is called when the event occurs.

Parameters:
Name Type Attributes Description
eventType string

The event type to listen to.

element Element <optional>
<nullable>

The HTML element to listen to. Defaults to this element.

label string <optional>
<nullable>

Optional label passed to the event handler.

useCapture boolean <optional>
Overrides:

(protected) processResponse(reqnon-null, status, responsenullable)

Implement this method to process the response received after a call to sendRequest. The response data type depends on the responseType property specified in the request.

The response status can be "success", "server-error", "type-error" (when the specified response type does not match the received data), "error" (if there is a connection error), "timeout" or "offline". Note that the "offline" status is not reliable in all devices, so an "error" status may be received when offline.

The default implementation does nothing.

Parameters:
Name Type Attributes Description
req jrt.AjaxRequest

The request object.

status string

The response status (see method description).

response jrt.AjaxResponse <nullable>

The server response. This will be null on error or timeout.

Overrides:

query(selector, baseElement) → (nullable) {HTMLElement}

Returns the first element that matches the specified selector. If no base element is specified, this block is used as base element. Returns null if no element is found.

Parameters:
Name Type Description
selector string

The CSS selector.

baseElement HTMLElement | DocumentFragment

Optional base element.

Overrides:
Returns:
Type
HTMLElement

queryAll(selector, baseElement) → (non-null) {NodeList.<!HTMLElement>}

Returns all elements that match the specified selector. If no base element is specified, this element is used.

Parameters:
Name Type Description
selector string

The CSS selector.

baseElement HTMLElement | DocumentFragment

Optional base element.

Overrides:
Returns:
Type
NodeList.<!HTMLElement>

(protected) sendRequest(reqnon-null)

Sends an asynchronous AJAX request to the URL specified in req'. The supported methods are "GET" (the default), "POST", "PUT", "PATCH", "DELETE" and "HEAD". The response will be passed to processResponse. The expected response type can be specified with the responseType property in the specified request ("json" by default).

Parameters:
Name Type Description
req jrt.AjaxRequest
Overrides:
Throws:

If any of the request parameters is invalid.

Type
Error

show()

Shows the modal dialog. If a dialog box is already open, it is closed first.

This method adds the "modal" token to the BODY element's class. Also, if the body has scroll, it also adds the "scroll" token.

toString()

Inherited From: