From 8c94d7b969a9565510ac38bc83ad6904e6bc7b2c Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Mon, 4 Jan 2016 14:49:04 +0100 Subject: [PATCH] Bug 15206 - Show patron's age under date of birth in memberentry.pl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test plan: Create or edit a patron (members/memberentry.pl), enter a date of birth (for a new patron), patron'a age should be shown under Followed test plan, works as expected. Signed-off-by: Marc VĂ©ron --- .../prog/en/modules/members/memberentrygen.tt | 55 +++++++++++++++++++- 1 file changed, 53 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 e646890..623806d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -34,6 +34,8 @@ } [% END %] $("#dateofbirth").datepicker({ maxDate: "-1D", yearRange: "c-120:" }); + dateformat = $("#dateofbirth").siblings(".hint").first().html(); + CalculateAge(dformat == 'metric' ? true : false); $("#entryform").validate({ rules: { email: { @@ -145,6 +147,55 @@ return 0; } + function CalculateAge(checkdate) { + var hint = $("#dateofbirth").siblings(".hint").first(); + hint.html(dateformat); + + if (checkdate && false === CheckDate(document.form.dateofbirth)) { + return; + } + + if (!$("#dateofbirth").datepicker( 'getDate' )) { + return; + } + + 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 > 1 ? '%s years ' : '%s year ').format(year); + } + + if (month) { + age_string += _(month > 1 ? '%s months ' : '%s month ').format(month); + } + + hint.html(age_string); + + } + var MSG_SEPARATOR = _("Separator must be / in field %s"); @@ -344,9 +395,9 @@ Date of birth: [% IF ( dateformat == "metric" ) %] - + [% ELSE %] - + [% END %] [% IF ( mandatorydateofbirth ) %]Required[% END %] -- 1.7.10.4