From c7bae48640125c37c29b67858be014a01798c196 Mon Sep 17 00:00:00 2001 From: Nicolas Legrand Date: Tue, 28 Apr 2020 12:02:15 +0200 Subject: [PATCH] Bug 24201: (follow-up) add desk choice with library choice You should be able to add desk choice when you are logging in or changing library. Test plan: 1. apply patch 2. log in, you should see desks if they are defined. All are disabled. 3. when choosing a library, it should enabled all desks it has and pick one. 4. the desk should be in your session 5. change library from intranet 6. you should have the same behaviours --- C4/Auth.pm | 11 ++- Koha/Template/Plugin/Desks.pm | 17 ++++- circ/selectdesk.pl | 87 ---------------------- circ/set-library.pl | 24 +++++- .../intranet-tmpl/prog/en/includes/circ-nav.inc | 4 - .../intranet-tmpl/prog/en/includes/header.inc | 5 -- .../prog/en/includes/html_helpers.inc | 11 +++ .../prog/en/includes/intranet-bottom.inc | 1 + .../intranet-tmpl/prog/en/includes/js_includes.inc | 3 + koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt | 16 ++++ .../prog/en/modules/circ/circulation-home.tt | 6 -- .../prog/en/modules/circ/set-library.tt | 20 ++++- koha-tmpl/intranet-tmpl/prog/js/desk_selection.js | 42 +++++++++++ 13 files changed, 139 insertions(+), 108 deletions(-) delete mode 100755 circ/selectdesk.pl create mode 100644 koha-tmpl/intranet-tmpl/prog/js/desk_selection.js diff --git a/C4/Auth.pm b/C4/Auth.pm index 28cb8f4..6ea435e 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1070,7 +1070,7 @@ sub checkauth { C4::Context->_unset_userenv($sessionID); } my ( $borrowernumber, $firstname, $surname, $userflags, - $branchcode, $branchname, $emailaddress ); + $branchcode, $branchname, $emailaddress, $desk_id, $desk_name ); if ( $return == 1 ) { my $select = " @@ -1114,6 +1114,11 @@ sub checkauth { my $library = Koha::Libraries->find($branchcode); $branchname = $library? $library->branchname: ''; } + if ( $query->param('desk_id') ) { + $desk_id = $query->param('desk_id'); + my $desk = Koha::Desks->find($desk_id); + $desk_name = $desk ? $desk->desk_name : ''; + } my $branches = { map { $_->branchcode => $_->unblessed } Koha::Libraries->search }; if ( $type ne 'opac' and C4::Context->boolean_preference('AutoLocation') ) { @@ -1149,6 +1154,8 @@ sub checkauth { $session->param( 'surname', $surname ); $session->param( 'branch', $branchcode ); $session->param( 'branchname', $branchname ); + $session->param( 'desk_id', $desk_id); + $session->param( 'desk_name', $desk_name); $session->param( 'flags', $userflags ); $session->param( 'emailaddress', $emailaddress ); $session->param( 'ip', $session->remote_addr() ); @@ -1164,7 +1171,7 @@ sub checkauth { $session->param('surname'), $session->param('branch'), $session->param('branchname'), $session->param('flags'), $session->param('emailaddress'), $session->param('shibboleth'), - $session->param('desk_id'), $session->param('desk_name') + $session->param('desk_id'), $session->param('desk_name') ); } diff --git a/Koha/Template/Plugin/Desks.pm b/Koha/Template/Plugin/Desks.pm index 27d0297..4216497 100644 --- a/Koha/Template/Plugin/Desks.pm +++ b/Koha/Template/Plugin/Desks.pm @@ -73,7 +73,7 @@ sub GetLoggedInDeskName { [% Desks.ListForLibrary %] -returns all desks existing at the library +returns all desks existing at the current library =cut @@ -87,4 +87,19 @@ sub ListForLibrary { ); } +=head3 all + +[% Desks.all %] + +returns all desks existing at all libraries + +=cut + + +sub all { + + my ( $self ) = @_; + return Koha::Desks->search( )->unblessed; +} + 1; diff --git a/circ/selectdesk.pl b/circ/selectdesk.pl deleted file mode 100755 index 7589bac..0000000 --- a/circ/selectdesk.pl +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/perl - -# Copyright (C) 2020 BULAC -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -use Modern::Perl; -use CGI qw ( -utf8 ); - -use C4::Context; -use C4::Output; -use C4::Auth qw/:DEFAULT get_session/; -use C4::Koha; -use Koha::Desks; - -my $query = CGI->new(); - -my ( $template, $borrowernumber, $cookie ) = get_template_and_user( - { - template_name => "circ/selectdesk.tt", - query => $query, - type => "intranet", - debug => 1, - authnotrequired => 0, - flagsrequired => { catalogue => 1, }, - } -); - -my $sessionID = $query->cookie("CGISESSID"); -my $session = get_session($sessionID); - -my $branch = C4::Context->userenv->{'branch'}; -my $searchfield = $query->param('searchfield'); -my $desks_lists; -if ($branch) { - $desks_lists = Koha::Desks->search( { branchcode => $branch } )->unblessed; -} -else { - $desks_lists = Koha::Desks->search( )->unblessed; -} - -my $desk_id = $query->param('desk_id'); - -my $userenv_desk = C4::Context->userenv->{'desk_id'} || ''; -my $updated = ''; - -if ($desk_id) { - if ( !$userenv_desk or $userenv_desk ne $desk_id ) { - my $desk = Koha::Desks->find( { desk_id => $desk_id } ); - $template->param( LoginDeskname => $desk->desk_name ); - $template->param( LoginDeskid => $desk->desk_id ); - $session->param( desk_name => $desk->desk_name ); - $session->param( desk_id => $desk->desk_id ); - $updated = 1; - } -} -else { - $desk_id = $userenv_desk; -} - -$template->param( updated => \$updated ); - -my $referer = $query->param('oldreferer') || $ENV{HTTP_REFERER}; -if ($updated) { - print $query->redirect( $referer || '/cgi-bin/koha/mainpage.pl' ); -} - -$template->param( - referer => $referer, - desks_list => $desks_lists, - desk_id => $desk_id, -); - -output_html_with_http_headers $query, $cookie, $template->output; diff --git a/circ/set-library.pl b/circ/set-library.pl index 375a7f7..775d824 100755 --- a/circ/set-library.pl +++ b/circ/set-library.pl @@ -26,6 +26,7 @@ use C4::Auth qw/:DEFAULT get_session/; use C4::Koha; use Koha::BiblioFrameworks; use Koha::Libraries; +use Koha::Desks; my $query = CGI->new(); @@ -42,7 +43,9 @@ my $sessionID = $query->cookie("CGISESSID"); my $session = get_session($sessionID); my $branch = $query->param('branch' ); +my $desk_id = $query->param('desk_id'); my $userenv_branch = C4::Context->userenv->{'branch'} || ''; +my $userenv_desk = C4::Context->userenv->{'desk_id'} || ''; my @updated; # $session lddines here are doing the updating @@ -56,11 +59,28 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) { $session->flush(); push @updated, { updated_branch => 1, - old_branch => $userenv_branch, + old_branch => $userenv_branch, }; } # else branch the same, no update + if ( $desk_id && (!$userenv_desk or $userenv_desk ne $desk_id) ) { + my $desk = Koha::Desks->find( { desk_id => $desk_id } ); + my $old_desk_name = ''; + if ($userenv_desk) { + $old_desk_name = Koha::Desks->find( { desk_id => $userenv_desk })->desk_name; + } + $template->param( LoginDeskname => $desk->desk_name ); + $template->param( LoginDeskid => $desk->desk_id ); + $session->param( desk_name => $desk->desk_name ); + $session->param( desk_id => $desk->desk_id ); + $session->flush(); + push @updated, { + updated_desk => 1, + old_desk => $old_desk_name, + }; + } } else { $branch = $userenv_branch; # fallback value + $desk_id = $userenv_desk; } $template->param(updated => \@updated) if (scalar @updated); @@ -69,6 +89,7 @@ my @recycle_loop; foreach ($query->param()) { $_ or next; # disclude blanks $_ eq "branch" and next; # disclude branch + $_ eq "desk_id" and next; # disclude desk_id $_ eq "oldreferer" and next; # disclude oldreferer push @recycle_loop, { param => $_, @@ -87,6 +108,7 @@ if (scalar @updated and not scalar @recycle_loop) { $template->param( referer => $referer, branch => $branch, + desk_id => $desk_id, recycle_loop=> \@recycle_loop, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc index 574224c..979871a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc @@ -1,5 +1,4 @@ [% USE Branches %] -[% USE Desks %]