Bugzilla – Attachment 121129 Details for
Bug 28377
Use the API to suspend/resume holds
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28377: Use the API to suspend/resume holds
Bug-28377-Use-the-API-to-suspendresume-holds.patch (text/plain), 7.60 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-05-18 20:52:19 UTC
(
hide
)
Description:
Bug 28377: Use the API to suspend/resume holds
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-05-18 20:52:19 UTC
Size:
7.60 KB
patch
obsolete
>From 2e9cc6eaa595ff1969a59b6bde55247287d10add Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 13 May 2021 17:37:44 -0300 >Subject: [PATCH] Bug 28377: Use the API to suspend/resume holds > >This patch makes the patron page (detail and circulation) use the API to >suspend/resume holds on the holds tab. > >It previously used the old svc/ scripts we plan to replace. > >To test >1. Have a patron with some holds >2. Play with suspending/resuming holds. Include the indefinite > suspension. >=> SUCCESS: Everything works as usual >3. Apply this patch >4. Repeat 2 >=> SUCCESS: Nothing changed, a soft breeze surprises you >5. Sign off :-D >--- > .../prog/en/modules/circ/circulation.tt | 1 + > .../prog/en/modules/members/moremember.tt | 1 + > koha-tmpl/intranet-tmpl/prog/js/holds.js | 73 ++++++++++++------- > 3 files changed, 48 insertions(+), 27 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >index fb3abec2200..9d3d29244ae 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >@@ -1172,6 +1172,7 @@ > [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %] > [% INCLUDE 'timepicker.inc' %] > [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %] >+ [% INCLUDE 'js-date-format.inc' %] > <script> > /* Set some variable needed in circulation.js */ > var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]"; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >index cd416da0ece..cd47f5cdeb3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >@@ -933,6 +933,7 @@ > [% INCLUDE 'calendar.inc' %] > [% Asset.js("lib/jquery/plugins/jquery-ui-timepicker-addon.min.js") | $raw %] > [% INCLUDE 'timepicker.inc' %] >+ [% INCLUDE 'js-date-format.inc' %] > <script> > /* Set some variable needed in circulation.js */ > var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]"; >diff --git a/koha-tmpl/intranet-tmpl/prog/js/holds.js b/koha-tmpl/intranet-tmpl/prog/js/holds.js >index e076fa55367..fbd58829081 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/holds.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/holds.js >@@ -1,5 +1,23 @@ > /* global __ dataTablesDefaults borrowernumber SuspendHoldsIntranet */ > $(document).ready(function() { >+ >+ function suspend_hold(hold_id, end_date) { >+ return $.ajax({ >+ method: 'POST', >+ url: '/api/v1/holds/'+encodeURIComponent(hold_id)+'/suspension', >+ data: function () { >+ if ( end_date !== null ) return JSON.stringify({ "end_date": end_date }) >+ } >+ }); >+ } >+ >+ function resume_hold(hold_id) { >+ return $.ajax({ >+ method: 'DELETE', >+ url: '/api/v1/holds/'+encodeURIComponent(hold_id)+'/suspension' >+ }); >+ } >+ > var holdsTable; > > // Don't load holds table unless it is clicked on >@@ -131,10 +149,10 @@ $(document).ready(function() { > if ( oObj.found ) { > return ""; > } else if ( oObj.suspend == 1 ) { >- return "<a class='hold-resume btn btn-default btn-xs' id='resume" + oObj.reserve_id + "'>" >+ return "<a class='hold-resume btn btn-default btn-xs' data-hold-id='" + oObj.reserve_id + "'>" > +"<i class='fa fa-play'></i> " + __("Resume") + "</a>"; > } else { >- return "<a class='hold-suspend btn btn-default btn-xs' id='suspend" + oObj.reserve_id + "'>" >+ return "<a class='hold-suspend btn btn-default btn-xs' data-hold-id='" + oObj.reserve_id + "' data-hold-title='"+ oObj.title +"'>" > +"<i class='fa fa-pause'></i> " + __("Suspend") + "</a>"; > } > } >@@ -197,25 +215,24 @@ $(document).ready(function() { > > $('#holds-table').on( 'draw.dt', function () { > $(".hold-suspend").on( "click", function() { >- var id = $(this).attr("id").replace("suspend", ""); >- var hold = holds[id]; >- $("#suspend-modal-title").html( hold.title ); >- $("#suspend-modal-reserve_id").val( hold.reserve_id ); >+ var hold_id = $(this).data('hold-id'); >+ var hold_title = $(this).data('hold-title'); >+ $("#suspend-modal-title").html( hold_title ); >+ $("#suspend-modal-submit").data( 'hold-id', hold_id ); > $('#suspend-modal').modal('show'); > }); > >- $(".hold-resume").on( "click", function() { >- var id = $(this).attr("id").replace("resume", ""); >- var hold = holds[id]; >- $.post('/cgi-bin/koha/svc/hold/resume', { "reserve_id": hold.reserve_id }, function( data ){ >- if ( data.success ) { >- holdsTable.api().ajax.reload(); >- } else { >- if ( data.error == "HOLD_NOT_FOUND" ) { >- alert( __("Unable to resume, hold not found") ); >+ $(".hold-resume").on("click", function () { >+ var hold_id = $(this).data('hold-id'); >+ resume_hold( >+ hold_id >+ ).success(function () { >+ holdsTable.api().ajax.reload(); >+ }).error(function (jqXHR, textStatus, errorThrown) { >+ if (jqXHR.status === 404) { >+ alert(__("Unable to resume, hold not found")); > holdsTable.api().ajax.reload(); > } >- } > }); > }); > >@@ -286,19 +303,21 @@ $(document).ready(function() { > > $("#suspend-modal-submit").on( "click", function( e ) { > e.preventDefault(); >- $.post('/cgi-bin/koha/svc/hold/suspend', $('#suspend-modal-form').serialize(), function( data ){ >- $('#suspend-modal').modal('hide'); >- if ( data.success ) { >- holdsTable.api().ajax.reload(); >- } else { >- if ( data.error == "INVALID_DATE" ) { >- alert( __("Unable to suspend hold, invalid date") ); >- } >- else if ( data.error == "HOLD_NOT_FOUND" ) { >- alert( __("Unable to suspend hold, hold not found") ); >+ var suspend_until_date = $("#suspend-modal-until").datepicker("getDate"); >+ if ( suspend_until_date !== null ) suspend_until_date = $date(suspend_until_date, {dateformat:"rfc3339"}); >+ suspend_hold( >+ $(this).data('hold-id'), >+ suspend_until_date >+ ).success(function () { >+ holdsTable.api().ajax.reload(); >+ }).error(function (jqXHR, textStatus, errorThrown) { >+ if (jqXHR.status === 404) { >+ alert(__("Unable to resume, hold not found")); > holdsTable.api().ajax.reload(); > } >- } >+ }).done(function() { >+ $("#suspend-modal-until").val(""); // clean the input >+ $('#suspend-modal').modal('hide'); > }); > }); > }); >-- >2.31.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28377
:
121129
|
121130
|
125052
|
125053
|
125057
|
125058
|
127270
|
127271
|
128380
|
128381
|
128402
|
128403
|
128404
|
128405
|
128458
|
128461