Shelves wrap up - bugfix 1405, opac checkbox js fixed

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Joe Atzberger 2008-01-16 12:32:22 -06:00 committed by Joshua Ferraro
parent e45912470f
commit afdf1c6de7
5 changed files with 181 additions and 92 deletions

View file

@ -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)";

View file

@ -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});
}
}

View file

@ -61,12 +61,19 @@ $(document).ready(function(){
}
//]]>
</script>
<style type="text/css">
input.confirm {
background:lightblue url(../../img/button-bg.gif) repeat-x scroll left top;
border-width:2pt;
}
</style>
</head>
<body>
<!-- TMPL_INCLUDE NAME="header.inc" -->
<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <!-- TMPL_IF NAME="viewshelf" --><a href="/cgi-bin/koha/virtualshelves/shelves.pl">Lists</a> &rsaquo; Contents of <i><!-- TMPL_VAR NAME="shelfname" --></i><!-- TMPL_ELSE --><a href="/cgi-bin/koha/virtualshelves/shelves.pl">Lists</a><!-- /TMPL_IF --><!-- TMPL_IF NAME="shelves" --> &rsaquo; Create New List<!-- /TMPL_IF --><!-- TMPL_IF NAME="edit" --> &rsaquo; Edit List<i> <!-- TMPL_VAR name="shelfname"--></i><!-- /TMPL_IF --></div>
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/virtualshelves/shelves.pl">Lists</a>
<!-- TMPL_IF NAME="viewshelf" -->&rsaquo; Contents of <i><!-- TMPL_VAR NAME="shelfname" --></i><!-- /TMPL_IF --><!-- TMPL_IF NAME="shelves" --> &rsaquo; Create New List<!-- /TMPL_IF --><!-- TMPL_IF NAME="edit" --> &rsaquo; Edit List <i><!-- TMPL_VAR name="shelfname"--></i><!-- /TMPL_IF --></div>
<div id="doc" class="yui-t7">
<div id="bd">
@ -82,6 +89,12 @@ $(document).ready(function(){
<!-- TMPL_IF NAME="status" --><div class="dialog alert"><!-- TMPL_VAR NAME="string" --></div><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="nobarcode" --><div class="dialog alert">ERROR: No barcode given.</div><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="noshelfnumber" --><div class="dialog alert">ERROR: No shelfnumber given.</div><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="need_confirm" -->
<div class="dialog alert">The list <i><!-- TMPL_VAR NAME="need_confirm" --></i> is not empty.
<br />It has <b><!-- TMPL_VAR NAME="count" --></b> entries.
<br />Use the "Confirm" button below to confirm deletion.
</div>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="nopermission" -->
<div class="dialog alert">ERROR: You do not have adequate permission for that action on list <!-- TMPL_VAR NAME="nopermission" -->.</div>
<!-- /TMPL_IF -->
@ -116,13 +129,18 @@ $(document).ready(function(){
<th>&nbsp;</th>
</tr>
<!-- TMPL_LOOP NAME="itemsloop" -->
<!-- TMPL_IF NAME="color" -->
<!-- TMPL_IF NAME="toggle" -->
<tr class="highlight">
<!-- TMPL_ELSE -->
<tr>
<!-- /TMPL_IF -->
<td>
<!-- TMPL_IF NAME="confirm" -->
<input type="hidden" name="CONFIRM-<!-- TMPL_VAR NAME="confirm" -->" />
<input type="checkbox" name="REM-<!-- TMPL_VAR NAME="biblionumber" -->" checked />
<!-- TMPL_ELSE -->
<input type="checkbox" name="REM-<!-- TMPL_VAR NAME="biblionumber" -->" />
<!-- /TMPL_IF -->
</td>
<td>
<!-- TMPL_VAR NAME="itemtype" -->
@ -253,20 +271,38 @@ $(document).ready(function(){
<!-- /TMPL_IF --><!-- /seflag -->
<!-- TMPL_UNLESS NAME="vseflag" -->
<!-- TMPL_IF NAME="shelvesloop" -->
<!-- TMPL_IF NAME="shelvesloopall" -->
<h3>Lists</h3>
<table>
<tr><th>Name</th><th>Category</th><th>Items</th><th>&nbsp;</th></tr>
<!-- TMPL_LOOP NAME="shelvesloopall" -->
<tr<!-- TMPL_IF name="color" --> class="highlight"<!-- /TMPL_IF -->>
<tr<!-- TMPL_IF NAME="toggle" --> class="highlight"<!-- /TMPL_IF -->>
<td><a href="/cgi-bin/koha/virtualshelves/shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelf" -->"><!-- TMPL_VAR NAME="shelfname" --></a></td>
<td>
<!-- TMPL_IF NAME="viewcategory1" -->Private<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="viewcategory2" -->Public<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="viewcategory3" -->Open<!-- /TMPL_IF -->
</td>
<td><!-- TMPL_VAR NAME="shelfvirtualcount" --> </td>
<td><!-- TMPL_IF name="mine" --><a href="/cgi-bin/koha/virtualshelves/shelves.pl?op=modif&amp;shelf=<!-- TMPL_VAR NAME="shelf" -->">Edit</a> <a href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1&amp;DEL-<!-- TMPL_VAR NAME="shelf" -->=1" onclick="return confirmDelete(_('Are you sure you want to remove this List?'))">Delete</a><!-- TMPL_ELSE -->&nbsp;<!-- /TMPL_IF --></td></tr>
<td><!-- TMPL_VAR NAME="count" --></td>
<td><!-- TMPL_IF NAME="mine" -->
<form action="/cgi-bin/koha/virtualshelves/shelves.pl" method="get">
<input type="hidden" name="shelf" value="<!-- TMPL_VAR NAME="shelf" -->" />
<input type="hidden" name="op" value="modif" />
<input type="submit" value="Edit" />
</form>
<form action="/cgi-bin/koha/virtualshelves/shelves.pl" method="post">
<input type="hidden" name="shelves" value="1" />
<input type="hidden" name="DEL-<!-- TMPL_VAR NAME="shelf" -->" value="1" />
<!-- TMPL_IF NAME="confirm" -->
<input type="hidden" name="CONFIRM-<!-- TMPL_VAR NAME="confirm" -->" value="1" />
<input type="submit" class="confirm" value="Confirm" />
<!-- TMPL_ELSE -->
<input type="submit" onclick="return confirmDelete(_('Are you sure you want to remove this List?'));" value="Delete" />
<!-- /TMPL_IF -->
</form>
<!-- /TMPL_IF -->&nbsp;
</td>
</tr>
<!-- /TMPL_LOOP -->
</table>
<!-- /TMPL_IF -->

View file

@ -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;
}
}
}

View file

@ -7,8 +7,45 @@
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<div class="yui-g">
<!-- TMPL_IF NAME="paramsloop" -->
<!-- TMPL_LOOP NAME="paramsloop" -->
<div class="yui-ge">
<div class="yui-u first">
<!-- TMPL_IF NAME="already" --><div class="dialog alert">A List named <b><!-- TMPL_VAR NAME="already" --></b> already exists!</div><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="status" --><div class="dialog alert"><!-- TMPL_VAR NAME="string" --></div><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="nobarcode" --><div class="dialog alert">ERROR: No barcode given.</div><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="noshelfnumber" --><div class="dialog alert">ERROR: No shelfnumber given.</div><!-- /TMPL_IF -->
<!-- TMPL_IF NAME="need_confirm" -->
<div class="dialog alert">The list <i><!-- TMPL_VAR NAME="need_confirm" --></i> is not empty.
<br />It has <b><!-- TMPL_VAR NAME="count" --></b> entries.
<br />Use the "Confirm" button below to confirm deletion.
</div>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="nopermission" -->
<div class="dialog alert">ERROR: You do not have adequate permission for that action on list <!-- TMPL_VAR NAME="nopermission" -->.</div>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="failgetitem" -->
<div class="dialog alert">ERROR: No item found with barcode <!-- TMPL_VAR NAME="failgetitem" -->.</div>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="duplicatebiblio" -->
<div class="dialog alert">A record matching barcode <b><!-- TMPL_VAR NAME="duplicatebiblio" --></b> has already been added.</div>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="delete_ok" -->
<p class="message">Shelf <!-- TMPL_VAR NAME="delete_ok" --> Deleted.</p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="delete_fail" -->
<p class="error">ERROR: Database error. Delete (shelf number <!-- TMPL_VAR NAME="delete_fail" -->) failed.</p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="unrecognized" -->
<p class="error">ERROR: Shelf number <!-- TMPL_VAR NAME="unrecognized" --> unrecognized.</p>
<!-- /TMPL_IF -->
</div>
</div>
<!-- /TMPL_LOOP -->
<!-- /TMPL_IF -->
<div class="yui-g">
<!-- TMPL_IF NAME="viewshelf" -->
<h3><a href="/cgi-bin/koha/opac-shelves.pl">Lists</a> <img src="<!-- TMPL_VAR NAME="themelang" -->/../images/caret.gif" width="16" height="16" alt="&gt;" border="0" /> <em><!-- TMPL_VAR NAME="shelfname" --></em></h3>
<!-- TMPL_IF NAME="itemsloop" -->
@ -74,24 +111,6 @@
</form>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="shelves" -->
<!-- TMPL_LOOP NAME="paramsloop" -->
<!-- TMPL_IF NAME="delete_ok" -->
<p class="message">Shelf <!-- TMPL_VAR NAME="delete_ok" --> Deleted.</p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="delete_fail" -->
<p class="error">ERROR: Database error. Delete (shelf number <!-- TMPL_VAR NAME="delete_fail" -->) failed.</p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="unrecognized" -->
<p class="error">ERROR: Shelf number <!-- TMPL_VAR NAME="unrecognized" --> unrecognized.</p>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
<!-- /TMPL_IF --><!-- /shelves -->
<!-- TMPL_IF NAME="already" -->
<p class="error">Error: A shelf named <!-- TMPL_VAR NAME="already" --> already exists. Please pick a different name.</p>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="edit" -->
<form method="post" action="/cgi-bin/koha/opac-shelves.pl">
<input type="hidden" name="op" value="modifsave">
@ -139,10 +158,28 @@
<!-- TMPL_LOOP NAME="shelveslooppriv" -->
<!-- TMPL_IF NAME="toggle" --><tr class="highlight"><!--TMPL_ELSE--><tr><!-- /TMPL_IF -->
<td><a href="opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelf" -->"><!-- TMPL_VAR NAME="shelfname" --></a></td>
<td><!-- TMPL_VAR NAME="shelfvirtualcount" --> item(s)</td>
<td><!-- TMPL_VAR NAME="count" --> item(s)</td>
<td><!-- TMPL_VAR NAME="sortfield" --></td>
<td>
<!-- TMPL_IF NAME="mine" --><a href="opac-shelves.pl?op=modif&amp;shelf=<!-- TMPL_VAR NAME="shelf" -->">Edit</a> <a class="delete" href="opac-shelves.pl?shelves=1&amp;DEL-<!-- TMPL_VAR NAME="shelf" -->=1">Delete</a><!-- TMPL_ELSE -->&nbsp;<!-- /TMPL_IF --></td></tr>
<!-- TMPL_IF NAME="mine" -->
<form action="opac-shelves.pl" method="get">
<input type="hidden" name="shelf" value="<!-- TMPL_VAR NAME="shelf" -->" />
<input type="hidden" name="op" value="modif" />
<input type="submit" value="Edit" />
</form>
<form action="opac-shelves.pl" method="post">
<input type="hidden" name="shelves" value="1" />
<input type="hidden" name="DEL-<!-- TMPL_VAR NAME="shelf" -->" value="1" />
<!-- TMPL_IF NAME="confirm" -->
<input type="hidden" name="CONFIRM-<!-- TMPL_VAR NAME="confirm" -->" value="1" />
<input type="submit" class="confirm" value="Confirm" />
<!-- TMPL_ELSE -->
<input type="submit" onclick="return confirmDelete(_('Are you sure you want to remove this List?'));" value="Delete" />
<!-- /TMPL_IF -->
</form>
<!-- /TMPL_IF -->&nbsp;
</td>
</tr>
<!-- /TMPL_LOOP -->
<!-- TMPL_ELSE -->
<tr><td colspan="4">No Private Lists.</td></tr>
@ -164,7 +201,7 @@
<!-- TMPL_LOOP NAME="shelvesloop" -->
<!-- TMPL_IF NAME="toggle" --><tr class="highlight"><!--TMPL_ELSE--><tr><!-- /TMPL_IF -->
<td><a href="opac-shelves.pl?viewshelf=<!-- TMPL_VAR NAME="shelf" -->"><!-- TMPL_VAR NAME="shelfname" --></a></td>
<td><!-- TMPL_VAR NAME="shelfvirtualcount" --> item(s)</td></tr>
<td><!-- TMPL_VAR NAME="count" --> item(s)</td></tr>
<!-- /TMPL_LOOP -->
</table>
<!-- TMPL_ELSE -->