Class: Page

jrt.Page(elementnon-null)

This class handles page events for a page element. A page element is a SECTION element that is a direct child of the BODY element and has a unique ID. This element will be made visible when navigating to the page.

When navigating to a page for the first time, an instance of its class is created. Afterwards, all page events for that page are sent to that instance. You must override this class in order to handle those events (the base implementations do nothing).

Note that, if you navigate to a page using a link, the page will always be scrolled to the top of its SECTION element's padding box (or to the window top, as long as the page has no top margin).

Constructor

new Page(elementnon-null)

Parameters:
Name Type Description
element HTMLElement
Implements:

Extends

Members

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

Reference to the app instance, just for convenience.

Type:
Overrides:

(nullable) caller :jrt.Target

The target that called this target for the last time.

Type:
Inherited From:
Implements:

(constant, non-null) element :HTMLElement

The HTML element represented by this instance.

Type:
  • HTMLElement
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:
Implements:

(non-null) req :jrt.AppRequest

The request that activated this target.

Type:
Inherited From:
Implements:

Methods

actionFinished(actionnon-null)

This method is called when an action that was requested from this target is finished explicitly with the jrt.Action#finish method.

This base implementation does nothing. Override as needed.

Parameters:
Name Type Description
action jrt.Action
Inherited From:
Implements:

dialogClosed(dialognon-null)

This method is called when a dialog that was opened from this target is closed. A dialog is usually closed by submitting a form with the "dialog" method. It can also be closed with jrt.Modal#close or with a #back URL.

This base implementation does nothing. Override as needed.

Parameters:
Name Type Description
dialog jrt.Modal
Inherited From:
Implements:

getParentId() → (nullable) {string}

Returns the hierarchical parent of this page. This method is used by jrt.App#navigateBack to determine what page to go back to. This base implementation returns null.

Returns:
Type
string

(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:

hidden()

This method is called when a view is hidden. If the view being hidden is a page, this is called before the jrt.Page#requested method of the page to be shown.

Implements:

(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>

requested()

This method is called when this target is requested. The request object can be found in the req property.

If this is a view, this method is called before the jrt.TargetView#shown method. You may cancel the request (thus preventing the view from showing) by calling jrt.App#navigateBack from this method. If this is a dialog, you can also do this by calling jrt.Dialog#close. The request can also be cancelled in this way from jrt.App#pageRequested and jrt.App#dialogRequested.

If this is a page, you can redirect the request by calling jrt.App#navigateTo from this method (you can also do this from jrt.App#pageRequested).

This base implementation does nothing.

Inherited From:
Implements:

(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

shown()

This method is called when a view has just been made visible, after a request to this target. The request object can be found in the req property. Note that this method will not be called when a view is reloaded.

Implements:

toString()

Inherited From: