/** * @package eHealth Portal * * @created 13th August, 2020 * @author Llewellyn van der Merwe * @copyright Copyright (C) 2020 Vast Development Method. All rights reserved. * @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html * * Portal for mobile health clinics */ // set immunisation vaccine types that are on the page var select_an_immunisation_vaccine_type = 'Select...'; var create_an_immunisation_vaccine_type = 'Create...'; immunisation_vaccine_types = {}; var immunisation_vaccine_type = 0; jQuery(document).ready(function($) { // when it changes $('#adminForm').on('change', '#jform_administration_part',function (e) { e.preventDefault(); getImmunisationVaccineType(); }); // set buckets jQuery("#jform_immunisation_vaccine_type option").each(function() { var key = jQuery(this).val(); var text = jQuery(this).text(); immunisation_vaccine_types[key] = text; }); immunisation_vaccine_type = jQuery('#jform_immunisation_vaccine_type').val(); // run now getImmunisationVaccineType(); }); function getImmunisationVaccineTypeServer(administration_part){ var getUrl = JRouter("index.php?option=com_ehealthportal&task=ajax.getImmunisationVaccineType&raw=true&format=json"); if(token.length > 0 && administration_part > 0){ var request = 'token='+token+'&administration_part='+administration_part; } return jQuery.ajax({ type: 'GET', url: getUrl, dataType: 'json', data: request, jsonp: false }); } function getImmunisationVaccineType(){ jQuery("#loading").show(); // clear the selection jQuery('#jform_immunisation_vaccine_type').find('option').remove().end(); jQuery('#jform_immunisation_vaccine_type').trigger('liszt:updated'); // get administration part value if set var administration_part = jQuery('#jform_administration_part').val(); getImmunisationVaccineTypeServer(administration_part).done(function(result) { setImmunisationVaccineType(result); jQuery("#loading").hide(); if (typeof ImmunisationVaccineTypeButton !== 'undefined') { // ensure button is correct var immunisation_vaccine_type = jQuery('#jform_immunisation_vaccine_type').val(); ImmunisationVaccineTypeButton(immunisation_vaccine_type); } }); } function setImmunisationVaccineType(array){ if (array) { jQuery('#jform_immunisation_vaccine_type').append(''); jQuery.each( array, function( i, id ) { if (id in immunisation_vaccine_types) { jQuery('#jform_immunisation_vaccine_type').append(''); } if (id == immunisation_vaccine_type) { jQuery('#jform_immunisation_vaccine_type').val(id); } }); } else { jQuery('#jform_immunisation_vaccine_type').append(''); } jQuery('#jform_immunisation_vaccine_type').trigger('liszt:updated'); }