2022.2

Table Of Contents
class.Intheeventhandlerfortheolcotgsavestateevent,thejQueryeach()methodisusedtoiter-
ateoverallinputsthathavethisclass,storingtheirnameandvalueinanobject.
Next,thisobjectisstored-inJSONformat-intheevent.detail.statedatawiththekeymy-cam-
era-data.
window.addEventListener('olcotgsavestate', function(event) {
var camObj = {};
$('input.camera-dyn').each(function(){
var camera = $(this).attr('name');
var val = $(this).val();
camObj[camera] = val;
});
event.detail.state['my-camera-data'] = JSON.stringify(camObj);
});
IntheolcotgrestorestateeventhandlerthepreviouslystoredJSONisreadfromtheevent.-
detail.stateandparsedintoaJavaScriptobject.Afor ... inloopisthenusedtoiterateover
thekeys(thecameranames)inthatobject.Insidethisloopthecamerasareaddedbycallingthe
addCamera()functionwiththeIDandvalue(thepathtothepicture)ofeachCameraelement.Sub-
sequentlytherestore-state.cotgeventofthenewwidgetiscalledtomakesurethatthethumb-
nailofthepictureisshownandtheClearbuttonbecomesvisible.
window.addEventListener('olcotgrestorestate', function(event) {
var json = JSON.parse(event.detail.state['my-camera-data']);
for (var cameraID in json) {
var value = json[cameraID];
addCameraWidget(cameraID,value);
$('#' + cameraID).trigger('restore-state.cotg', event.detail.state);
}
});
function addCameraWidget(cameraID, value) {
if(typeof value == 'undefined') {
value = '';
}
var html = '<label>Camera' +
'<div id="' + cameraID + '" role="cotg.PhotoWidget">' +
'<div class="panel" role="control-wrapper" style="position:relative;">' +
'<img role="photo" src="">' +
'<input role="photo-data" class="camera-dyn" name="' + cameraID + '" type="hidden" value="' + value + '">' +
'</div>' +
'<button class="small" role="take-button" type="button">Take now</button>' +
'<button class="small" role="pick-button" type="button">Library</button>' +
'<button class="small" role="clear-button" type="button">Clear</button>' +
'</div></label>';
$('#cameras').append(html); // add the camera object to the DOM
$('#' + cameraID).cotgPhotoWidget(); // init COTG widget
Using submitted COTG data in a template
WhenausersubmitsaCaptureOnTheGoForm,theWorkflowprocessthatreceivesthedatamay
storetheinformationinadatabaseand/orpushitintootherWorkflowprocesses.Itcould,forexample,
sendaletteroranemailreceiptthatispersonalizedwiththesubmitteddata.Thatletteroremailwould
needtobeproducedusingatemplatethatincorporatesthesubmitteddata.
FollowthesestepstodevelopatemplatethatusessubmittedCOTGdata.
Page 554