Bug 35329: Move patron search to modal - routing list

The behaviour is a bit different here. Adding a patron from the popup
refreshed the parent page with the newly added patron.

With this patch the refresh of the page will happen when the modal is
closed (if patrons have been added).

Test plan:
Create a subscription, receive one item, create a routing list.
Add users.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2024-01-05 14:50:38 +01:00
parent 7a25557bfe
commit e3743529eb
Signed by: jonathan.druart
GPG key ID: A085E712BEF0E0F0
2 changed files with 51 additions and 17 deletions

View file

@ -1,6 +1,8 @@
[% USE raw %]
[% USE KohaDates %]
[% SET footerjs = 1 %]
[% PROCESS 'i18n.inc' %]
[% PROCESS 'patron-search.inc' %]
[% INCLUDE 'doc-head-open.inc' %]
<title>[% IF ( op ) %]Create routing list[% ELSE %]Edit routing list[% END %] &rsaquo; [% title | html %] &rsaquo; Serials &rsaquo; Koha</title>
[% INCLUDE 'doc-head-close.inc' %]
@ -88,9 +90,10 @@
[% END %]
</table>
[% END %]
<input type="hidden" id="new_recipients" name="new_recipients" value="">
<p style="margin-left:10em;">
<a href="#" id="add_recipients"><i class="fa fa-plus"></i> Add recipients</a>
<a href="#patron_search_modal" id="add_recipients" data-toggle="modal"><i class="fa fa-plus"></i> Add recipients</a>
[% IF memberloop %]
<a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid | uri %]&amp;op=delete"><i class="fa fa-trash-can"></i> Delete all</a>
[% END %]
@ -116,10 +119,6 @@
[% MACRO jsinclude BLOCK %]
<script>
$(document).ready(function(){
$("#add_recipients").on("click",function(e){
e.preventDefault();
userPopup();
});
$(".itemrank").on("change",function(){
var subscriptionid = $(this).data("subscriptionid");
var routingid = $(this).data("routingid");
@ -131,17 +130,50 @@
window.location.href=mylocation;
}
function userPopup() {
window.open("/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add",
'PatronPopup',
'width=1024,height=768,scrollbars=yes,toolbar=no,'
+ 'scrollbars=yes,resize=yes'
);
function add_user(borrowernumber) {
let users = $("#new_recipients").val().split(':');
if ( !users.includes(borrowernumber) ) {
users.push(borrowernumber);
}
users = [...new Set(users)]; // unique
$("#new_recipients").val(users.filter(Number).join(':')); // remove empty and join
}
function add_user(borrowernumber) {
var myurl = "/cgi-bin/koha/serials/routing.pl?subscriptionid="+[% subscriptionid | html %]+"&borrowernumber="+borrowernumber+"&op=add";
window.location.href = myurl;
</script>
[% INCLUDE 'select2.inc' %]
[% SET columns = ['cardnumber','name','category','branch','action'] %]
[% PROCESS patron_search_modal columns => columns, modal_title => t("Add recipients") %]
[% PROCESS patron_search_js columns => columns, actions => ["add"], preview_on_name_click => 1 %]
<script>
$(document).on(
"hidden.bs.modal",
"#patron_search_modal",
add_new_recipients);
function add_new_recipients(e){
e.preventDefault();
let borrowernumbers = $("#new_recipients").val();
if(!borrowernumbers.length > 0) {
return;
}
$.ajax({
data: {
subscriptionid: [% subscriptionid | html %],
borrowernumbers,
op: 'add_new_recipients'
},
type: 'POST',
url: '/cgi-bin/koha/serials/routing.pl',
success: function (data) {
document.location.href = '/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid | uri %]';
return false;
},
error: function (data) {
alert(data);
},
});
}
</script>
[% END %]

View file

@ -41,7 +41,7 @@ my $query = CGI->new;
my $subscriptionid = $query->param('subscriptionid');
my $serialseq = $query->param('serialseq');
my $routingid = $query->param('routingid');
my $borrowernumber = $query->param('borrowernumber');
my $borrowernumbers = $query->param('borrowernumbers');
my $notes = $query->param('notes');
my $op = $query->param('op') || q{};
my $date_selected = $query->param('date_selected');
@ -66,8 +66,10 @@ if($op eq 'cud-delete'){
delroutingmember($routingid,$subscriptionid);
}
if($op eq 'cud-add'){
addroutingmember($borrowernumber,$subscriptionid);
if ( $op eq 'cud-add_new_recipients' ) {
for my $borrowernumber ( split ':', $borrowernumbers ) {
addroutingmember( $borrowernumber, $subscriptionid );
}
}
if($op eq 'cud-save'){
my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?');