From 3567f21ebb2aff72327b4c000df187dbb96275d3 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Tue, 1 Oct 2019 15:26:55 -0300 Subject: [PATCH] Bug 23710: Use API to place holds for patrons This patch effectively uses API to place holds for patrons. It adds a listener on submit event of the form in javascript, where it calls holds API. To test: 1. Place a hold on any biblio for a patron SUCCESS => hold is placed or rejected, but no blank page with JSON error is shown. 2. Place a multi hold for any patron SUCCESS => holds are placed or rejected, but no blank page with JSON error is shown. 3. Sign off Signed-off-by: Lisette Scheer Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- .../prog/en/modules/reserve/request.tt | 75 ++++++++++++++----- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt index eef3c049aa..10c8cd7a08 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt @@ -375,6 +375,9 @@ [% END %] +
+
+
Hold details
@@ -443,6 +446,7 @@
  • + Clear date
  • [% END %] @@ -450,6 +454,7 @@
  • + Clear date
  • @@ -977,6 +982,12 @@ $(".suspend_until_datepicker, .datepickerfrom, .datepickerto").datepicker("option", "minDate", 1); [% END %] + $(".datepickerto").datepicker("option", "altField", ".datepickerto_hidden"); + $(".datepickerto").datepicker("option", "altFormat", "yy-mm-dd"); + + $(".datepickerfrom").datepicker("option", "altField", ".datepickerfrom_hidden"); + $(".datepickerfrom").datepicker("option", "altFormat", "yy-mm-dd"); + var my_table = $("#requestspecific").dataTable($.extend(true, {}, dataTablesDefaults, { 'bPaginate': false, "sDom": '<"top pager"ilf>t', @@ -992,28 +1003,56 @@ "margin-right":"0em" }); - $("#club-request-form").on("submit", function() { + $("#club-request-form, #hold-request-form").on("submit", function() { let $t = $(this); $('.clubalert').addClass('hide'); - let options = { - url: $t.attr('action'), - method: $t.attr('method').toUpperCase(), - contentType: 'application/json', - data: JSON.stringify({ - biblio_id: biblionumber, - pickup_library_id: $('select[name="pickup"]').val() - }) + let biblionumbers = [biblionumber]; + let biblionumbers_text; + const data = { + pickup_library_id: $('select[name="pickup"]').val() }; if($('input[name="checkitem"]:checked').length) - options.data.item_id = $('input[name="checkitem"]:checked').val(); - $.ajax(options) - .then(function(result) { - let url = 'request.pl?biblionumber='+biblionumber+($('input[name="multi_hold"]').length && $('input[name="multi_hold"]').val()?'&multi_hold=1':''); - document.location = url; - }) - .fail(function(err) { - $('.clubalert').removeClass('hide').html(err.responseJSON.error); - }); + data.item_id = $('input[name="checkitem"]:checked').val(); + if($('input[name="borrowernumber"]').length) + data.patron_id = $('input[name="borrowernumber"]').val(); + if($('textarea[name="notes"]').length) + data.notes = $('textarea[name="notes"]').val()||null; + if($('.datepickerto_hidden').length) + data.expiration_date = $('.datepickerto_hidden').val()||null; + if($('.datepickerfrom_hidden').length) + data.hold_date = $('.datepickerfrom_hidden').val()||null; + if($('input[name="itemtype"]').length) { + data.item_type = $('input[name="itemtype"]').val()||null; + } + if($('input[name="biblionumbers"]').length) { + biblionumbers_text = $('input[name="biblionumbers"]').val(); + biblionumbers = biblionumbers_text.replace(/\/$/, '').split('/') + } + + const count = $('input[name="holds_to_place_count"]').length?$('input[name="holds_to_place_count"]').val():1; + biblionumbers.forEach(function(biblionumber) { + data.biblio_id = biblionumber; + let options = { + url: $t.attr('action'), + method: $t.attr('method').toUpperCase(), + contentType: 'application/json', + data: JSON.stringify(data) + }; + for(let i = 0; i < count; i++) { + $.ajax(options) + .then(function(result) { + let url = 'request.pl?biblionumber='+biblionumber; + if(biblionumbers_text) { + url = 'request.pl?biblionumbers='+biblionumbers_text+'&multi_hold=1'; + } + document.location = url; + }) + .fail(function(err) { + $('.clubalert, .holdalert').removeClass('hide').html(err.responseJSON.error); + }); + } + }); + return false; }); -- 2.39.5