1 // this function checks id date is like DD/MM/YYYY
2 function CheckDate(field) {
7 var date = d.split("/");
10 if ( (date.length < 2) && (ok==1) ) {
11 msg = MSG_SEPARATOR.format(field.name);
12 alert(msg); ok=0; field.focus();
19 if ( ((isNaN(dd))||(dd<1)||(dd>31)) && (ok==1) ) {
20 msg = MSG_INCORRECT_DAY.format(field.name);
21 alert(msg); ok=0; field.focus();
25 if ( ((isNaN(mm))||(mm<1)||(mm>12)) && (ok==1) ) {
26 msg = MSG_INCORRECT_MONTH.format(field.name);
27 alert(msg); ok=0; field.focus();
31 if ( ((isNaN(yyyy))||(yyyy<amin)||(yyyy>amax)) && (ok==1) ) {
32 msg = MSG_INCORRECT_YEAR.format(field.name);
33 alert(msg); ok=0; field.focus();
39 //function test if member is unique and if it's right the member is registred
43 if ( document.form.check_member.value==1){
44 if (document.form.categorycode.value != "I"){
46 msg1 += MSG_DUPLICATE_PATRON;
48 check_form_borrowers(0);
49 document.form.submit();
52 msg2 += MSG_DUPLICATE_ORGANIZATION;
54 check_form_borrowers(0);
59 document.form.submit();
64 //function test if date enrooled < date expiry
65 // WARNING: format-specific test.
66 function check_manip_date(status) {
67 if (status=='verify'){
68 // this part of function('verify') is used to check if dateenrolled<date expiry
69 if (document.form.dateenrolled !== '' && document.form.dateexpiry.value !=='') {
70 var myDate1=document.form.dateenrolled.value.split ('/');
71 var myDate2=document.form.dateexpiry.value.split ('/');
72 if ((myDate1[2]>myDate2[2])||(myDate1[2]==myDate2[2] && myDate1[1]>myDate2[1])||(myDate1[2]==myDate2[2] && myDate1[1]>=myDate2[1] && myDate1[0]>=myDate2[0]))
75 document.form.dateenrolled.focus();
76 var msg = MSG_LATE_EXPIRY;
84 function check_password( password ) {
85 if ( password.match(/^\s/) || password.match(/\s$/)) {
91 // function to test all fields in forms and nav in different forms(1 ,2 or 3)
92 function check_form_borrowers(nav){
96 if (document.form.check_member.value == 1 )
98 if (document.form.answernodouble) {
99 if( (!(document.form.answernodouble.checked))){
100 document.form.nodouble.value=0;
102 document.form.nodouble.value=1;
107 //patrons form to test if you checked no to the question of double
108 if (statut!=1 && document.form.check_member.value > 0 ) {
109 if (!(document.form.answernodouble.checked)){
110 message_champ+= MSG_DUPLICATE_SUSPICION;
112 document.form.nodouble.value=0;
114 document.form.nodouble.value=1;
119 //alert if at least 1 error
120 alert(message+"\n"+message_champ);
127 function Dopop(link) {
128 // // var searchstring=document.form.value[i].value;
129 var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=no,top');
132 function clear_entry(node) {
133 var original = $(node).parent();
134 $("textarea", original).attr('value', '');
135 $("select", original).attr('value', '');
138 function clone_entry(node) {
139 var original = $(node).parent();
140 var clone = original.clone();
142 var newId = 50 + parseInt(Math.random() * 100000);
143 $("input,select,textarea", clone).attr('id', function() {
144 return this.id.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
146 $("input,select,textarea", clone).attr('name', function() {
147 return this.name.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
149 $("label", clone).attr('for', function() {
150 return $(this).attr("for").replace(/patron_attr_\d+/, 'patron_attr_' + newId);
152 $("input#patron_attr_" + newId, clone).attr('value','');
153 $("select#patron_attr_" + newId, clone).attr('value','');
154 $(original).after(clone);
158 function update_category_code(category_code) {
159 if ( $(category_code).is("select") ) {
160 category_code = $("#categorycode_entry").find("option:selected").val();
162 var mytables = $(".attributes_table");
163 $(mytables).find("li").hide();
164 $(mytables).find(" li[data-category_code='"+category_code+"']").show();
165 $(mytables).find(" li[data-category_code='']").show();
168 function select_user(borrowernumber, borrower, relationship) {
169 let is_guarantor = $(`.guarantor-details[data-borrowernumber=${borrower.borrowernumber}]`).length;
171 if ( is_guarantor ) {
172 alert("Patron is already a guarantor for this patron");
174 $('#guarantor_id').val(borrower.borrowernumber);
175 $('#guarantor_surname').val(borrower.surname);
176 $('#guarantor_firstname').val(borrower.firstname);
178 var fieldset = $('#guarantor_template').clone();
179 fieldset.removeAttr('id');
181 var guarantor_id = $('#guarantor_id').val();
182 if ( guarantor_id ) {
183 fieldset.find('.new_guarantor_id').first().val( guarantor_id );
184 fieldset.find('.new_guarantor_id_text').first().text( borrower.cardnumber );
185 fieldset.find('.new_guarantor_link').first().attr("href", "/cgi-bin/koha/members/moremember.pl?borrowernumber=" + guarantor_id );
187 fieldset.find('.guarantor_id').first().hide();
189 $('#guarantor_id').val("");
191 var guarantor_surname = $('#guarantor_surname').val();
192 fieldset.find('.new_guarantor_surname').first().val( guarantor_surname );
193 fieldset.find('.new_guarantor_surname_text').first().text( guarantor_surname );
194 $('#guarantor_surname').val("");
196 var guarantor_firstname = $('#guarantor_firstname').val();
197 fieldset.find('.new_guarantor_firstname').first().val( guarantor_firstname );
198 fieldset.find('.new_guarantor_firstname_text').first().text( guarantor_firstname );
199 $('#guarantor_firstname').val("");
201 var guarantor_relationship = $('#relationship').val();
202 fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship );
203 $('#relationship').find('option:eq(0)').prop('selected', true);
205 fieldset.find('.guarantor-details').first().attr( 'data-borrowernumber', borrower.borrowernumber );
207 $('#guarantor_relationships').append( fieldset );
210 if ( relationship ) {
211 fieldset.find('.new_guarantor_relationship').val(relationship);
218 function CalculateAge(dateofbirth) {
219 var today = new Date();
220 var dob = Date_from_syspref(dateofbirth);
223 age.year = today.getFullYear() - dob.getFullYear();
224 age.month = today.getMonth() - dob.getMonth();
225 var day = today.getDate() - dob.getDate();
228 age.month = parseInt(age.month) -1;
232 age.year = parseInt(age.year) -1;
233 age.month = 12 + age.month;
239 function write_age() {
240 var hint = $("#dateofbirth").siblings(".hint").first();
241 hint.html(dateformat);
243 var age = CalculateAge(document.form.dateofbirth.value);
245 if (!age.year && !age.month) {
250 if (age.year || age.month) {
251 age_string = LABEL_AGE + ": ";
255 age_string += age.year > 1 ? MSG_YEARS.format(age.year) : MSG_YEAR.format(age.year);
260 age_string += age.month > 1 ? MSG_MONTHS.format(age.month) : MSG_MONTH.format(age.month);
263 hint.html(age_string);
266 $(document).ready(function(){
267 if($("#yesdebarred").is(":checked")){
268 $("#debarreduntil").show();
270 $("#debarreduntil").hide();
272 $("#yesdebarred,#nodebarred").change(function(){
273 if($("#yesdebarred").is(":checked")){
274 $("#debarreduntil").show();
275 $("#datedebarred").focus();
277 $("#debarreduntil").hide();
280 var mandatory_fields = $("input[name='BorrowerMandatoryField']").val().split ('|');
281 $(mandatory_fields).each(function(){
282 $("[name='"+this+"']").attr('required', 'required');
285 $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
287 $('body').on('click', '#guarantor_search', function(e) {
289 var newin = window.open('guarantor_search.pl','popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=yes,top');
292 $('#guarantor_relationships').on('click', '.guarantor_cancel', function(e) {
294 $(this).parents('fieldset').first().remove();
297 $(document.body).on('change','.select_city',function(){
298 var selected_city = $(this).val();
299 var addressfield = $(this).data("addressfield");
300 var myRegEx=new RegExp(/(.*)\|(.*)\|(.*)\|(.*)/);
301 var matches = selected_city.match( myRegEx );
302 $("#" + addressfield + "zipcode").val( matches[1] );
303 $("#" + addressfield + "city").val( matches[2] );
304 $("#" + addressfield + "state").val( matches[3] );
305 $("#" + addressfield + "country").val( matches[4] );
308 dateformat = $("#dateofbirth").siblings(".hint").first().html();
310 if( $('#dateofbirth').length ) {
314 $.validator.addMethod(
316 function(value, element, phone) {
317 var e164 = "^\\+?[1-9]\\d{1,14}$";
318 var re = new RegExp(e164);
320 let has_plus = value.charAt(0) === '+';
321 value = value.replace(/\D/g,'');
322 if ( has_plus ) value = '+' + value;
323 element.value = value;
325 return this.optional(element) || re.test(value);
327 jQuery.validator.messages.phone);
329 $("#entryform").validate({
341 password_strong: true,
342 password_no_spaces: true
351 submitHandler: function(form) {
352 $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
353 if (form.beenSubmitted)
356 form.beenSubmitted = true;
361 var mrform = $("#manual_restriction_form");
362 var mrlink = $("#add_manual_restriction");
364 mrlink.on("click",function(e){
370 $("#cancel_manual_restriction").on("click",function(e){
371 $('#debarred_expiration').val('');
372 $('#add_debarment').val(0);
373 $('#debarred_comment').val('');
378 $('#floating-save').css( { bottom: parseInt( $('#floating-save').css('bottom') ) + $('#changelanguage').height() + 'px' } );
380 bottom: parseInt( $('#qa-save').css('bottom') ) + $('#changelanguage').height() + 'px' ,
381 "background-color": "rgba(185, 216, 217, 0.6)",