Bugzilla – Attachment 49033 Details for
Bug 15206
Show patron's age when filling date of birth in memberentry.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15206 - Make CalculateAge a reusable function
Bug-15206---Make-CalculateAge-a-reusable-function.patch (text/plain), 12.66 KB, created by
Alex Arnaud
on 2016-03-11 14:30:05 UTC
(
hide
)
Description:
Bug 15206 - Make CalculateAge a reusable function
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2016-03-11 14:30:05 UTC
Size:
12.66 KB
patch
obsolete
>From 90b0f76b8dd377191e90e7aca1a3b52dbbee18cf Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Tue, 26 Jan 2016 10:45:46 +0100 >Subject: [PATCH] Bug 15206 - Make CalculateAge a reusable function > >Signed-off-by: Owen Leonard <oleonard@myacpl.org> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > 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' %] > <script type="text/javascript"> > //<![CDATA[ >- $(document).ready(function() { >+$(document).ready(function() { > >- [% IF categorycode %] >- update_category_code( "[% categorycode %]" ); >- [% ELSE %] >- if ( $("#categorycode_entry").length > 0 ){ >- var category_code = $("#categorycode_entry").find("option:selected").val(); >- update_category_code( category_code ); >- } >- [% END %] >- $("#dateofbirth").datepicker({ maxDate: "-1D", yearRange: "c-120:" }); >- dateformat = $("#dateofbirth").siblings(".hint").first().html(); >- CalculateAge(); >- $("#entryform").validate({ >- rules: { >- email: { >- email: true >- }, >- emailpro: { >- email: true >- }, >- B_email: { >- email: true >- } >- }, >- submitHandler: function(form) { >- $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting'); >- if (form.beenSubmitted) >- return false; >- else >- form.beenSubmitted = true; >- form.submit(); >- } >- }); >+ [% IF categorycode %] >+ update_category_code( "[% categorycode %]" ); >+ [% ELSE %] >+ if ( $("#categorycode_entry").length > 0 ){ >+ var category_code = $("#categorycode_entry").find("option:selected").val(); >+ update_category_code( category_code ); >+ } >+ [% END %] >+ $("#dateofbirth").datepicker({ maxDate: "-1D", yearRange: "c-120:" }); >+ dateformat = $("#dateofbirth").siblings(".hint").first().html(); >+ write_age(); >+ $("#entryform").validate({ >+ rules: { >+ email: { >+ email: true >+ }, >+ emailpro: { >+ email: true >+ }, >+ B_email: { >+ email: true >+ } >+ }, >+ submitHandler: function(form) { >+ $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting'); >+ if (form.beenSubmitted) >+ return false; >+ else >+ form.beenSubmitted = true; >+ form.submit(); >+ } >+ }); > >- var mrform = $("#manual_restriction_form"); >- var mrlink = $("#add_manual_restriction"); >- mrform.hide(); >- mrlink.on("click",function(e){ >- $(this).hide(); >- mrform.show(); >- e.preventDefault(); >- }); >- $("#cancel_manual_restriction").on("click",function(e){ >- $('#debarred_expiration').val(''); >- $('#add_debarment').val(0); >- $('#debarred_comment').val(''); >- mrlink.show(); >- mrform.hide(); >- e.preventDefault(); >- }); >- }); >+ var mrform = $("#manual_restriction_form"); >+ var mrlink = $("#add_manual_restriction"); >+ mrform.hide(); >+ mrlink.on("click",function(e){ >+ $(this).hide(); >+ mrform.show(); >+ e.preventDefault(); >+ }); >+ $("#cancel_manual_restriction").on("click",function(e){ >+ $('#debarred_expiration').val(''); >+ $('#add_debarment').val(0); >+ $('#debarred_comment').val(''); >+ mrlink.show(); >+ mrform.hide(); >+ e.preventDefault(); >+ }); >+}); > >- function clear_entry(node) { >- var original = $(node).parent(); >- $("textarea", original).attr('value', ''); >- $("select", original).attr('value', ''); >- } >+function clear_entry(node) { >+ var original = $(node).parent(); >+ $("textarea", original).attr('value', ''); >+ $("select", original).attr('value', ''); >+} > >- function clone_entry(node) { >- var original = $(node).parent(); >- var clone = original.clone(); >+function clone_entry(node) { >+ var original = $(node).parent(); >+ var clone = original.clone(); > >- var newId = 50 + parseInt(Math.random() * 100000); >- $("input,select,textarea", clone).attr('id', function() { >- return this.id.replace(/patron_attr_\d+/, 'patron_attr_' + newId); >- }); >- $("input,select,textarea", clone).attr('name', function() { >- return this.name.replace(/patron_attr_\d+/, 'patron_attr_' + newId); >- }); >- $("label", clone).attr('for', function() { >- return $(this).attr("for").replace(/patron_attr_\d+/, 'patron_attr_' + newId); >- }); >- $("input#patron_attr_" + newId, clone).attr('value',''); >- $("select#patron_attr_" + newId, clone).attr('value',''); >- $(original).after(clone); >- return false; >- } >+ var newId = 50 + parseInt(Math.random() * 100000); >+ $("input,select,textarea", clone).attr('id', function() { >+ return this.id.replace(/patron_attr_\d+/, 'patron_attr_' + newId); >+ }); >+ $("input,select,textarea", clone).attr('name', function() { >+ return this.name.replace(/patron_attr_\d+/, 'patron_attr_' + newId); >+ }); >+ $("label", clone).attr('for', function() { >+ return $(this).attr("for").replace(/patron_attr_\d+/, 'patron_attr_' + newId); >+ }); >+ $("input#patron_attr_" + newId, clone).attr('value',''); >+ $("select#patron_attr_" + newId, clone).attr('value',''); >+ $(original).after(clone); >+ return false; >+} > >- function update_category_code(category_code) { >- if ( $(category_code).is("select") ) { >- category_code = $("#categorycode_entry").find("option:selected").val(); >- } >- var mytables = $(".attributes_table"); >- $(mytables).find("li").hide(); >- $(mytables).find(" li[data-category_code='"+category_code+"']").show(); >- $(mytables).find(" li[data-category_code='']").show(); >- } >+function update_category_code(category_code) { >+ if ( $(category_code).is("select") ) { >+ category_code = $("#categorycode_entry").find("option:selected").val(); >+ } >+ var mytables = $(".attributes_table"); >+ $(mytables).find("li").hide(); >+ $(mytables).find(" li[data-category_code='"+category_code+"']").show(); >+ $(mytables).find(" li[data-category_code='']").show(); >+} > >- function select_user(borrowernumber, borrower) { >- var form = $('#entryform').get(0); >- if (form.guarantorid.value) { >- $("#contact-details").find('a').remove(); >- $("#contactname, #contactfirstname").parent().find('span').remove(); >- } >+function select_user(borrowernumber, borrower) { >+ var form = $('#entryform').get(0); >+ if (form.guarantorid.value) { >+ $("#contact-details").find('a').remove(); >+ $("#contactname, #contactfirstname").parent().find('span').remove(); >+ } >+ >+ var id = borrower.borrowernumber; >+ form.guarantorid.value = id; >+ $('#contact-details') >+ .show() >+ .find('span') >+ .after('<a target="blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' + id + '">' + id + '</a>'); >+ >+ $(form.contactname) >+ .val(borrower.surname) >+ .before('<span>' + borrower.surname + '</span>').get(0).type = 'hidden'; >+ $(form.contactfirstname) >+ .val(borrower.firstname) >+ .before('<span>' + borrower.firstname + '</span>').get(0).type = 'hidden'; >+ >+ form.streetnumber.value = borrower.streetnumber; >+ form.address.value = borrower.address; >+ form.address2.value = borrower.address2; >+ form.city.value = borrower.city; >+ form.state.value = borrower.state; >+ form.zipcode.value = borrower.zipcode; >+ form.country.value = borrower.country; >+ form.branchcode.value = borrower.branchcode; >+ >+ form.guarantorsearch.value = _("Change"); > >- var id = borrower.borrowernumber; >- form.guarantorid.value = id; >- $('#contact-details') >- .show() >- .find('span') >- .after('<a target="blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' + id + '">' + id + '</a>'); >+ return 0; >+} > >- $(form.contactname) >- .val(borrower.surname) >- .before('<span>' + borrower.surname + '</span>').get(0).type = 'hidden'; >- $(form.contactfirstname) >- .val(borrower.firstname) >- .before('<span>' + borrower.firstname + '</span>').get(0).type = 'hidden'; >+ function write_age() { >+ var hint = $("#dateofbirth").siblings(".hint").first(); >+ hint.html(dateformat); > >- form.streetnumber.value = borrower.streetnumber; >- form.address.value = borrower.address; >- form.address2.value = borrower.address2; >- form.city.value = borrower.city; >- form.state.value = borrower.state; >- form.zipcode.value = borrower.zipcode; >- form.country.value = borrower.country; >- form.branchcode.value = borrower.branchcode; >+ var age = CalculateAge(document.form.dateofbirth.value); > >- form.guarantorsearch.value = _("Change"); >+ if (!age.year && !age.month) { >+ return; >+ } >+ >+ var age_string; >+ if (age.year || age.month) { >+ age_string = _('Age: '); >+ } >+ >+ if (age.year) { >+ age_string += _(age.year > 1 ? '%s years ' : '%s year ').format(age.year); >+ } >+ >+ if (age.month) { >+ age_string += _(age.month > 1 ? '%s months ' : '%s month ').format(age.month); >+ } > >- return 0; >+ hint.html(age_string); > } > >->>>>>>> Bug 15206 - Show patron's age under date of birth in memberentry.pl > var MSG_SEPARATOR = _("Separator must be / in field %s"); > var MSG_INCORRECT_DAY = _("Invalid day entered in field %s"); > var MSG_INCORRECT_MONTH = _("Invalid month entered in field %s"); >@@ -329,7 +354,7 @@ > [% END %] > Date of birth: </label> > >- <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="CalculateAge();" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" /> >+ <input type="text" id="dateofbirth" name="dateofbirth" size="20" onchange="write_age();" value="[% UNLESS opduplicate %][% dateofbirth %][% END %]" /> > > [% IF ( mandatorydateofbirth ) %]<span class="required">Required</span>[% END %] > [% IF ( ERROR_dateofbirth ) %]<span class="required">(Error)</span>[% END %] >-- >2.7.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15206
:
44953
|
44978
|
45579
|
45580
|
45581
|
45589
|
45590
|
45591
|
45592
|
45593
|
45597
|
45598
|
45599
|
45600
|
45601
|
46228
|
46245
|
46396
|
47301
|
47505
|
47506
|
47540
|
47541
|
47542
|
49032
| 49033 |
49034