From 97b27b94bb79525ca630f8e902bb44c1a96c9d73 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 8 Apr 2016 08:11:11 -0400 Subject: [PATCH] Bug 16228 - Move some patron entry form JavaScript into members.js again MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bug 15206 undid the changes Bug 15692 made to memberentrygen.tt. This patch re-removes the JS from the template and moves the additions made by Bug 15206 into members.js. Two other minor edits: Changes to quiet JSHint errors. To test, apply the patch and repeat the test plan for Bug 15692. Confirm that the following interactions still work on the patron entry form: 1. clear_entry(): With ExtendedPatronAttributes enabled, the "Clear" link next to any attribute form field should work to clear the field. 2. clone_entry(): With ExtendedPatronAttributes enabled and a repeatable attribute defined, it should be possible to click the "New" link to add another instance of that attribute's entry field. 3. update_category_code(): With ExtendedPatronAttributes enabled and an attribute defined which is limited to a single patron category, changing the patron category selection should correctly show or hide the attribute entry form. 4. select_user(): When adding or editing a patron with a "Child" category it should be possible to search for and select a guarantor to add to the record by clicking the "Set to patron" button. Selecting a new guarantor should change the text of the button from "Set to patron" to "Change." 5. noEnterSubmit(): This function should be correctly preventing you from hitting "ENTER" in any form field to submit the form. 6. guarantordelete(): When adding or editing a patron with a "Child" category, it should be possible to clear existing guarantor information by clicking the "Delete" button. Clicking the "Delete" button should change the text of the adjacent button to "Set to patron." 7. select_city(): With one or more cities defined it should be possible to use the drop-down menu of cities to populate the city, state, zip, and country fields. 8. Date of birth entry should have a maximum date limit of yesterday. The drop-down menu of years should go back 100 years. 9. Selecting a date of birth should replace the date format hint with a message showing the user's age in years or months. Test with values which will show an age of 1 month, between 2 and 11 months, 1 year, and more than one year. 10. Client-side validation rules should be in effect, requiring that a valid email address be entered in the primary email, secondary email, and alternate address email fields. 11.When editing a patron, the "Add manual restriction" link should display the form for adding a manual restriction, and clicking the "Cancel" link should hide it. Followed test plan, everything works OK. Signed-off-by: Marc Véron Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- .../prog/en/modules/members/memberentrygen.tt | 148 +----------------- koha-tmpl/intranet-tmpl/prog/js/members.js | 38 ++++- 2 files changed, 41 insertions(+), 145 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 6086b3c242..35340ee4bc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -7,7 +7,6 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index 2acefb60f5..a6b6b59978 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -219,8 +219,8 @@ function select_user(borrowernumber, borrower) { function CalculateAge(dateofbirth) { var today = new Date(); - var dob = Date_from_syspref(dateofbirth) - var age = new Object(); + var dob = Date_from_syspref(dateofbirth); + var age = {}; age.year = today.getFullYear() - dob.getFullYear(); age.month = today.getMonth() - dob.getMonth(); @@ -238,6 +238,33 @@ function CalculateAge(dateofbirth) { return age; } +function write_age() { + var hint = $("#dateofbirth").siblings(".hint").first(); + hint.html(dateformat); + + var age = CalculateAge(document.form.dateofbirth.value); + + if (!age.year && !age.month) { + return; + } + + var age_string; + if (age.year || age.month) { + age_string = LABEL_AGE + ": "; + } + + if (age.year) { + age_string += age.year > 1 ? MSG_YEARS.format(age.year) : MSG_YEAR.format(age.year); + age_string += " "; + } + + if (age.month) { + age_string += age.month > 1 ? MSG_MONTHS.format(age.month) : MSG_MONTH.format(age.month); + } + + hint.html(age_string); +} + $(document).ready(function(){ if($("#yesdebarred").is(":checked")){ $("#debarreduntil").show(); @@ -278,6 +305,11 @@ $(document).ready(function(){ }); $("#dateofbirth").datepicker({ maxDate: "-1D", yearRange: "c-120:" }); + dateformat = $("#dateofbirth").siblings(".hint").first().html(); + + if( $('#dateofbirth').length ) { + write_age(); + } $("#entryform").validate({ rules: { @@ -318,5 +350,5 @@ $(document).ready(function(){ mrform.hide(); e.preventDefault(); }); - + $('#floating-save').css( { bottom: parseInt( $('#floating-save').css('bottom') ) + $('#changelanguage').height() + 'px' } ); }); -- 2.39.5