From 14631570f25739d07547882d8c628fc33740dbf8 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Wed, 18 Nov 2015 10:31:29 +0100 Subject: [PATCH] Bug 15206 - Show patron's age under date of birth in memberentry.pl Test plan: Create a new patron (members/memberentry.pl), enter a date of birth, patron'a age should be shown under --- .../prog/en/modules/members/memberentrygen.tt | 35 ++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 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 a3b7a9d..290bebe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -145,6 +145,37 @@ 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(); + + var birthyear = dob.getFullYear(); + var birthmonth = dob.getMonth(); + var birthday = dob.getDate(); + + var year = nowyear - birthyear; + var month = nowmonth - birthmonth; + var day = nowday - birthday; + + if(day < 0) { + month = parseInt(month) -1; + } + + 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); + } var MSG_SEPARATOR = _("Separator must be / in field %s"); @@ -344,9 +375,9 @@ Date of birth: [% IF ( dateformat == "metric" ) %] - + [% ELSE %] - + [% END %] [% IF ( mandatorydateofbirth ) %]Required[% END %] -- 1.7.10.4