Zymonic Web UI and Javascript Implementation: Difference between revisions
Amasidlover (talk | contribs) |
Amasidlover (talk | contribs) |
||
Line 7: | Line 7: | ||
===Handling XML Communications=== |
===Handling XML Communications=== |
||
Since most Zymonic communication is done with XML the usual 'flow' is to make a request with |
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 |
type = POST or GET |
||
form_data = a form data object generated with Zymonic.new_form_data and Zymonic.assemble_form_data |
form_data = a form data object generated with Zymonic.new_form_data and Zymonic.assemble_form_data |
||
Line 18: | Line 19: | ||
expected_errors = NOT USED |
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). |
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 should be a method that includes the use of Zymonic.Transformer's XMLErrHandle method to pre-process the XML and detect session timeouts and other Zymonic session messages. |
|||
⚫ | |||
⚫ | |||
<pre> |
<pre> |
||
var zt = new Zymonic.Transformer.Transformer({blockxml: xml}); |
var zt = new Zymonic.Transformer.Transformer({blockxml: xml}); |
||
Line 35: | Line 37: | ||
} |
} |
||
} |
} |
||
⚫ | |||
The following is an example of using Transformer in a non-OO style: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
||
Line 53: | Line 49: | ||
} |
} |
||
</pre> |
</pre> |
||
In non-communications cases then Transformer can be used as follows: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
===Session Expiry in the Web UI=== |
|||
===Opening a Block=== |
===Opening a Block=== |
Revision as of 20:20, 29 December 2019
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 success_cb should be a method that includes the use of Zymonic.Transformer's XMLErrHandle method to pre-process the XML and detect session timeouts and other Zymonic session messages.
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
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);