Bug 24201: (follow-up) add desk choice with library choice
authorNicolas Legrand <nicolas.legrand@bulac.fr>
Tue, 28 Apr 2020 10:02:15 +0000 (12:02 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 7 Aug 2020 14:54:40 +0000 (16:54 +0200)
You should be able to add desk choice when you are logging in or
changing library.

Test plan:

1. apply patch
2. have at least three libraries, one without desk, one with one and
one with a few.
3. At login, when choosing a library, it should enable all desks it
has. Pick one.
4. the desk id and name should be set in your session and appear in
the top right, next to the library name.
5. change library and desks from intranet (at the set-library.pl page)
6. you should have the same behaviours
7. if you have a library without a desk, it should prompt you a '---'
option and no desks will be attached to the session.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

13 files changed:
C4/Auth.pm
Koha/Template/Plugin/Desks.pm
circ/selectdesk.pl [deleted file]
circ/set-library.pl
koha-tmpl/intranet-tmpl/prog/en/includes/circ-nav.inc
koha-tmpl/intranet-tmpl/prog/en/includes/header.inc
koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc
koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc
koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc
koha-tmpl/intranet-tmpl/prog/en/modules/auth.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation-home.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/set-library.tt
koha-tmpl/intranet-tmpl/prog/js/desk_selection.js [new file with mode: 0644]

index 17df921..c539678 100644 (file)
@@ -1066,7 +1066,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 = "
@@ -1110,6 +1110,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') ) {
 
@@ -1145,6 +1150,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() );
@@ -1160,7 +1167,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')
                 );
 
             }
index 27d0297..4216497 100644 (file)
@@ -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 (executable)
index 7589bac..0000000
+++ /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 <http://www.gnu.org/licenses>.
-
-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;
index 35b013c..3fdc0a7 100755 (executable)
@@ -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
@@ -58,8 +61,25 @@ if ( $branch and my $library = Koha::Libraries->find($branch) ) {
                 new_branch => $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);
@@ -68,6 +88,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 => $_,
@@ -86,6 +107,7 @@ if (scalar @updated and not scalar @recycle_loop) {
 $template->param(
     referer     => $referer,
     branch      => $branch,
+    desk_id     => $desk_id,
     recycle_loop=> \@recycle_loop,
 );
 
index 574224c..979871a 100644 (file)
@@ -1,5 +1,4 @@
 [% USE Branches %]
-[% USE Desks %]
 <div id="navmenu">
     <div id="navmenulist">
 
@@ -18,9 +17,6 @@
             [% IF ( AutoLocation ) %][% ELSE %][% IF ( IndependentBranches ) %][% ELSE %]
                 <li><a href="/cgi-bin/koha/circ/set-library.pl">Set library</a></li>
             [% END %][% END %]
-            [% IF Desks.ListForLibrary.count %]
-                <li><a href="/cgi-bin/koha/circ/selectdesk.pl">Set desk</a></li>
-            [% END %]
             [% IF ( fast_cataloging ) %][% IF ( CAN_user_editcatalogue_fast_cataloging ) %]
                 <li><a href="/cgi-bin/koha/cataloguing/addbiblio.pl?frameworkcode=FA">Fast cataloging</a></li>
             [% END %][% END %]
index 67e0a96..5435139 100644 (file)
                         <a class="toplinks" href="/cgi-bin/koha/circ/set-library.pl">Set library</a>
                     </li>
                     [% END %]
-                    [% IF Desks.ListForLibrary.count %]
-                    <li>
-                        <a class="toplinks" href="/cgi-bin/koha/circ/selectdesk.pl">Set desk</a>
-                    </li>
-                    [% END %]
                     [% IF EnableSearchHistory %]
                     <li>
                         <a class="toplinks" href="/cgi-bin/koha/catalogue/search-history.pl">Search history</a>
index b761688..e1f0ee2 100644 (file)
@@ -8,6 +8,17 @@
     [% END %]
 [% END %]
 
+[% BLOCK options_for_desks %]
+                <option id="nodesk" value="">---</option>
+       [% FOREACH d IN desks %]
+            [% IF d.branchcode == branch %]
+                <option class="[% d.branchcode | html %]" value="[% d.desk_id | html %]" >[% d.desk_name | html %]</option>
+            [% ELSE %]
+                <option class="[% d.branchcode | html %]" value="[% d.desk_id | html %]" disabled hidden>[% d.desk_name | html %]</option>
+            [% END%]
+        [% END %]
+    [% END %]
+
 [% BLOCK options_for_authorised_value_categories %]
     [% FOREACH avc IN authorised_value_categories %]
         [% IF avc.selected %]
index e0bce02..27ba415 100644 (file)
@@ -73,5 +73,6 @@
         [% jsinclude | $raw # Parse the page template's JavaScript block if necessary %]
     [% END %]
 [% KohaPlugins.get_plugins_intranet_js | $raw %]
+
 </body>
 </html>
index 1acf183..cb2ca00 100644 (file)
@@ -25,6 +25,9 @@
 [% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %]
 <!-- koha core js -->
 [% Asset.js("js/staff-global.js") | $raw %]
+[% IF setdesk %]
+[% Asset.js("js/desk_selection.js") | $raw %]
+[% END %]
 
 [% INCLUDE 'validator-strings.inc' %]
 [% IF ( IntranetUserJS ) %]
index acdbeb3..2ae7993 100644 (file)
@@ -1,8 +1,12 @@
 [% USE raw %]
 [% USE Koha %]
 [% USE Branches %]
+[% USE Desks %]
 [% USE Categories %]
 [% SET footerjs = 1 %]
+[% IF Desks.all %]
+    [% SET setdesk = 1 %]
+[% END %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; 
     [% IF ( nopermission ) %]Access denied[% END %]
             [% END %]
         </select>
     </p>
+    [% IF Desks.all %]
+        <p>
+            <label for="desk">Desk:</label>
+            <select name="desk_id" id="desk_id" class="input" tabindex="3">
+                <option id="nodesk" value="">---</option>
+                    [% FOREACH d IN Desks.all %]
+                    <option class="[% d.branchcode | html %]" value="[% d.desk_id | html %]" disabled >[% d.desk_name | html %]</option>
+                    [% END %]
+            </select>
+        </p>
+</fieldset>
+[% END %]
 [% END %]
 
 <!-- <p><label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />Remember me</label></p> -->
index caf7f3d..fbabec6 100644 (file)
@@ -1,7 +1,6 @@
 [% USE raw %]
 [% USE Koha %]
 [% USE Branches %]
-[% USE Desks %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Circulation</title>
 [% INCLUDE 'doc-head-close.inc' %]
                             <a class="circ-button" href="/cgi-bin/koha/circ/set-library.pl"><i class="fa fa-home"></i> Set library</a>
                         </li>
                     [% END %]
-                    [% IF Desks.ListForLibrary.count %]
-                        <li>
-                            <a class="circ-button" href="/cgi-bin/koha/circ/selectdesk.pl"><i class="fa fa-location-arrow"></i> Set desk</a>
-                        </li>
-                    [% END %]
                     [% IF ( fast_cataloging ) %]
                         [% IF ( CAN_user_editcatalogue_fast_cataloging ) %]
                             <li>
index 4a5ac05..2d6242d 100644 (file)
@@ -1,5 +1,9 @@
 [% USE Branches %]
+[% USE Desks %]
 [% USE Koha %]
+[% IF Desks.all %]
+    [% SET setdesk = 1 %]
+[% END %]
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Circulation &rsaquo; Set library</title>
 [% INCLUDE 'doc-head-close.inc' %]
@@ -37,6 +41,8 @@ Updated:<ul>
     [% FOREACH update IN updated %]
     [% IF ( update.updated_branch ) %]
         <li>Library: [% update.old_branch or "?" | html %] &rArr; [% update.new_branch or "?" | html %]</li>
+    [% ELSIF (update.updated_desk) %]
+        <li>Desk: [% update.old_desk or "?" | html %] &rArr; [% LoginDeskname or "?" | html %]</li>
     [% ELSE %]
         <li>ERROR - unknown</li>
     [% END %]
@@ -63,11 +69,21 @@ Updated:<ul>
         <li><label for="branch">Choose library:</label>
         <select name="branch" id="branch">
             [% PROCESS options_for_libraries libraries => Branches.all( selected => branch ) %]
-                        [% PROCESS options_for_yallah yallah => Branches.all( selected => branch ) %]
         </select></li>
     [% END %]
     </ol>
 </fieldset>
+[% IF Desks.all %]
+<fieldset class="rows">
+    <legend>Set Desk</legend>
+    <ol>
+        <li><label for="desk">Choose Desk:</label>
+        <select name="desk_id" id="desk_id">
+            [% PROCESS options_for_desks desks => Desks.all( selected => desk_id ) %]
+        </select></li>
+    </ol>
+</fieldset>
+[% END %]
 <fieldset class="action">
     <input type="submit" value="Submit" />
     <a class="cancel" id="cancel_set_library" href="[% referer or '/cgi-bin/koha/circ/circulation.pl' %]">Cancel</a>
diff --git a/koha-tmpl/intranet-tmpl/prog/js/desk_selection.js b/koha-tmpl/intranet-tmpl/prog/js/desk_selection.js
new file mode 100644 (file)
index 0000000..ab42768
--- /dev/null
@@ -0,0 +1,42 @@
+$(document).ready(function() {
+    $("#desk_id").children().each(function() {
+        var selectedBranch = $("#branch"). children("option:selected"). val();
+        if ($(this).attr('id') === "nodesk") { //set no desk by default, should be first element
+            $(this).prop("selected", true);
+            $(this).prop("disabled", false);
+            $(this).show();
+        }
+        else if ($(this).hasClass(selectedBranch)) {
+            $('#nodesk').prop("disabled", true); // we have desk, no need for nodesk option
+            $('#nodesk').hide();
+            $(this).prop("disabled", false);
+            $(this).show();
+            $(this).prop("selected", true)
+        } else {
+            $(this).prop("disabled", true);
+            $(this).hide();
+        }
+    });
+
+    $("#branch").on("change", function() {
+
+        $("#desk_id").children().each(function() {
+            var selectedBranch = $("#branch"). children("option:selected"). val();
+            if ($(this).attr('id') === "nodesk") { //set no desk by default, should be first element
+                $(this).prop("selected", true);
+                $(this).prop("disabled", false);
+                $(this).show();
+            }
+            else if ($(this).hasClass(selectedBranch)) {
+                $('#nodesk').prop("disabled", true); // we have desk, no need for nodesk option
+                $('#nodesk').hide();
+                $(this).prop("disabled", false);
+                $(this).show();
+                $(this).prop("selected", true)
+            } else {
+                $(this).prop("disabled", true);
+                $(this).hide();
+            }
+        });
+    });
+}) ;