From bb63dcf34227428f31641346da75e41e47aca2aa Mon Sep 17 00:00:00 2001 From: Joseph Sikowitz Date: Wed, 20 May 2020 17:11:01 -0400 Subject: [PATCH 2/2] Bug 14648: Batch Remove Reserve Items Adds batch remove reserves button to course-details.tt for users who have the permission to delete reserves and adds Javascript dialog box to warn users about batch remove action. Adds batch remove functionality to course-details.pl. Test plan 1. Install patch 2. Log in as user with permission to delete reserves 3. View a course reserve record with multiple items attached 4. There should now be a button that says "- Batch remove reserves" 5. When you click the button a dialog box should appear with a warning 6. Click "Ok" 7. All course reserves should be removed from the record 8. Add an item to more than course record 9. Redo 3-7 10. Items should have been removed from that course but remain on all other courses 11. Log in as a user without delete reserves permission 12. You should not see the batch remove option --- course_reserves/course-details.pl | 10 +++++++++- .../prog/en/modules/course_reserves/course-details.tt | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/course_reserves/course-details.pl b/course_reserves/course-details.pl index af1eb62..5175840 100755 --- a/course_reserves/course-details.pl +++ b/course_reserves/course-details.pl @@ -34,7 +34,7 @@ my $action = $cgi->param('action') || ''; my $course_id = $cgi->param('course_id'); my $flagsrequired; -$flagsrequired->{coursereserves} = 'delete_reserves' if ( $action eq 'del_reserve' ); +$flagsrequired->{coursereserves} = 'delete_reserves' if ( $action eq 'del_reserve' or $action eq 'batch_del' ); my $tmpl = ($course_id) ? "course-details.tt" : "invalid-course.tt"; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -49,6 +49,14 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( if ( $action eq 'del_reserve' ) { DelCourseReserve( cr_id => scalar $cgi->param('cr_id') ); } +elsif ( $action eq 'batch_del' ) { + my $course_res = GetCourseReserves(course_id => $course_id); + foreach my $cr (@$course_res) { + if(exists $cr->{'cr_id'}) { + DelCourseReserve(cr_id => $cr->{cr_id}); + } + } +} my $course = GetCourse($course_id); my $course_reserves = GetCourseReserves( diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt index a1e04a9..157b4b7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt @@ -36,6 +36,9 @@ Add reserves Batch add reserves [% END %] + [% IF CAN_user_coursereserves_delete_reserves %] + Batch remove reserves + [% END %] [% IF ( CAN_user_coursereserves_manage_courses ) %] Edit course [% END %] @@ -263,6 +266,10 @@ return confirmDelete(_("Are you sure you want to remove this item from the course?")); }); + $("#rm_items").click(function(){ + return confirmDelete(_("Are you sure you want to remove all items from the course?")); + }); + $("#delete_course").click(function(){ [% SET count = course_reserves.size || 0 %] [% IF count == 1 %] -- 2.7.4