@@ -, +, @@ --- .../prog/en/modules/members/memberentrygen.tt | 12 ++-- koha-tmpl/intranet-tmpl/prog/js/members.js | 62 +++++++++++-------- 2 files changed, 42 insertions(+), 32 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -327,8 +327,8 @@ [% FOREACH r IN relationships %]
    - [% IF category_type == 'P' %] -
  1. + [% IF category_type == 'I' %] +
  2. Organization #: [% IF ( r.guarantor_id ) %] [% r.guarantor_id | html %][% END %]
  3. @@ -337,7 +337,7 @@ [% r.guarantor.surname | html %] [% ELSE %] -
  4. +
  5. Patron #: [% r.guarantor_id | html %]
  6. @@ -362,7 +362,7 @@
  7. - +
  8. [% END %] @@ -373,7 +373,7 @@
      -
    1. +
    2. Patron #: @@ -411,7 +411,7 @@
    3. - Search + Search to add
    4. [% IF relationships && Koha.Preference('AllowStaffToSetCheckoutsVisibilityForGuarantor') %] --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ a/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -166,38 +166,48 @@ function update_category_code(category_code) { } function select_user(borrowernumber, borrower) { - $('#guarantor_id').val(borrower.borrowernumber); - $('#guarantor_surname').val(borrower.surname); - $('#guarantor_firstname').val(borrower.firstname); + let is_guarantor = $(`.guarantor-details[data-borrowernumber=${borrower.borrowernumber}]`).length; + console.log("LEN: " + is_guarantor ); - var fieldset = $('#guarantor_template').clone(); - fieldset.removeAttr('id'); - - var guarantor_id = $('#guarantor_id').val(); - if ( guarantor_id ) { - fieldset.find('.new_guarantor_id').first().val( guarantor_id ); - fieldset.find('.new_guarantor_id_text').first().text( guarantor_id ); + if ( is_guarantor ) { + alert("Patron is already a guarantor for this patron"); } else { - fieldset.find('.guarantor_id').first().hide(); - } - $('#guarantor_id').val(""); + $('#guarantor_id').val(borrower.borrowernumber); + $('#guarantor_surname').val(borrower.surname); + $('#guarantor_firstname').val(borrower.firstname); + + var fieldset = $('#guarantor_template').clone(); + fieldset.removeAttr('id'); + + var guarantor_id = $('#guarantor_id').val(); + if ( guarantor_id ) { + fieldset.find('.new_guarantor_id').first().val( guarantor_id ); + fieldset.find('.new_guarantor_id_text').first().text( guarantor_id ); + } else { + fieldset.find('.guarantor_id').first().hide(); + } + $('#guarantor_id').val(""); - var guarantor_surname = $('#guarantor_surname').val(); - fieldset.find('.new_guarantor_surname').first().val( guarantor_surname ); - fieldset.find('.new_guarantor_surname_text').first().text( guarantor_surname ); - $('#guarantor_surname').val(""); + var guarantor_surname = $('#guarantor_surname').val(); + fieldset.find('.new_guarantor_surname').first().val( guarantor_surname ); + fieldset.find('.new_guarantor_surname_text').first().text( guarantor_surname ); + $('#guarantor_surname').val(""); - var guarantor_firstname = $('#guarantor_firstname').val(); - fieldset.find('.new_guarantor_firstname').first().val( guarantor_firstname ); - fieldset.find('.new_guarantor_firstname_text').first().text( guarantor_firstname ); - $('#guarantor_firstname').val(""); + var guarantor_firstname = $('#guarantor_firstname').val(); + fieldset.find('.new_guarantor_firstname').first().val( guarantor_firstname ); + fieldset.find('.new_guarantor_firstname_text').first().text( guarantor_firstname ); + $('#guarantor_firstname').val(""); - var guarantor_relationship = $('#relationship').val(); - fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship ); - $('#relationship').find('option:eq(0)').prop('selected', true);; + var guarantor_relationship = $('#relationship').val(); + fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship ); + $('#relationship').find('option:eq(0)').prop('selected', true); - $('#guarantor_relationships').append( fieldset ); - fieldset.show(); + fieldset.find('.guarantor-details').first().attr( 'data-borrowernumber', borrower.borrowernumber ); + console.log( fieldset.find('.guarantor-details').first().data() ); + + $('#guarantor_relationships').append( fieldset ); + fieldset.show(); + } return 0; } --