From c1b56308dfc28e8856f04be125d1f612c9265597 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 16 Sep 2019 15:57:12 -0300 Subject: [PATCH] Bug 23623: Use the new API for changing privacy settings (guarantors) This patchset makes opac-memberentry.pl use the API instead of the old svc scripts for ajax calls, for setting privacy configuration in the OPAC. To test: 1) Disable OPACPrivacy 2) Enable AllowPatronToSetCheckoutsVisibilityForGuarantor 3) Enable AllowPatronToSetFinesVisibilityForGuarantor 4) Have a known patron be the guarantee of someone (so things display) 5) Log into the OPAC, go to the 'your personal details' tab 6) Change 'Allow your guarantor to view your current checkouts?' and click the 'Update' button. => SUCCESS: Operation succeeds 7) Reload the tab => SUCCESS: The page reflects the expected changes (i.e. the API did it right) 8) Repeat 6 and 7 with the 'Allow your guarantor to view your current fines?' option => SUCCESS: It works as well - Sign off :-D --- .../bootstrap/en/modules/opac-memberentry.tt | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index 9d23d27498..19f74a8bbe 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -1051,32 +1051,36 @@ [% IF Koha.Preference('AllowPatronToSetCheckoutsVisibilityForGuarantor') %] $('#update_privacy_guarantor_checkouts').click( function() { - $.post( "/cgi-bin/koha/svc/patron/show_checkouts_to_relatives", { privacy_guarantor_checkouts: $('#privacy_guarantor_checkouts').val() }, null, 'json') - .done(function( data ) { - var message; - if ( data.success ) { - message = _("Your setting has been updated!"); - } else { - message = _("Unable to update your setting!"); + var can_see_checkouts = $('#privacy_guarantor_checkouts').val() == 1; + $.ajax({ + url: "/api/v1/public/patrons/[% logged_in_user.borrowernumber %]/guarantors/can_see_checkouts" + type: "PUT", + data: JSON.stringify({ allowed: can_see_checkouts }), + contentType: "application/json", + success: function() { + $('#update_privacy_guarantor_checkouts_message').fadeIn("slow").text( _("Your setting has been updated!") ).delay( 5000 ).fadeOut("slow"); + }, + error: function() { + $('#update_privacy_guarantor_checkouts_message').fadeIn("slow").text( _("Unable to update your setting!") ).delay( 5000 ).fadeOut("slow"); } - - $('#update_privacy_guarantor_checkouts_message').fadeIn("slow").text( message ).delay( 5000 ).fadeOut("slow"); }); }); [% END %] [% IF Koha.Preference('AllowPatronToSetFinesVisibilityForGuarantor') %] $('#update_privacy_guarantor_fines').click( function() { - $.post( "/cgi-bin/koha/svc/patron/show_fines_to_relatives", { privacy_guarantor_fines: $('#privacy_guarantor_fines').val() }, null, 'json') - .done(function( data ) { - var message; - if ( data.success ) { - message = _("Your setting has been updated!"); - } else { - message = _("Unable to update your setting!"); + var can_see_charges = $('#privacy_guarantor_fines').val() == 1; + $.ajax({ + url: "/api/v1/public/patrons/[% logged_in_user.borrowernumber %]/guarantors/can_see_charges", + type: 'PUT', + data: JSON.stringify({ allowed: can_see_charges }), + contentType: 'application/json', + success: function() { + $('#update_privacy_guarantor_fines_message').fadeIn("slow").text( _("Your setting has been updated!") ).delay( 5000 ).fadeOut("slow"); + }, + error: function() { + $('#update_privacy_guarantor_fines_message').fadeIn("slow").text( _("Unable to update your setting!") ).delay( 5000 ).fadeOut("slow"); } - - $('#update_privacy_guarantor_fines_message').fadeIn("slow").text( message ).delay( 5000 ).fadeOut("slow"); }); }); [% END %] -- 2.23.0