@@ -, +, @@
Log in with staff patron C having edit_public_lists.
Pick a public list. Choose Transfer. Select a patron.
Submit and check if transfer was successful.
Pick a staff user D. Temporary enable edit_public_lists.
Add another private tab. Login with D.
Pick a public list. Transfer. Choose another patron. Wait.
Switch tab: remove added permission from D.
Switch tab again: Submit transfer form. Error? Close tab.
Pick a public list. Transfer. Choose another patron. Wait.
Open another tab. Delete the selected public list.
Close tab. Submit the transfer. Not exist error?
Pick a public list. Transfer. Choose another patron. Wait.
Open another tab. Delete selected patron.
Close tab. Submit transfer. Patron not found error?
---
.../prog/en/modules/virtualshelves/shelves.tt | 72 ++++++++++++++++++-
virtualshelves/shelves.pl | 19 +++++
2 files changed, 90 insertions(+), 1 deletion(-)
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt
@@ -114,6 +114,10 @@
[% END %]
+
+ [% IF op == 'transfer' %]
+
Transfer list [% shelf.shelfname | html %]
+ [% END %]
@@ -122,7 +126,7 @@
- [% INCLUDE 'virtualshelves-toolbar.inc' %]
+ [% IF op != 'transfer' %][% INCLUDE 'virtualshelves-toolbar.inc' %][% END %]
[% FOR m IN messages %]
@@ -169,20 +173,57 @@
You do not have permission to delete this list.
[% CASE 'unauthorized_on_add_biblio' %]
You do not have permission to add a record to this list.
+ [% CASE 'unauthorized_transfer' %]
+ You do not have permission to transfer ownership of this list.
+ [% CASE 'new_owner_not_found' %]
+ The new owner could not be found anymore.
[% CASE 'no_biblio_removed' %]
No record was removed.
+
[% CASE 'Koha::Exceptions::Virtualshelf::DuplicateObject' %]
An error occurred when creating this list. The name [% shelfname | html %] already exists.
[% CASE 'Koha::Exceptions::Virtualshelf::UseDbAdminAccount' %]
List could not be created. (Do not use the database administrator account.)
[% CASE 'DBIx::Class::Exception' %]
[% m.msg | html %]
+
[% CASE %]
[% m.code | html %] [% m.msg | html %]
[% END %]
[% END %]
+[% IF op == 'transfer' %]
+ Transfer ownership of public list [% shelf.shelfname | html %]
+
+
+[% END %]
+
[% IF op == 'view' %]
Contents of [% shelf.shelfname | html %]
[% IF itemsloop %]
@@ -848,6 +889,35 @@
});
[% END %]
+
+ [% IF op == 'transfer' %]
+ $(document).ready(function() {
+ $('#find_patron').autocomplete({
+ source: "/cgi-bin/koha/circ/ysearch.pl",
+ minLength: 3,
+ select: function( event, ui ) {
+ $('#new_owner_name').html( ui.item.firstname + " " + ui.item.surname );
+ $('#new_owner').val( ui.item.borrowernumber );
+ $('#find_patron').val('').focus();
+ return false;
+ },
+ }).data('ui-autocomplete')._renderItem = function( ul, item ) {
+ return $('')
+ .data( 'ui-autocomplete-item', item )
+ .append( '' + item.surname + ', ' + item.firstname + '' )
+ .appendTo(ul);
+ };
+
+ $('#transferform').submit(function() {
+ if( $('#new_owner').val() == '' ) {
+ alert( _("Please select a new owner first") );
+ return false;
+ }
+ return true;
+ });
+ });
+ [% END %]
+
[% END %]
--- a/virtualshelves/shelves.pl
+++ a/virtualshelves/shelves.pl
@@ -234,6 +234,25 @@ if ( $op eq 'add_form' ) {
push @messages, { type => 'alert', code => 'does_not_exist' };
}
$op = $referer;
+} elsif ( $op eq 'transfer' ) {
+ $shelfnumber = $query->param('shelfnumber');
+ $shelf = Koha::Virtualshelves->find($shelfnumber) if $shelfnumber;
+ my $new_owner = $query->param('new_owner'); # is a borrowernumber
+
+ if( $new_owner ) {
+ $op = 'list';
+ # First check: shelf found, permission, patron found?
+ if( !$shelf ) {
+ push @messages, { type => 'alert', code => 'does_not_exist' };
+ } elsif( !haspermission(C4::Context->userenv->{id}, { lists => 'edit_public_lists' }) ) {
+ push @messages, { type => 'alert', code => 'unauthorized_transfer' };
+ } elsif( !Koha::Patrons->find($new_owner) ) {
+ push @messages, { type => 'alert', code => 'new_owner_not_found' };
+ $op = 'transfer'; # find again..
+ } else { # success
+ $shelf->owner($new_owner)->store;
+ }
+ }
}
if ( $op eq 'view' ) {
--