Zymonic Web UI and Javascript Implementation
Zymonic Web UI and Javascript Implementation
Zymonic Javascript
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
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 following is an example of using the Object Oriented form of Transformer:
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 Transformer in a non-OO style:
var zt = new Zymonic.Transformer.Transformer(); var doc = zt.TransformXML(xml);
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); }
Opening a Block
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);