From 90b0f76b8dd377191e90e7aca1a3b52dbbee18cf Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Tue, 26 Jan 2016 10:45:46 +0100 Subject: [PATCH] Bug 15206 - Make CalculateAge a reusable function Signed-off-by: Owen Leonard Signed-off-by: Jonathan Druart --- koha-tmpl/intranet-tmpl/prog/en/js/members.js | 52 +---- .../prog/en/modules/members/memberentrygen.tt | 249 ++++++++++++--------- 2 files changed, 148 insertions(+), 153 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/members.js b/koha-tmpl/intranet-tmpl/prog/en/js/members.js index 1dd1cb8..7f7955a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/en/js/members.js @@ -217,55 +217,25 @@ function select_user(borrowernumber, borrower) { return 0; } -function CalculateAge() { - var hint = $("#dateofbirth").siblings(".hint").first(); - hint.html(dateformat); - - if (dformat == 'metric' && false === CheckDate(document.form.dateofbirth)) { - return; - } - - if (!$("#dateofbirth").datepicker( 'getDate' )) { - return; - } - +function CalculateAge(dateofbirth) { var today = new Date(); - var dob = new Date($("#dateofbirth").datepicker( 'getDate' )); + var dob = Date_from_syspref(dateofbirth) + var age = new Object(); - 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; + age.year = today.getFullYear() - dob.getFullYear(); + age.month = today.getMonth() - dob.getMonth(); + var day = today.getDate() - dob.getDate(); if(day < 0) { - month = parseInt(month) -1; - } - - if(month < 0) { - year = parseInt(year) -1; - month = 12 + month; - } - - var age_string; - if (year || month) { - age_string = _('Age: '); - } - if (year) { - age_string += _(year > 1 ? '%s years ' : '%s year ').format(year); + age.month = parseInt(age.month) -1; } - if (month) { - age_string += _(month > 1 ? '%s months ' : '%s month ').format(month); + if(age.month < 0) { + age.year = parseInt(age.year) -1; + age.month = 12 + age.month; } - hint.html(age_string); + return age; } $(document).ready(function(){ 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 78c5e05..8d2eab6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -6,131 +6,156 @@ [% INCLUDE 'calendar.inc' %]