From e7dec207fa0d4223da29ee13808dd2e2caba259b Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Tue, 15 Jan 2008 11:39:17 -0600 Subject: [PATCH] Shelves - bugfix 1403 amongst others Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/VirtualShelves.pm | 20 ++--- C4/VirtualShelves/Page.pm | 82 ++++++++++--------- .../en/includes/virtualshelves-toolbar.inc | 9 +- .../en/modules/virtualshelves/shelves.tmpl | 57 ++++++++----- koha-tmpl/opac-tmpl/prog/en/js/script.js | 15 ++-- 5 files changed, 101 insertions(+), 82 deletions(-) diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index 1970ec00ae..b476eb440a 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -257,17 +257,15 @@ sub AddToShelf { my $sth = $dbh->prepare($query); $sth->execute( $shelfnumber, $biblionumber ); - unless ( $sth->rows ) { - # already on shelf - my $query = qq( - INSERT INTO virtualshelfcontents - (shelfnumber, biblionumber, flags) - VALUES - (?, ?, 0) - ); - $sth = $dbh->prepare($query); - $sth->execute( $shelfnumber, $biblionumber ); - } + ($sth->rows) and return undef; # already on shelf + my $query = qq( + INSERT INTO virtualshelfcontents + (shelfnumber, biblionumber, flags) + VALUES + (?, ?, 0) + ); + $sth = $dbh->prepare($query); + $sth->execute( $shelfnumber, $biblionumber ); } =item AddToShelfFromBiblio diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 108397d4f5..49f09c0fd4 100755 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -53,22 +53,36 @@ sub shelfpage ($$$$$) { ($pages{$type}) or $type = 'opac'; $query or die "No query"; $template or die "No template"; + $template->param( { loggedinuser => $loggedinuser } ); + my @paramsloop; + # getting the Shelves list + my $shelflist = GetShelves( $loggedinuser, 2 ); + my $op = $query->param('op'); # the format of this is unindented for ease of diff comparison to the old script +# Note: do not mistake the assignment statements below for comparisons! if ( $query->param('modifyshelfcontents') ) { - my $shelfnumber = $query->param('viewshelf'); - my $barcode = $query->param('addbarcode'); - my ($item) = GetItem( 0, $barcode ); - my ($biblio) = GetBiblioFromItemNumber($item->{'itemnumber'}); - if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ) ) { - AddToShelf( $biblio->{'biblionumber'}, $shelfnumber ); - foreach ( $query->param ) { - /REM-(\d*)/ or next; - $debug and warn "SHELVES: user $loggedinuser removing item $1 from shelf $shelfnumber"; - DelFromShelf( $1, $shelfnumber ); # $1 is biblionumber - } - } + my ($shelfnumber,$barcode,$item,$biblio); + if ($shelfnumber = $query->param('viewshelf')) { + if (ShelfPossibleAction($loggedinuser, $shelfnumber, 'manage')) { + if ($barcode = $query->param('addbarcode')) { + if ($item = GetItem( 0, $barcode )) { + $biblio = GetBiblioFromItemNumber($item->{'itemnumber'}); + AddToShelf($biblio->{'biblionumber'}, $shelfnumber) or + push @paramsloop, {duplicatebiblio=>$barcode}; + } else { push @paramsloop, {failgetitem=>$barcode}; } + } else { + (grep {/REM-(\d+)/} $query->param) or push @paramsloop, {nobarcode=>1}; + foreach ($query->param) { + /REM-(\d+)/ or next; + $debug and warn + "SHELVES: user $loggedinuser removing item $1 from shelf $shelfnumber"; + DelFromShelf($1, $shelfnumber); # $1 is biblionumber + } + } + } else { push @paramsloop, {nopermission=>$shelfnumber}; } + } else { push @paramsloop, {noshelfnumber=>1}; } } my $showadd = 1; @@ -87,10 +101,6 @@ if (defined $shelf_type) { $template->param(showprivateshelves => 1); } -# getting the Shelves list -my $shelflist = GetShelves( $loggedinuser, 2 ); -$template->param( { loggedinuser => $loggedinuser } ); -my $op = $query->param('op'); SWITCH: { if ( $op ) { @@ -112,9 +122,8 @@ SWITCH: { } last SWITCH; } - if ( $query->param('viewshelf') ) { + if (my $shelfnumber = $query->param('viewshelf') ) { #check that the user can view the shelf - my $shelfnumber = $query->param('viewshelf'); if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) { my $items = GetShelfContents($shelfnumber); $showadd = 1; @@ -127,11 +136,11 @@ SWITCH: { $template->param( shelfname => $shelflist->{$shelfnumber}->{'shelfname'}, shelfnumber => $shelfnumber, - viewshelf => $query->param('viewshelf'), + viewshelf => $shelfnumber, manageshelf => &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ), itemsloop => $items, ); - } + } else { push @paramsloop, {nopermission=>$shelfnumber}; } last SWITCH; } if ( $query->param('shelves') ) { @@ -144,16 +153,14 @@ SWITCH: { if ( $shelfnumber == -1 ) { #shelf already exists. $showadd = 1; - $template->param( - shelfnumber => $shelfnumber, - already => 1 - ); + push @paramsloop, { already => $newshelf }; + $template->param(shelfnumber => $shelfnumber); } else { print $query->redirect($pages{$type}->{redirect} . "?viewshelf=$shelfnumber"); exit; } } - my @paramsloop; + my $stay = 1; foreach ( $query->param() ) { /DEL-(\d+)/ or next; my $number = $1; @@ -163,6 +170,7 @@ SWITCH: { if (DelShelf($number)) { delete $shelflist->{$number}; $line{delete_ok} = $name; + $stay = 0; } else { $line{delete_fail} = $name; } @@ -170,19 +178,18 @@ SWITCH: { $line{unrecognized} = $number; } push(@paramsloop, \%line); - # print $query->redirect("/cgi-bin/koha/virtualshelves/shelves.pl"); exit; + # print $query->redirect($pages{$type}->{redirect}); + # exit; } $showadd = 1; - $template->param( - paramsloop => \@paramsloop, - shelves => 1, - ); + $stay and $template->param(shelves => 1); last SWITCH; } } +(@paramsloop) and $template->param(paramsloop => \@paramsloop); # rebuild shelflist in case a shelf has been added -$shelflist = GetShelves( $loggedinuser, 2 ); +# $shelflist = GetShelves( $loggedinuser, 2 ); $showadd and $template->param(showadd => 1); my $i = 0; my @shelvesloop; @@ -259,22 +266,21 @@ __END__ =item C - Op can be equals to: - * modifsave to save change on the shelves - * modif to change the template to allow to modify the shelves. + Op can be: + * modif: show the template allowing modification of the shelves; + * modifsave: save changes from modif mode. =item C - To load the template with 'viewshelves param' which allow to read the shelves information. + Load template with 'viewshelves param' displaying the shelf's information. =item C - If equals to 1. then call the function shelves which add - or delete a shelf. + If the param shelves == 1, then add or delete a shelf. =item C - If the param shelves = 1 then addshelf must be equals to the name of the shelf to add. + If the param shelves == 1, then addshelf is the name of the shelf to add. =back diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc index ac326ab559..58621890c6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc @@ -27,7 +27,10 @@ + +
  • ">Edit List
  • +
  • =1">Delete List
  • + + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl index d24f9969c3..cbbdf8f73a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl @@ -6,10 +6,12 @@ ///../img/checkall.gif\" height=\"18\" width=\"18\" alt=\"Check All\" title=\"Check All\" border=\"0\" />"); $("#CheckAll").click(function(){ $(".checkboxed").checkCheckboxes(); $("#CheckAll img").attr("src","/../img/checknone.gif").attr("title","Check None").attr("alt","Check None"); + // FIXME: a checknone.gif image should be made! $("#CheckAll").attr("id","CheckNone"); return false; }); @@ -21,12 +23,13 @@ $(document).ready(function(){ }); }); -function confirmDelete(s,n){ - if (window.confirm(s)) { - location.href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1&DEL-=1"; } else { - return false; - } - } + function confirmDelete(message,n){ + if (window.confirm(message)) { + location.href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1&DEL-=1"; + } else { + return false; + } + } /** * this function checks all checkbox * or uncheck all if there are already checked. @@ -35,10 +38,9 @@ function confirmDelete(s,n){ var checkboxes = document.getElementsByTagName('input'); var nbCheckbox = checkboxes.length; var check = areAllChecked(); - check = !check; for(var i=0;i
    + + + +
    +
    +
    A List named already exists!
    +
    +
    ERROR: No barcode given.
    +
    ERROR: No shelfnumber given.
    + +
    ERROR: You do not have adequate permission for that action on list .
    + + +
    ERROR: No item found with barcode .
    + + +
    A record matching barcode has already been added.
    + +
    +
    + + +
    @@ -141,8 +166,9 @@ function confirmDelete(s,n){
    -
    + +
    Add an item to @@ -157,8 +183,8 @@ function confirmDelete(s,n){
    +
    -
    Edit is on ()
    @@ -168,15 +194,6 @@ function confirmDelete(s,n){
    -
    A List with that name already exists!
    - -
    - - - -
    - -
    @@ -240,7 +257,7 @@ function confirmDelete(s,n){

    Lists

    - + class="highlight">
    NameCategoryItems 
    "> diff --git a/koha-tmpl/opac-tmpl/prog/en/js/script.js b/koha-tmpl/opac-tmpl/prog/en/js/script.js index 60fd21bd37..140aa34450 100644 --- a/koha-tmpl/opac-tmpl/prog/en/js/script.js +++ b/koha-tmpl/opac-tmpl/prog/en/js/script.js @@ -1,4 +1,4 @@ -/** + /** * this function checks all checkbox * or uncheck all if there are already checked. */ @@ -6,10 +6,9 @@ var checkboxes = document.getElementsByTagName('input'); var nbCheckbox = checkboxes.length; var check = areAllChecked(); - check = !check; for(var i=0;i