Cost-Benefit-Projection/admin/models/forms/health_data.js

100 lines
3.1 KiB
JavaScript

/*----------------------------------------------------------------------------------| www.giz.de |----/
Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb
/-------------------------------------------------------------------------------------------------------/
@version 3.3.7
@build 28th February, 2016
@created 15th June, 2012
@package Cost Benefit Projection
@subpackage health_data.js
@author Llewellyn van der Merwe <http://www.vdm.io>
@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('<table style="margin: 5px 0 20px;" class="table" id="table_'+id+'">');
jQuery('#table_'+id).append(tableHeader(array));
jQuery('#table_'+id).append(tableBody(array));
jQuery('#table_'+id).append('</table>');
}
function tableHeader(array)
{
var header = '<thead><tr>';
jQuery.each(array, function(key, value) {
header += '<th style="padding: 10px; text-align: center; border: 1px solid rgb(221, 221, 221);">'+capitalizeFirstLetter(key)+'</th>';
});
header += '</tr></thead>';
return header;
}
function tableBody(array)
{
var body = '<tbody>';
var rows = new Array();
jQuery.each(array, function(key, value) {
jQuery.each(value, function(i, line) {
if( rows[i] === undefined ) {
rows[i] = '<td style="padding: 10px; text-align: center; border: 1px solid rgb(221, 221, 221);">' + line + '</td>';
}
else
{
rows[i] = rows[i] + '<td style="padding: 10px; text-align: center; border: 1px solid rgb(221, 221, 221);">' + line + '</td>';
}
});
});
// now load to body the rows
jQuery.each(rows, function(a, row) {
body += '<tr>' + row + '</tr>';
});
body += '</tbody>';
return body;
}
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}