01.06.2013 Views

OpenEdge Development: Mobile Applications - Product ...

OpenEdge Development: Mobile Applications - Product ...

OpenEdge Development: Mobile Applications - Product ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Managing JSDO event subscriptions<br />

JSDO overview<br />

You can subscribe event handlers to JSDO events using either the subscribe( )<br />

method on the JSDO or by setting appropriate properties in an initialization object that<br />

you can pass to the constructor to instantiate the JSDO. If you use the subscribe( )<br />

method after the JSDO is instantiated and its local storage has been loaded with<br />

records, you can also subscribe to events for the <strong>Mobile</strong> create, update, and delete<br />

operations that execute only for a specific table reference.<br />

When you subscribe an event handler function to a JSDO event, the parameter list for<br />

the function must match the parameter list defined for the event. However, every event<br />

handler receives a reference to the JSDO as its first parameter and a reference to a<br />

request object as its last parameter that contains event results (see the following<br />

section). All handlers for 'after*' events receive a Boolean parameter that indicates<br />

the success of the <strong>Mobile</strong> operation (or operations for 'afterSaveChanges'). All<br />

handlers for events fired by <strong>Mobile</strong> create, update, and delete operations receive a<br />

JSRecord object parameter that represents the record object in local storage that is<br />

created, updated, or deleted. For more information on the required parameter list for<br />

each event, see the reference entry for the event in Appendix C, “<strong>OpenEdge</strong><br />

JavaScript Class Properties, Methods, and Events Reference.”<br />

Regardless of how you subscribe event handlers to an event, you can remove an event<br />

subscription for an event handler using the unsubscribe( ) method. If an event has<br />

no event handler subscribed and the event fires, it returns no results to the <strong>Mobile</strong> App.<br />

Handling asynchronous and synchronous execution results<br />

For the synchronous JSDO methods (such as add( ) or find( )) that do not execute<br />

<strong>Mobile</strong> operations, the results for both successful and unsuccessful execution are as<br />

defined for each method. For more information, see the reference entry for the method<br />

in Appendix C, “<strong>OpenEdge</strong> JavaScript Class Properties, Methods, and Events<br />

Reference.”<br />

For methods that execute <strong>Mobile</strong> operations asynchronously (fill( ),<br />

saveChanges( ), and invocation methods), the results for each event are returned in<br />

a general request object that is passed as the last parameter to the event handler. For<br />

invocation methods that you execute synchronously, a reference to this same request<br />

object is available as the return value of the method. This request object has a number<br />

of properties whose values depend on the event. Some properties (including the jsdo,<br />

jsrecord, and success properties) duplicate the settings of the other parameters<br />

passed to the event handler. The settings of other properties provide additional<br />

information appropriate for the event.<br />

One of the most important is the response property of the request object. This property<br />

is set only for the 'after*' events of all <strong>Mobile</strong> operations (that is, all except the<br />

'afterSaveChanges' event). It references a JavaScript object that a <strong>Mobile</strong> operation<br />

returns for a successful completion or with ABL errors.<br />

For a built-in <strong>Mobile</strong> operation that completes successfully, this property references a<br />

JavaScript object that contains the data of the returned temp-table or ProDataSet<br />

converted from any valid JSON returned for the operation over the network, and is<br />

otherwise null.<br />

<strong>OpenEdge</strong> ® <strong>Development</strong>: <strong>Mobile</strong> <strong>Applications</strong> 101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!