Skip to content

Commit e374352

Browse files
committed
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>
1 parent 7a25557 commit e374352

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

koha-tmpl/intranet-tmpl/prog/en/modules/serials/routing.tt

+46-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[% USE raw %]
22
[% USE KohaDates %]
33
[% SET footerjs = 1 %]
4+
[% PROCESS 'i18n.inc' %]
5+
[% PROCESS 'patron-search.inc' %]
46
[% INCLUDE 'doc-head-open.inc' %]
57
<title>[% IF ( op ) %]Create routing list[% ELSE %]Edit routing list[% END %] &rsaquo; [% title | html %] &rsaquo; Serials &rsaquo; Koha</title>
68
[% INCLUDE 'doc-head-close.inc' %]
@@ -88,9 +90,10 @@
8890
[% END %]
8991
</table>
9092
[% END %]
93+
<input type="hidden" id="new_recipients" name="new_recipients" value="">
9194

9295
<p style="margin-left:10em;">
93-
<a href="#" id="add_recipients"><i class="fa fa-plus"></i> Add recipients</a>
96+
<a href="#patron_search_modal" id="add_recipients" data-toggle="modal"><i class="fa fa-plus"></i> Add recipients</a>
9497
[% IF memberloop %]
9598
<a href="/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid | uri %]&amp;op=delete"><i class="fa fa-trash-can"></i> Delete all</a>
9699
[% END %]
@@ -116,10 +119,6 @@
116119
[% MACRO jsinclude BLOCK %]
117120
<script>
118121
$(document).ready(function(){
119-
$("#add_recipients").on("click",function(e){
120-
e.preventDefault();
121-
userPopup();
122-
});
123122
$(".itemrank").on("change",function(){
124123
var subscriptionid = $(this).data("subscriptionid");
125124
var routingid = $(this).data("routingid");
@@ -131,17 +130,50 @@
131130
window.location.href=mylocation;
132131
}
133132

134-
function userPopup() {
135-
window.open("/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add",
136-
'PatronPopup',
137-
'width=1024,height=768,scrollbars=yes,toolbar=no,'
138-
+ 'scrollbars=yes,resize=yes'
139-
);
133+
function add_user(borrowernumber) {
134+
let users = $("#new_recipients").val().split(':');
135+
if ( !users.includes(borrowernumber) ) {
136+
users.push(borrowernumber);
137+
}
138+
users = [...new Set(users)]; // unique
139+
$("#new_recipients").val(users.filter(Number).join(':')); // remove empty and join
140140
}
141141

142-
function add_user(borrowernumber) {
143-
var myurl = "/cgi-bin/koha/serials/routing.pl?subscriptionid="+[% subscriptionid | html %]+"&borrowernumber="+borrowernumber+"&op=add";
144-
window.location.href = myurl;
142+
</script>
143+
144+
[% INCLUDE 'select2.inc' %]
145+
[% SET columns = ['cardnumber','name','category','branch','action'] %]
146+
[% PROCESS patron_search_modal columns => columns, modal_title => t("Add recipients") %]
147+
[% PROCESS patron_search_js columns => columns, actions => ["add"], preview_on_name_click => 1 %]
148+
149+
<script>
150+
$(document).on(
151+
"hidden.bs.modal",
152+
"#patron_search_modal",
153+
add_new_recipients);
154+
155+
function add_new_recipients(e){
156+
e.preventDefault();
157+
let borrowernumbers = $("#new_recipients").val();
158+
if(!borrowernumbers.length > 0) {
159+
return;
160+
}
161+
$.ajax({
162+
data: {
163+
subscriptionid: [% subscriptionid | html %],
164+
borrowernumbers,
165+
op: 'add_new_recipients'
166+
},
167+
type: 'POST',
168+
url: '/cgi-bin/koha/serials/routing.pl',
169+
success: function (data) {
170+
document.location.href = '/cgi-bin/koha/serials/routing.pl?subscriptionid=[% subscriptionid | uri %]';
171+
return false;
172+
},
173+
error: function (data) {
174+
alert(data);
175+
},
176+
});
145177
}
146178
</script>
147179
[% END %]

serials/routing.pl

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ =head1 Routing.pl
4141
my $subscriptionid = $query->param('subscriptionid');
4242
my $serialseq = $query->param('serialseq');
4343
my $routingid = $query->param('routingid');
44-
my $borrowernumber = $query->param('borrowernumber');
44+
my $borrowernumbers = $query->param('borrowernumbers');
4545
my $notes = $query->param('notes');
4646
my $op = $query->param('op') || q{};
4747
my $date_selected = $query->param('date_selected');
@@ -66,8 +66,10 @@ =head1 Routing.pl
6666
delroutingmember($routingid,$subscriptionid);
6767
}
6868

69-
if($op eq 'cud-add'){
70-
addroutingmember($borrowernumber,$subscriptionid);
69+
if ( $op eq 'cud-add_new_recipients' ) {
70+
for my $borrowernumber ( split ':', $borrowernumbers ) {
71+
addroutingmember( $borrowernumber, $subscriptionid );
72+
}
7173
}
7274
if($op eq 'cud-save'){
7375
my $sth = $dbh->prepare('UPDATE serial SET routingnotes = ? WHERE subscriptionid = ?');

0 commit comments

Comments
 (0)