/*----------------------------------------------------------------------------------| www.giz.de |----/ Deutsche Gesellschaft für International Zusammenarbeit (GIZ) Gmb /-------------------------------------------------------------------------------------------------------/ @version 3.3.0 @build 14th February, 2016 @created 15th June, 2012 @package Cost Benefit Projection @subpackage country.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_percentmale').val(); if (values_a) { values_a = jQuery.parseJSON(values_a); buildTable(values_a,'jform_percentmale'); } var values_b = jQuery('#jform_percentfemale').val(); if (values_b) { values_b = jQuery.parseJSON(values_b); buildTable(values_b,'jform_percentfemale'); } var valuesh_a = jQuery('#jform_maledeath').val(); if (valuesh_a) { valuesh_a = jQuery.parseJSON(valuesh_a); buildTable(valuesh_a,'jform_maledeath'); } var valuesh_b = jQuery('#jform_femaledeath').val(); if (valuesh_b) { valuesh_b = jQuery.parseJSON(valuesh_b); buildTable(valuesh_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); } function updateSelection(row) { var groupId = jQuery(row).find("select:first").attr("id"); var percentValue = jQuery(row).find(".text_area:first").val(); var arr = groupId.split('-'); if (arr[1] != 1) { var selection = {}; jQuery(row).find("select:first option").each(function() { // first get the values and text selection[jQuery(this).text()] = jQuery(this).val(); }); jQuery.each(AgeGroup, function(i, group){ jQuery(row).find("select:first option[value='"+group+"']").remove(); }); if (percentValue) { var text = jQuery(row).find(".chzn-single:first span").text(); jQuery(row).find("select:first").append(jQuery('