Shelves - bugfix 1403 amongst others
authorJoe Atzberger <joe.atzberger@liblime.com>
Tue, 15 Jan 2008 17:39:17 +0000 (11:39 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 15 Jan 2008 21:33:08 +0000 (15:33 -0600)
Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/VirtualShelves.pm
C4/VirtualShelves/Page.pm
koha-tmpl/intranet-tmpl/prog/en/includes/virtualshelves-toolbar.inc
koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tmpl
koha-tmpl/opac-tmpl/prog/en/js/script.js

index 1970ec0..b476eb4 100644 (file)
@@ -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
index 108397d..49f09c0 100755 (executable)
@@ -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>
 
-    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<viewshelf>
 
-    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<shelves>
 
-    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<addshelf>
 
-    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
 
index ac326ab..5862189 100644 (file)
        </script>
        
 <ul class="toolbar">
-
        <li><a id="newshelf" href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1">New List</a></li>
-       <!-- TMPL_IF NAME="viewshelf" --><!-- TMPL_IF name="manageshelf" --><li><a id="editshelf" href="/cgi-bin/koha/virtualshelves/shelves.pl?op=modif&amp;shelf=<!-- TMPL_VAR NAME="shelfnumber" -->">Edit List</a></li><li id="deleteshelfc"><a id="deleteshelf" href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1&amp;DEL-<!-- TMPL_VAR NAME="shelfnumber" -->=1">Delete List</a></li><!-- /TMPL_IF --><!-- /TMPL_IF -->
-</ul></div>
+       <!-- TMPL_IF NAME="viewshelf" --><!-- TMPL_IF name="manageshelf" -->
+       <li><a id="editshelf" href="/cgi-bin/koha/virtualshelves/shelves.pl?op=modif&amp;shelf=<!-- TMPL_VAR NAME="shelfnumber" -->">Edit List</a></li>
+       <li id="deleteshelfc"><a id="deleteshelf" href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1&amp;DEL-<!-- TMPL_VAR NAME="shelfnumber" -->=1">Delete List</a></li>
+       <!-- /TMPL_IF --><!-- /TMPL_IF -->
+</ul>
+</div>
index d24f996..cbbdf8f 100644 (file)
@@ -6,10 +6,12 @@
 //<![CDATA[ 
 
 $(document).ready(function(){
+       $("#addbarcode").focus();
     $("th.checkall").html("<a href=\"/cgi-bin/koha/shelves.pl\" id=\"CheckAll\"><img src=\"<!-- TMPL_VAR NAME="themelang" -->/../img/checkall.gif\" height=\"18\" width=\"18\" alt=\"Check All\" title=\"Check All\" border=\"0\" /></a>");
     $("#CheckAll").click(function(){
         $(".checkboxed").checkCheckboxes();
         $("#CheckAll img").attr("src","<!-- TMPL_VAR NAME="themelang" -->/../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&amp;DEL-<!-- TMPL_VAR NAME="shelfnumber" -->=1"; } else { 
-        return false;
-        }
-    }
+       function confirmDelete(message,n){
+               if (window.confirm(message)) {
+                       location.href="/cgi-bin/koha/virtualshelves/shelves.pl?shelves=1&amp;DEL-<!-- TMPL_VAR NAME="shelfnumber" -->=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<nbCheckbox;i++){
             if(checkboxes[i].getAttribute('type') == "checkbox" ){
-                checkboxes[i].checked = check;
+                checkboxes[i].checked = (check) ? 0 : 1;
             }
         }
     }
@@ -71,6 +73,29 @@ function confirmDelete(s,n){
   <div id="yui-main">
    <div class="yui-g"><!-- TMPL_INCLUDE NAME="virtualshelves-toolbar.inc" -->
    </div>
+
+<!-- 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 <!-- TMPL_VAR NAME="already" --> 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="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 --> 
+       </div>
+</div>
+<!-- /TMPL_LOOP -->
+<!-- /TMPL_IF --> 
+
 <!-- TMPL_IF NAME="viewshelf" -->
    <div class="yui-g">
     <!-- TMPL_IF NAME="itemsloop" -->
@@ -141,8 +166,9 @@ function confirmDelete(s,n){
        <!-- /TMPL_IF -->
    </div>
 <!-- /TMPL_IF --><!-- /viewshelf -->
-   <div class="yui-g">
+
 <!-- TMPL_IF name="manageshelf" -->
+<div class="yui-g">
 <form action="/cgi-bin/koha/virtualshelves/shelves.pl" method="post">
  <fieldset class="brief">
     <legend>Add an item to <i><!-- TMPL_VAR NAME="shelfname" --></i></legend>
@@ -157,8 +183,8 @@ function confirmDelete(s,n){
         </ol>
  </fieldset>
 </form>
+</div>
 <!-- /TMPL_IF --><!-- /manageshelf -->
-   </div>
 
 <!-- TMPL_IF name="debug" -->
   <!-- TMPL_IF name="edit" --><div>Edit is on (<!-- TMPL_VAR name="shelfname" -->)</div><!-- /TMPL_IF -->
@@ -168,15 +194,6 @@ function confirmDelete(s,n){
 <!-- TMPL_IF NAME="seflag" -->
 <div class="yui-ge">
     <div class="yui-u first">
-        <!-- TMPL_IF NAME="already" --><div class="dialog alert">A List with that name already exists!</div><!-- /TMPL_IF -->
-        <!-- TMPL_IF NAME="status1" -->
-            <div class="dialog alert"><!-- TMPL_VAR NAME="string1" --></div>
-        <!-- /TMPL_IF -->
-        <!-- TMPL_LOOP NAME="paramsloop" -->
-            <!-- TMPL_IF NAME="status" -->
-            <div class="dialog alert"><!-- TMPL_VAR NAME="string" --></div>
-            <!-- /TMPL_IF -->
-        <!-- /TMPL_LOOP -->
     <form method="post" action="/cgi-bin/koha/virtualshelves/shelves.pl">
         <fieldset class="rows">
 
@@ -240,7 +257,7 @@ function confirmDelete(s,n){
 <h3>Lists</h3>
 <table>
 <tr><th>Name</th><th>Category</th><th>Items</th><th>&nbsp;</th></tr>
-<!-- TMPL_LOOP NAME="shelvesloop" -->
+<!-- TMPL_LOOP NAME="shelvesloopall" -->
 <tr<!-- TMPL_IF name="color" --> 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>
index 60fd21b..140aa34 100644 (file)
@@ -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<nbCheckbox;i++){
                        if(checkboxes[i].getAttribute('type') == "checkbox" ){
-                               checkboxes[i].checked = check;
+                               checkboxes[i].checked = (check) ? 0 : 1;
                        }
                }
        }
        }
 
 function confirmDelete(message) {
-       var agree = confirm(message);
-       if(agree) {
-               return true;
-       } else {
-               return false;
-       }
+       return (confirm(message) ? true : false);
 }
 
 function Dopop(link) {
        newin=window.open(link,'popup','width=500,height=400,toolbar=false,scrollbars=yes');
-       }
\ No newline at end of file
+}
+