From aee8503238e58ea9f5446ccf6d083dc81b17d24d Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 12 Aug 2019 14:14:39 -0400 Subject: [PATCH] Bug 14570: (QA follow-up) Fix issues in Guarantee context --- .../prog/en/modules/members/memberentrygen.tt | 12 ++-- koha-tmpl/intranet-tmpl/prog/js/members.js | 66 +++++++++++-------- 2 files changed, 44 insertions(+), 34 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 bdb7bf89f2..3ad4a6b121 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/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') %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index 5e12bb76fa..eb2b08cb7b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/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(""); - - 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(""); + $('#guarantor_id').val(borrower.borrowernumber); + $('#guarantor_surname').val(borrower.surname); + $('#guarantor_firstname').val(borrower.firstname); - var guarantor_relationship = $('#relationship').val(); - fieldset.find('.new_guarantor_relationship').first().val( guarantor_relationship ); - $('#relationship').find('option:eq(0)').prop('selected', true);; + var fieldset = $('#guarantor_template').clone(); + fieldset.removeAttr('id'); - $('#guarantor_relationships').append( fieldset ); - fieldset.show(); + 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_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); + + 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; } -- 2.20.1 (Apple Git-117)