1 // function to test all fields in forms and nav in different forms(1 ,2 or 3)
2 function check_form_borrowers(nav){
6 if (document.form.check_member.value == 1 )
8 if (document.form.answernodouble) {
9 if( (!(document.form.answernodouble.checked))){
10 document.form.nodouble.value=0;
12 document.form.nodouble.value=1;
17 //patrons form to test if you checked no to the question of double
18 if (statut!=1 && document.form.check_member.value > 0 ) {
19 if (!(document.form.answernodouble.checked)){
20 message_champ += __("Please confirm whether this is a duplicate patron");
22 document.form.nodouble.value=0;
24 document.form.nodouble.value=1;
29 //alert if at least 1 error
30 alert(message+"\n"+message_champ);
37 function clear_entry(node) {
38 var original = $(node).parent();
39 $("textarea", original).val('');
40 $("select", original).val('');
43 function clone_entry(node) {
44 var original = $(node).parent();
45 var clone = original.clone();
47 var newId = 50 + parseInt(Math.random() * 100000);
48 $("input,select,textarea", clone).attr('id', function() {
49 return this.id.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
51 $("input,select,textarea", clone).attr('name', function() {
52 return this.name.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
54 $("label", clone).attr('for', function() {
55 return $(this).attr("for").replace(/patron_attr_\d+/, 'patron_attr_' + newId);
57 $("input#patron_attr_" + newId, clone).attr('value','');
58 $("select#patron_attr_" + newId, clone).attr('value','');
59 $(original).after(clone);
63 function update_category_code(category_code) {
64 if ( $(category_code).is("select") ) {
65 category_code = $("#categorycode_entry").find("option:selected").val();
67 var mytables = $(".attributes_table");
68 $(mytables).find("li").hide();
69 $(mytables).find(" li[data-category_code='"+category_code+"']").show();
70 $(mytables).find(" li[data-category_code='']").show();
72 //Change password length hint
73 var hint = $("#password").siblings(".hint").first();
74 var min_length = $('select'+category_selector+' option:selected').data('pwdLength');
75 var hint_string = __("Minimum password length: %s").format(min_length);
76 hint.html(hint_string);
79 function select_user(borrowernumber, borrower, relationship) {
80 let is_guarantor = $(`.guarantor-details[data-borrowernumber=${borrowernumber}]`).length;
83 alert("Patron is already a guarantor for this patron");
85 $('#guarantor_id').val(borrowernumber);
86 $('#guarantor_surname').val(borrower.surname);
87 $('#guarantor_firstname').val(borrower.firstname);
89 var fieldset = $('#guarantor_template').clone();
90 fieldset.removeAttr('id');
92 var guarantor_id = $('#guarantor_id').val();
94 fieldset.find('.new_guarantor_id').first().val( guarantor_id );
95 fieldset.find('.new_guarantor_id_text').first().text( borrower.cardnumber );
96 fieldset.find('.new_guarantor_link').first().attr("href", "/cgi-bin/koha/members/moremember.pl?borrowernumber=" + guarantor_id );
98 fieldset.find('.guarantor_id').first().hide();
100 $('#guarantor_id').val("");
102 var guarantor_surname = $('#guarantor_surname').val();
103 fieldset.find('.new_guarantor_surname').first().val( guarantor_surname );
104 fieldset.find('.new_guarantor_surname_text').first().text( guarantor_surname );
105 $('#guarantor_surname').val("");
107 var guarantor_firstname = $('#guarantor_firstname').val();
108 fieldset.find('.new_guarantor_firstname').first().val( guarantor_firstname );
109 fieldset.find('.new_guarantor_firstname_text').first().text( guarantor_firstname );
110 $('#guarantor_firstname').val("");
112 var guarantor_relationship = $('#relationship').val();
113 fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship );
114 $('#relationship').find('option:eq(0)').prop('selected', true);
116 fieldset.find('.guarantor-details').first().attr( 'data-borrowernumber', borrowernumber );
118 $('#guarantor_relationships').append( fieldset );
121 if ( relationship ) {
122 fieldset.find('.new_guarantor_relationship').val(relationship);
129 function CalculateAge(dateofbirth) {
130 var today = new Date();
131 var dob = new Date(dateofbirth);
134 age.year = today.getFullYear() - dob.getFullYear();
135 age.month = today.getMonth() - dob.getMonth();
136 var day = today.getDate() - dob.getDate();
139 age.month = parseInt(age.month) -1;
143 age.year = parseInt(age.year) -1;
144 age.month = 12 + age.month;
150 function write_age() {
151 var hint = $("#dateofbirth_hint");
152 hint.html(dateformat);
154 var age = CalculateAge(document.form.dateofbirth.value);
156 if (!age.year && !age.month) {
161 if (age.year || age.month) {
162 age_string = __("Age") + ": ";
166 age_string += age.year > 1 ? __("%s years").format(age.year) : __("%s year").format(age.year);
171 age_string += age.month > 1 ? __("%s months").format(age.month) : __("%s month").format(age.month);
174 hint.html(age_string);
177 $(document).ready(function(){
178 if($("#yesdebarred").is(":checked")){
179 $("#debarreduntil").show();
181 $("#debarreduntil").hide();
183 $("#yesdebarred,#nodebarred").change(function(){
184 if($("#yesdebarred").is(":checked")){
185 $("#debarreduntil").show();
186 $("#datedebarred").focus();
188 $("#debarreduntil").hide();
191 var mandatory_fields = $("input[name='BorrowerMandatoryField']").val().split ('|');
192 $(mandatory_fields).each(function(){
193 let input = $("[name='"+this+"']")
194 if ( input.hasClass('flatpickr') ) {
195 $(input).siblings('.flatpickr_wrapper').find('input.flatpickr').prop('required', true)
197 input.prop('required', true);
200 $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
202 $('body').on('click', '#guarantor_search', function(e) {
204 var newin = window.open('/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,dateofbirth,address-library,action','popup','width=1024,height=768,resizable=no,toolbar=false,scrollbars=yes,top');
207 $('#guarantor_relationships').on('click', '.guarantor_cancel', function(e) {
209 $(this).parents('fieldset').first().remove();
212 $(document.body).on('change','.select_city',function(){
213 var selected_city = $(this).val();
214 var addressfield = $(this).data("addressfield");
215 var myRegEx=new RegExp(/(.*)\|(.*)\|(.*)\|(.*)/);
216 var matches = selected_city.match( myRegEx );
217 $("#" + addressfield + "zipcode").val( matches[1] );
218 $("#" + addressfield + "city").val( matches[2] );
219 $("#" + addressfield + "state").val( matches[3] );
220 $("#" + addressfield + "country").val( matches[4] );
223 dateformat = $("#dateofbirth").siblings(".hint").first().html();
225 if( $('#dateofbirth').length ) {
229 $.validator.addMethod(
231 function(value, element, phone) {
232 let e164_re = /^((\+?|(0{2})?)?[1-9]{0,2})?\d{1,12}$/;
233 let has_plus = value.charAt(0) === '+';
234 value = value.replace(/\D/g,'');
235 if ( has_plus ) value = '+' + value;
236 element.value = value;
238 return this.optional(element) || e164_re.test(value);
240 jQuery.validator.messages.phone);
242 $("#entryform").validate({
254 password_strong: true,
255 password_no_spaces: true
264 submitHandler: function(form) {
265 $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
266 if (form.beenSubmitted)
269 form.beenSubmitted = true;
274 var mrform = $("#manual_restriction_form");
275 var mrlink = $("#add_manual_restriction");
277 mrlink.on("click",function(e){
283 $("#cancel_manual_restriction").on("click",function(e){
284 $('#debarred_expiration').val('');
285 $('#add_debarment').val(0);
286 $('#debarred_comment').val('');
291 $('#floating-save').css( { bottom: parseInt( $('#floating-save').css('bottom') ) + $('#changelanguage').height() + 'px' } );
293 bottom: parseInt( $('#qa-save').css('bottom') ) + $('#changelanguage').height() + 'px' ,
294 "background-color": "rgba(185, 216, 217, 0.6)",