/*----------------------------------------------------------------------------------| www.giz.de |----/ Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb /-------------------------------------------------------------------------------------------------------/ @version 3.4.1 @build 14th May, 2016 @created 15th June, 2012 @package Cost Benefit Projection @subpackage health_data.js @author Llewellyn van der Merwe @owner Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb @copyright Copyright (C) 2015. All Rights Reserved @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html /-------------------------------------------------------------------------------------------------------/ Cost Benefit Projection Tool. /------------------------------------------------------------------------------------------------------*/ jQuery(document).ready(function() { var values_a = jQuery('#jform_maledeath').val(); if (values_a) { values_a = jQuery.parseJSON(values_a); buildTable(values_a,'jform_maledeath'); } var values_b = jQuery('#jform_femaledeath').val(); if (values_b) { values_b = jQuery.parseJSON(values_b); buildTable(values_b,'jform_femaledeath'); } var values_c = jQuery('#jform_maleyld').val(); if (values_c) { values_c = jQuery.parseJSON(values_c); buildTable(values_c,'jform_maleyld'); } var values_d = jQuery('#jform_femaleyld').val(); if (values_d) { values_d = jQuery.parseJSON(values_d); buildTable(values_d,'jform_femaleyld'); } }); function buildTable(array,id){ jQuery('#table_'+id).remove(); jQuery('#'+id).closest('.control-group').append(''); jQuery('#table_'+id).append(tableHeader(array)); jQuery('#table_'+id).append(tableBody(array)); jQuery('#table_'+id).append('
'); } function tableHeader(array) { var header = ''; jQuery.each(array, function(key, value) { header += ''+capitalizeFirstLetter(key)+''; }); header += ''; return header; } function tableBody(array) { var body = ''; var rows = new Array(); jQuery.each(array, function(key, value) { jQuery.each(value, function(i, line) { if( rows[i] === undefined ) { rows[i] = '' + line + ''; } else { rows[i] = rows[i] + '' + line + ''; } }); }); // now load to body the rows jQuery.each(rows, function(a, row) { body += '' + row + ''; }); body += ''; return body; } function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); }