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);
125 if(typeof guarantor_attributes !== 'undefined') {
127 url: '/api/v1/patrons/'+borrowernumber,
130 success: function(data){
131 for (var i = 0; i < parseInt(guarantor_attributes.length, 10); i++) {
132 var attribute = guarantor_attributes[i];
133 if ( data[attribute] != null && document.forms.entryform[attribute].value == "" ) {
134 document.forms.entryform[attribute].value = data[attribute];
145 function CalculateAge(dateofbirth) {
146 var today = new Date();
147 var dob = new Date(dateofbirth);
150 age.year = today.getFullYear() - dob.getFullYear();
151 age.month = today.getMonth() - dob.getMonth();
152 var day = today.getDate() - dob.getDate();
155 age.month = parseInt(age.month) -1;
159 age.year = parseInt(age.year) -1;
160 age.month = 12 + age.month;
166 function write_age() {
167 var hint = $("#dateofbirth_hint");
168 hint.html(dateformat);
170 var age = CalculateAge(document.form.dateofbirth.value);
172 if (!age.year && !age.month) {
177 if (age.year || age.month) {
178 age_string = __("Age") + ": ";
182 age_string += age.year > 1 ? __("%s years").format(age.year) : __("%s year").format(age.year);
187 age_string += age.month > 1 ? __("%s months").format(age.month) : __("%s month").format(age.month);
190 hint.html(age_string);
193 $(document).ready(function(){
194 if($("#yesdebarred").is(":checked")){
195 $("#debarreduntil").show();
197 $("#debarreduntil").hide();
199 $("#yesdebarred,#nodebarred").change(function(){
200 if($("#yesdebarred").is(":checked")){
201 $("#debarreduntil").show();
202 $("#datedebarred").focus();
204 $("#debarreduntil").hide();
207 var mandatory_fields = $("input[name='BorrowerMandatoryField']").val().split ('|');
208 $(mandatory_fields).each(function(){
209 let input = $("[name='"+this+"']")
210 if ( input.hasClass('flatpickr') ) {
211 $(input).siblings('.flatpickr_wrapper').find('input.flatpickr').prop('required', true)
213 input.prop('required', true);
216 $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
218 $('#guarantor_relationships').on('click', '.guarantor_cancel', function(e) {
220 $(this).parents('fieldset').first().remove();
223 $(document.body).on('change','.select_city',function(){
224 var selected_city = $(this).val();
225 var addressfield = $(this).data("addressfield");
226 var myRegEx=new RegExp(/(.*)\|(.*)\|(.*)\|(.*)/);
227 var matches = selected_city.match( myRegEx );
228 $("#" + addressfield + "zipcode").val( matches[1] );
229 $("#" + addressfield + "city").val( matches[2] );
230 $("#" + addressfield + "state").val( matches[3] );
231 $("#" + addressfield + "country").val( matches[4] );
234 dateformat = $("#dateofbirth").siblings(".hint").first().html();
236 if( $('#dateofbirth').length ) {
240 $.validator.addMethod(
242 function(value, element, phone) {
243 let e164_re = /^((\+?|(0{2})?)?[1-9]{0,2})?\d{1,12}$/;
244 let has_plus = value.charAt(0) === '+';
245 value = value.replace(/\D/g,'');
246 if ( has_plus ) value = '+' + value;
247 element.value = value;
249 return this.optional(element) || e164_re.test(value);
251 jQuery.validator.messages.phone);
253 $("#entryform").validate({
265 password_strong: true,
266 password_no_spaces: true
275 submitHandler: function(form) {
276 $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
277 if (form.beenSubmitted)
280 form.beenSubmitted = true;
285 var mrform = $("#manual_restriction_form");
286 var mrlink = $("#add_manual_restriction");
288 mrlink.on("click",function(e){
294 $("#cancel_manual_restriction").on("click",function(e){
295 $('#debarred_expiration').val('');
296 $('#add_debarment').val(0);
297 $('#debarred_comment').val('');
302 $('#floating-save').css( { bottom: parseInt( $('#floating-save').css('bottom') ) + $('#changelanguage').height() + 'px' } );
304 bottom: parseInt( $('#qa-save').css('bottom') ) + $('#changelanguage').height() + 'px' ,
305 "background-color": "rgba(185, 216, 217, 0.6)",