From 81a17654b0649188218dc7e7d9ab1d01be522c81 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Thu, 10 Dec 2015 16:33:53 +0100 Subject: [PATCH] Bug 15206 - CalculateAge in memberentry use C4::Members::GetAge() --- .../prog/en/modules/members/memberentrygen.tt | 44 ++++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 290bebe..6ca7570 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -145,36 +145,34 @@ return 0; } - function CalculateAge(dateofbirth) { - var today = new Date(); - var dob = new Date($("#dateofbirth").datepicker( 'getDate' )); - - var nowyear = today.getFullYear(); - var nowmonth = today.getMonth(); - var nowday = today.getDate(); + function CalculateAge() { + if (!$("#dateofbirth").datepicker( 'getDate' )) { + var elem = $("#dateofbirth").siblings(".hint").first().html(''); + return 1; + } - var birthyear = dob.getFullYear(); - var birthmonth = dob.getMonth(); - var birthday = dob.getDate(); + var dob = new Date($("#dateofbirth").datepicker( 'getDate' )); - var year = nowyear - birthyear; - var month = nowmonth - birthmonth; - var day = nowday - birthday; + var year = dob.getFullYear(); + var month = dob.getMonth(); + var day = dob.getDate(); - if(day < 0) { - month = parseInt(month) -1; - } + $.ajax({ + url : '/cgi-bin/koha/svc/members/age', + type : 'GET', + data: 'dateofbirth=' + year + '-' + month + '-' + day, + dataType: 'json', + success : function(json, statut){ + var age_string = "Age: "; + if (json.years) { age_string += json.years + " year(s) "; } + if (json.months) { age_string += json.months + " month(s) "; } + var elem = $("#dateofbirth").siblings(".hint").first().html(age_string); + }, + }); - if(month < 0) { - year = parseInt(year) -1; - month = 12 + month; - } var age_string = "Age: "; - if (year) { age_string += year + " year(s) "; } - if (month) { age_string += month + " month(s) "; } - var elem = $("#dateofbirth").siblings(".hint").first().html(age_string); } -- 1.7.10.4