Bug 26597: Fixing the populate of fields when using the REST API route

This attachment correct the populate of fields by using the api mapping.
Now All fields are populated following the selected PrefillGuaranteeField options

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Emmi Takkinen <emmi.takkinen@koha-suomi.fi>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Hammat Wele 2022-12-13 22:27:29 +00:00 committed by Katrin Fischer
parent d3822c7d86
commit b9e4b88d32
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 13 additions and 6 deletions

View File

@ -1971,6 +1971,9 @@ legend:hover {
[% IF guarantor_attributes %]
guarantor_attributes = [% To.json(guarantor_attributes) %];
[% END %]
[% IF to_api_mapping %]
to_api_mapping = [% To.json(to_api_mapping) %];
[% END %]
var TalkingTechItivaPhoneNotification = [% Koha.Preference('TalkingTechItivaPhoneNotification') || 0 | html %];
var PhoneNotification = [% Koha.Preference('PhoneNotification') || 0 | html %];

View File

@ -122,16 +122,17 @@ function select_user(borrowernumber, borrower, relationship) {
fieldset.find('.new_guarantor_relationship').val(relationship);
}
if(typeof guarantor_attributes !== 'undefined') {
if(typeof guarantor_attributes !== 'undefined' && to_api_mapping) {
$.ajax({
url: '/api/v1/patrons/'+borrowernumber,
method: "GET",
dataType: 'json',
success: function(data){
for (var i = 0; i < parseInt(guarantor_attributes.length, 10); i++) {
var attribute = guarantor_attributes[i];
if ( data[attribute] != null && document.forms.entryform[attribute].value == "" ) {
document.forms.entryform[attribute].value = data[attribute];
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];
}
}
}

View File

@ -618,7 +618,10 @@ if (C4::Context->preference("IndependentBranches")) {
# Define the fields to be pre-filled in guarantee records
my $prefillguarantorfields=C4::Context->preference("PrefillGuaranteeField");
my @prefill_fields=split(/\,/,$prefillguarantorfields);
$template->param( guarantor_attributes => \@prefill_fields );
$template->param(
guarantor_attributes => \@prefill_fields,
to_api_mapping => Koha::Patron->new->to_api_mapping
);
if ($op eq 'add_form'){
if ($guarantor_id) {