function updateStatus() { $.ajax({ dataType: "json", url: "api/status/", success: function(data, status, xhr) { $('#userName').text(data.name); if (!data.active) { showstatus(data.activestatus, 'warning'); } else { $('#statusdiv').hide(); } }, error: function(xhr, status, thrown) { show_ajax_error('loading status', xhr); } }); } function format_datetime(d) { d = new Date(d); s = d.toISOString(); return s.substring(0,10) + ' ' + s.substring(11, 19); } function reset_state(leave_completed) { if (!leave_completed) $('#completed_div').hide(); $('div.approw').hide(); $('div#buttonrow').show(); $('input[type=submit]').attr('disabled', null); $('.cancelButton').attr('disabled', null); scanner = $('#qrpreview').data('scanner'); if (scanner) { scanner.stop(); } } function showstatus(msg, level) { $('#statusdiv').text(msg); $('#statusdiv').attr('class', 'alert alert-' + level); if (level == 'success') { $('#statusdiv').fadeIn(200).fadeOut(200).fadeIn(200); } else { $('#statusdiv').fadeIn(200).fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200); } } function show_ajax_error(type, xhr) { if (xhr.status == 412) { /* 412 Precondition Failed is a controlled error from the backend code */ showstatus('Error ' + type + ': ' + xhr.responseText, 'danger'); } else { showstatus('Error ' + type + ': ' + xhr.status, 'danger'); } } function add_dynamic_fields(reg, cl, regcompleted) { $('.found_dyn').remove(); if (reg.note) { $('#scan_note').val(reg.note); } else { $('#scan_note').val(''); } let elements = []; scanfields.forEach(function(a) { let val = \u6865.getProperty(reg,a[0]); if (val && val.length > 0) { elements.push($('
').text(a[1]).addClass('found_dyn')); if (typeof(val) == 'string') { let e = $('
').text(val).addClass('found_dyn'); if (val.includes(' NOT ')) { e = $(e).addClass('found_dyn_warn'); } elements.push(e); } else { elements.push($('
').html($('