From afdf1c6de760255640d28675051a56eb425cbc6d Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Wed, 16 Jan 2008 12:32:22 -0600 Subject: [PATCH] Shelves wrap up - bugfix 1405, opac checkbox js fixed Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/VirtualShelves.pm | 32 +++---- C4/VirtualShelves/Page.pm | 93 +++++++++++-------- .../en/modules/virtualshelves/shelves.tmpl | 48 ++++++++-- koha-tmpl/opac-tmpl/prog/en/js/basket.js | 19 ++-- .../prog/en/modules/opac-shelves.tmpl | 81 +++++++++++----- 5 files changed, 181 insertions(+), 92 deletions(-) diff --git a/C4/VirtualShelves.pm b/C4/VirtualShelves.pm index b476eb440a..1af3603d9c 100644 --- a/C4/VirtualShelves.pm +++ b/C4/VirtualShelves.pm @@ -258,7 +258,7 @@ sub AddToShelf { $sth->execute( $shelfnumber, $biblionumber ); ($sth->rows) and return undef; # already on shelf - my $query = qq( + $query = qq( INSERT INTO virtualshelfcontents (shelfnumber, biblionumber, flags) VALUES @@ -318,20 +318,6 @@ sub ModShelf { $sth->execute( $shelfname, $owner, $category, $sortfield, $shelfnumber ); } -=item DelShelf - - ($status) = &DelShelf($shelfnumber); - -Deletes virtual virtualshelves number C<$shelfnumber>. The virtualshelves must -be empty. - -Returns a two-element array, where C<$status> is 0 if the operation -was successful, or non-zero otherwise. C<$msg> is "Done" in case of -success, or an error message giving the reason for failure. - -=cut - - =item ShelfPossibleAction ShelfPossibleAction($loggedinuser, $shelfnumber, $action); @@ -382,15 +368,25 @@ sub DelFromShelf { $sth->execute( $shelfnumber, $biblionumber ); } -=head2 DelShelf +=item DelShelf (old version) + + ($status, $msg) = &DelShelf($shelfnumber); + +Deletes virtual virtualshelves number C<$shelfnumber>. The virtualshelves must +be empty. + +Returns a two-element array, where C<$status> is 0 if the operation +was successful, or non-zero otherwise. C<$msg> is "Done" in case of +success, or an error message giving the reason for failure. + +=item DelShelf (current version) $Number = DelShelf($shelfnumber); - this function delete the shelf number, and all of it's content +This function deletes the shelf number, and all of it's content. =cut -#' sub DelShelf { unless (@_) { carp "DelShelf called without valid argument (shelfnumber)"; diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 49f09c0fd4..72db7f4c10 100755 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -33,7 +33,7 @@ use Exporter; use vars qw($debug @EXPORT @ISA $VERSION); BEGIN { - $VERSION = 1.00; + $VERSION = 1.01; @ISA = qw(Exporter); @EXPORT = qw(&shelfpage); $debug = $ENV{DEBUG} || 0; @@ -101,28 +101,39 @@ if (defined $shelf_type) { $template->param(showprivateshelves => 1); } +my($okmanage, $okview); +my $shelfnumber = $query->param('shelfnumber') || $query->param('viewshelf'); +if ($shelfnumber) { + $okmanage = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'manage' ); + $okview = &ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ); +} SWITCH: { if ( $op ) { + unless ($okmanage) { + push @paramsloop, {nopermission=>$shelfnumber}; + last SWITCH; + } if ( $op eq 'modifsave' ) { ModShelf( - $query->param('shelfnumber'), $query->param('shelfname'), - $loggedinuser, $query->param('category'), $query->param('sortfield') + $shelfnumber, $query->param('shelfname'), $loggedinuser, + $query->param('category'), $query->param('sortfield') ); $shelflist = GetShelves( $loggedinuser, 2 ); # refresh after mods } elsif ( $op eq 'modif' ) { - my ( $shelfnumber, $shelfname, $owner, $category, $sortfield ) =GetShelf( $query->param('shelf') ); + my ( $shelfnumber2, $shelfname, $owner, $category, $sortfield ) =GetShelf( $query->param('shelf') ); $template->param( edit => 1, - shelfnumber => $shelfnumber, + shelfnumber => $shelfnumber2, shelfname => $shelfname, + owner => $owner, "category$category" => 1, "sort_$sortfield" => 1, ); } last SWITCH; } - if (my $shelfnumber = $query->param('viewshelf') ) { + if ($shelfnumber = $query->param('viewshelf') ) { #check that the user can view the shelf if ( ShelfPossibleAction( $loggedinuser, $shelfnumber, 'view' ) ) { my $items = GetShelfContents($shelfnumber); @@ -144,13 +155,15 @@ SWITCH: { last SWITCH; } if ( $query->param('shelves') ) { - if ( my $newshelf = $query->param('addshelf') ) { + my $stay = 0; + if (my $newshelf = $query->param('addshelf')) { + # note: a user can always add a new shelf my $shelfnumber = AddShelf( $newshelf, $query->param('owner'), $query->param('category') ); - + $stay = 1; if ( $shelfnumber == -1 ) { #shelf already exists. $showadd = 1; push @paramsloop, { already => $newshelf }; @@ -160,26 +173,30 @@ SWITCH: { exit; } } - my $stay = 1; - foreach ( $query->param() ) { - /DEL-(\d+)/ or next; + foreach ($query->param()) { + /DEL-(\d+)/ or next; my $number = $1; - my %line; - if (defined $shelflist->{$number}) { - my $name = $shelflist->{$number}->{'shelfname'}; - if (DelShelf($number)) { - delete $shelflist->{$number}; - $line{delete_ok} = $name; - $stay = 0; - } else { - $line{delete_fail} = $name; - } - } else { - $line{unrecognized} = $number; + unless (defined $shelflist->{$number}) { + push(@paramsloop, {unrecognized=>$number}); last; } - push(@paramsloop, \%line); - # print $query->redirect($pages{$type}->{redirect}); - # exit; + unless (ShelfPossibleAction($loggedinuser, $number, 'manage')) { + push(@paramsloop, {nopermission=>$shelfnumber}); last; + } + my $contents = GetShelfContents($number); + if (my $count = scalar @$contents){ + unless (scalar grep {/^CONFIRM-$number$/} $query->param()) { + push(@paramsloop, {need_confirm=>$shelflist->{$number}->{shelfname}, count=>$count}); + $shelflist->{$number}->{confirm} = $number; + next; + } + } + my $name = $shelflist->{$number}->{'shelfname'}; + unless (DelShelf($number)) { + push(@paramsloop, {delete_fail=>$name}); last; + } + delete $shelflist->{$number}; + push(@paramsloop, {delete_ok=>$name}); + # print $query->redirect($pages{$type}->{redirect}); exit; } $showadd = 1; $stay and $template->param(shelves => 1); @@ -198,24 +215,20 @@ my $numberCanManage = 0; foreach my $element (sort { lc($shelflist->{$a}->{'shelfname'}) cmp lc($shelflist->{$b}->{'shelfname'}) } keys %$shelflist) { my %line; - (++$i % 2) and $line{'toggle'} = $i; - $line{'shelf'} = $element; - $line{'shelfname'} = $shelflist->{$element}->{'shelfname'}; - $line{'shelfvirtualcount'} = $shelflist->{$element}->{'count'}; - $line{'sortfield'} = $shelflist->{$element}->{'sortfield'}; - $line{"viewcategory$shelflist->{$element}->{'category'}"} = 1; - $line{'canmanage'} = ShelfPossibleAction( $loggedinuser, $element, 'manage' ); + (++$i % 2) and $shelflist->{$element}->{toggle} = 1; # $line{'toggle'} = $i; + $shelflist->{$element}->{shelf} = $element; + my $category = $shelflist->{$element}->{'category'}; + my $canmanage = ShelfPossibleAction( $loggedinuser, $element, 'manage' ); + $shelflist->{$element}->{"viewcategory$category"} = 1; + $shelflist->{$element}->{canmanage} = $canmanage; if ($shelflist->{$element}->{'owner'} eq $loggedinuser) { - $line{'mine'} = 1; - } else { - $line{'firstname'} = $shelflist->{$element}->{'firstname'}; - $line{'surname'} = $shelflist->{$element}->{'surname'} ; + $shelflist->{$element}->{'mine'} = 1; } - $numberCanManage++ if $line{'canmanage'}; + $numberCanManage++ if $canmanage; if ($shelflist->{$element}->{'category'} eq '1') { - push (@shelveslooppriv, \%line); + push (@shelveslooppriv, $shelflist->{$element}); } else { - push (@shelvesloop, \%line); + push (@shelvesloop, $shelflist->{$element}); } } 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 cbbdf8f73a..0214eb0634 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl @@ -61,12 +61,19 @@ $(document).ready(function(){ } //]]> + - +
@@ -82,6 +89,12 @@ $(document).ready(function(){
ERROR: No barcode given.
ERROR: No shelfnumber given.
+ +
The list is not empty. +
It has entries. +
Use the "Confirm" button below to confirm deletion. +
+
ERROR: You do not have adequate permission for that action on list .
@@ -116,13 +129,18 @@ $(document).ready(function(){   - + + + " /> + " checked /> + " /> + @@ -253,20 +271,38 @@ $(document).ready(function(){ - +

Lists

- class="highlight"> + class="highlight"> - - + + +
NameCategoryItems 
"> Private Public Open ">Edit =1" onclick="return confirmDelete(_('Are you sure you want to remove this List?'))">Delete 
+
+ " /> + + +
+
+ + " value="1" /> + + " value="1" /> + + + + +
+   +
diff --git a/koha-tmpl/opac-tmpl/prog/en/js/basket.js b/koha-tmpl/opac-tmpl/prog/en/js/basket.js index d761598fa2..9aa460e633 100644 --- a/koha-tmpl/opac-tmpl/prog/en/js/basket.js +++ b/koha-tmpl/opac-tmpl/prog/en/js/basket.js @@ -132,14 +132,21 @@ function addRecord(val, selection,NoMsgAlert) { } } +function AllAreChecked(s){ + if (! s.length) { return false;} + var l = s.length; + for (var i=0; i < l; i++) { + if(! s[i].checked) { return false; } + } + return true; +} + function SelectAll(){ if(document.bookbag_form.biblionumber.length > 0) { - for (var i=0; i < document.bookbag_form.biblionumber.length; i++) { - if (document.bookbag_form.select_all.checked) { - document.bookbag_form.biblionumber[i].checked=true; - } else { - document.bookbag_form.biblionumber[i].checked=false; - } + var checky = AllAreChecked(document.bookbag_form.biblionumber); + var l = document.bookbag_form.biblionumber.length; + for (var i=0; i < l; i++) { + document.bookbag_form.biblionumber[i].checked = (checky) ? false : true; } } } diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl index 332b5d5b84..a84b114f12 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-shelves.tmpl @@ -7,8 +7,45 @@
-
+ + +
+
+
A List named already exists!
+
+
ERROR: No barcode given.
+
ERROR: No shelfnumber given.
+ +
The list is not empty. +
It has entries. +
Use the "Confirm" button below to confirm deletion. +
+ + +
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.
+ + +

Shelf Deleted.

+ + +

ERROR: Database error. Delete (shelf number ) failed.

+ + +

ERROR: Shelf number unrecognized.

+ +
+
+ + + +

Lists /../images/caret.gif" width="16" height="16" alt=">" border="0" />

@@ -74,24 +111,6 @@ - - - -

Shelf Deleted.

- - -

ERROR: Database error. Delete (shelf number ) failed.

- - -

ERROR: Shelf number unrecognized.

- - - - - -

Error: A shelf named already exists. Please pick a different name.

- -
@@ -139,10 +158,28 @@ "> - item(s) + item(s) - ">Edit =1">Delete  + + + " /> + + +
+
+ + " value="1" /> + + " value="1" /> + + + + +
+   + + No Private Lists. @@ -164,7 +201,7 @@ "> - item(s) + item(s) -- 2.39.5