From 6accf17f2699f0b4e4d64b0dc212665af73dd1be Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Tue, 30 May 2023 21:41:14 +0000 Subject: [PATCH 4/5] Bug 26597: (Fix) remove REST API call and retrieve the patron's data from borrower_data input This patch remove the REST API call in select_user function and retrieve the patron's data from borrower_data To test: 1) Apply patch 2) Search PrefillGuaranteeField preference and make sure some fields are selected 3) Select a user that can have a guarantor 4) In the edit form, click on "Search to add" in "Patron guarantor" fieldset 5) Choose a patron who has at least one of the fields in 1) set 6) Click Select 7) Confirm guarantee's information is filled from the guarantor's record 8) Check that any preexisting information is not overwritten Signed-off-by: Emmi Takkinen --- .../prog/en/modules/members/memberentrygen.tt | 6 ++--- koha-tmpl/intranet-tmpl/prog/js/members.js | 26 +++++-------------- members/memberentry.pl | 2 +- 3 files changed, 11 insertions(+), 23 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 14d8e210fe..c144e5eba0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1929,10 +1929,10 @@ legend:hover { }); [% END %] $("#guarantor_template").hide(); - var guarantor_attributes; + var prefill_fields; var to_api_mapping; - [% IF guarantor_attributes %] - guarantor_attributes = [% To.json(guarantor_attributes) %]; + [% IF prefill_fields %] + prefill_fields = [% To.json(prefill_fields)%]; [% END %] [% IF to_api_mapping %] to_api_mapping = [% To.json(to_api_mapping) %]; diff --git a/koha-tmpl/intranet-tmpl/prog/js/members.js b/koha-tmpl/intranet-tmpl/prog/js/members.js index ca4daaf287..576353400c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/members.js +++ b/koha-tmpl/intranet-tmpl/prog/js/members.js @@ -122,26 +122,14 @@ function select_user(borrowernumber, borrower, relationship) { fieldset.find('.new_guarantor_relationship').val(relationship); } - if(guarantor_attributes && to_api_mapping) { - $('#saverecord').prop('disabled', true); - $.ajax({ - url: '/api/v1/patrons/'+borrowernumber, - method: "GET", - dataType: 'json', - success: function(data){ - for (let i = 0; i < parseInt(guarantor_attributes.length, 10); i++) { - let attribute = guarantor_attributes[i]; - let key_data = to_api_mapping[attribute] || attribute; - if(data[key_data] != null && attribute in document.forms.entryform && document.forms.entryform[attribute].value == ""){ - document.forms.entryform[attribute].value = data[key_data]; - } - } - $('#saverecord').prop('disabled', false); - }, - error:function(){ - $('#saverecord').prop('disabled', false); + if ( prefill_fields && to_api_mapping) { + for (let i = 0; i < parseInt(prefill_fields.length, 10); i++) { + let field_name = prefill_fields[i]; + let attribute = to_api_mapping[field_name] || field_name; + if ( borrower[attribute] != null && document.forms.entryform[field_name] && document.forms.entryform[field_name].value == "" ) { + document.forms.entryform[field_name].value = borrower[attribute]; } - }); + } } } diff --git a/members/memberentry.pl b/members/memberentry.pl index a68daea52f..93268578b4 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -598,7 +598,7 @@ if (C4::Context->preference("IndependentBranches")) { my $prefillguarantorfields=C4::Context->preference("PrefillGuaranteeField"); my @prefill_fields=split(/\,/,$prefillguarantorfields); $template->param( - guarantor_attributes => \@prefill_fields, + prefill_fields => \@prefill_fields, to_api_mapping => Koha::Patron->new->to_api_mapping ); -- 2.34.1