Zymonic Web UI and Javascript Implementation

From Zymonic

Zymonic Web UI and Javascript Implementation[edit]

Zymonic Javascript[edit]

Zymonic Javascript is mostly object oriented and contained in a Zymonic. namespace; there are exceptions to this but they are in the process of being removed.

Handling XML Communications[edit]

Since most Zymonic communication is done with XML the usual 'flow' is to make a request with:

 Zymonic.request(type, form_data, async, request_key, request_type, success_cb, error_cb, expected_errors, loading_function)  
 type = POST or GET
 form_data = a form data object generated with Zymonic.new_form_data and Zymonic.assemble_form_data
 async = true or false (usually true to allow the UI to continue operating)
 request_key = a key that can be used to subsequently cancel a request
 request_type = combined with request key to cancel requests
 success_cb = function to run on success
 error_cb = functions to run on error (HTTP error)
 expected_errors = NOT USED
 loading_function = is a function that will run if the user has to 'relogin' (note that relogin will automatically re-run the original request and re-run the success function).

The success_cb often includes the use of Zymonic.Transformer's XMLErrHandle method to pre-process the XML and detect session timeouts and other Zymonic session messages - however, this is not necessary if using Zymonic.request since Zymonic.request automatically passes the XML through XMLErrHandle.

The following is an example of using the Object Oriented form of Transformer to transform the XML to HTML and insert it into the document (notice the use of xt.XMLErrHandle):

                var zt = new Zymonic.Transformer.Transformer({blockxml: xml});
		if(zt.XMLErrHandle(function(dxml) { Zymonic.newBlockCB(dxml, block_id); }, loading_function )) {
		/* Transform the XML */

			if (zt.block_deleted) {
				$('#block_' + block_id).remove();
			} else {
				$('#block_' + block_id).replaceWith(zt.resultDocument);

				//Re-run any JS that has not been run
				Zymonic.Utils.reRunJS($('#block_' + zt.block_id));
			}
		}

The following is an example of using the Transformer object to check for 'routine' Zymonic XML errors and handle them (and if not then pass the xml through to be handled - in this case by process filter data).

    var zt = new Zymonic.Transformer.Transformer();
	if (zt.XMLErrHandle( 
			function(dxml) { thisfilter.processNoData( dxml, no_transform); }, undefined, xml, this.block_id)) {

		// may have collapsed a group that had all per record filter actions
		this.updateFilterActions(this.ident);
	}

In non-communications cases then Transformer can be used as follows:

	var zt = new Zymonic.Transformer.Transformer();
	var doc = zt.TransformXML(xml);

Session Expiry in the Web UI (Miscfunctions.js version)[edit]

If the server detects that a request has been received after a session has timed out but before the 'relogin' window is expired then it will log all the sent parameters into a table and return a 'stored params ID' (SSPID).

If zt.XMLErrHandle detects an SSPID and 'session expired' message then it will pass the 'cont function' that was passed to zt.XMLErrHandle to a 'relogin' method (along with the SSPID and other parameters).

The relogin function will do two things, firstly, if another relogin function is not running then it will allow the user to re-authenticate, secondly (regardless of whether the user is re-authenticating via another instance) the function will create a new rRequest object (re-request) with the sspid and the continue function and add it to a global array of re-request (rRequest) objects.

If the user succeeds in re-authenticating then the success of the relogin will run all of the rRequest objects' methods.

Session Expiry in the Web UI (Desktop version - proposed)[edit]

The Zymonic class holds a server side session expiry time and relogin expiry timeout additionally there will be a method attached to each of the two timeouts; at session expiry the method will obscure the blocks on screen and present the user with a UI to enter their password (to re-authenticate), at relogin expiry the method will redirect the user to the home page.

The Zymonic.request method will not send requests to the server after the server side session expiry, instead it will store them ready to send if the user succesfully re-authenticates.

Each time XMLErrorHandle is used it will update the server side session expiry time and relogin expiry timeout.

Additionally, each time the user 'interacts' (mouse move? mouse click) with the UI, even if the interaction does not result in a Zymonic request then if the session expiry is within (X?) seconds then the JS will send a ping request to keep the session alive.

Opening a Block[edit]

Opening a block should be done with Zymonic.openBlock - an example, with additional parameters, follows...

var extras = {};
			
			// add main value field mappiung
			if (value_destination_field_zname != '') {
				Zymonic.addOpenBlockParam(extras, target_location, value_destination_field_zname, getZymonicField(field_ident).getValue());
			}
			
			// add field maps
			for (var i=0; i<field_maps.length; ++i) {
				Zymonic.addOpenBlockParam(extras, 
						                  target_location, 
						                  ( field_maps[i].destination_field ? field_maps[i].destination_field : field_maps[i].destination_parameter ),
						                  ( field_maps[i].source_field_ident ? getZymonicField(field_maps[i].source_field_ident).getValue() : field_maps[i].static_value ) );
			}
			
			Zymonic.openBlock(fop_zname, 0, fop_type, target_location, extras);