Class: Action

jrt.Action(id)

Base class for app actions.

An action is a type of jrt.Target and, as such, it can be requested by following a link or submitting a form (see jrt.HashUrl).

An action can also be executed from code with jrt.App.execute.

Constructor

new Action(id)

Parameters:
Name Type Description
id string
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:
Implements:

(constant) id :string

The target id.

Type:
  • string
Implements:

(non-null) req :jrt.AppRequest

The request that activated this target.

Type:
Implements:

result :*

This value is set when a value is passed to the finish method. If no value is passed, the result will be null.

Type:
  • *

running :boolean

True if this action is running. An action starts runnning when it is requested, and stops running when finish is called or a new page is requested.

Type:
  • boolean

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

(protected) finish(resultopt) → {boolean}

Ends execution of this action and calls the requester's jrt.Target#actionFinished method.

Parameters:
Name Type Attributes Default Description
result * <optional>
null

The action's result (null if not specified).

Returns:

True on success and false if the action is not running.

Type
boolean

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

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.

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

toString()