Fix / improve bookbag list paging
authorDan Scott <dan@coffeecode.net>
Sun, 22 Jul 2012 22:58:11 +0000 (18:58 -0400)
committerBen Shum <bshum@biblio.org>
Mon, 23 Jul 2012 00:18:36 +0000 (20:18 -0400)
The prior code used CSS to hide elements, which is a bit weird given
that we can simply avoid creating the element in the first place and
keep the DOM a lot simpler.

Also, the previous code was subject to some bugs if it wasn't given
an explicit offset GET param or paging at the end of a list
(particularly given that the LIMIT parameter ensured that the number of
bookbags returned would always be equal to or less than the LIMIT
parameter).

Finally, the changes related the permanent bookbags didn't pass through
one of the context parameters we needed (bookbag_count) to enable
paging.

Signed-off-by: Dan Scott <dan@coffeecode.net>
Signed-off-by: Ben Shum <bshum@biblio.org>

Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/myopac/lists.tt2

index 07db754..10dd567 100644 (file)
@@ -1702,6 +1702,15 @@ sub load_myopac_bookbags {
     # We load the user prefs to get their default bookbag.
     $self->_load_user_with_prefs;
 
+    # We also want a total count of the user's bookbags.
+    my $q = {
+        'select' => { 'cbreb' => [ { 'column' => 'id', 'transform' => 'count', 'aggregate' => 'true', 'alias' => 'count' } ] },
+        'from' => 'cbreb',
+        'where' => { 'btype' => 'bookbag', 'owner' => $self->ctx->{user}->id }
+    };
+    my $r = $e->json_query($q);
+    $ctx->{bookbag_count} = $r->[0]->{'count'};
+
     # If the user wants a specific bookbag's items, load them.
     # XXX add bookbag item paging support
 
index e633688..651f990 100644 (file)
     [% IF ctx.bookbags.size %]
     <div class="header_middle">
         <span class="float-left">[% l('Saved Lists') %]</span>
-        [% IF limit < ctx.bookbag_count %]
+        [% IF limit < ctx.bookbag_count; %]
         <span class='float-left' style='padding-left: 10px;'>
-            <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {limit => limit, offset => (offset - limit)}) %]'
-                [% IF offset == 0 %] class='invisible' [% END %]><span class="nav_arrow_fix">&#9668;</span>[% l('Previous') %]</a>
-            <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {limit => limit, offset => (offset + limit)}) %]'
-               [% IF ctx.bookbags.size < limit %] class='invisible' [% END %] >[% l('Next') %]<span class="nav_arrow_fix">&#9658;</span></a>
-        </span>
+            [%- IF offset > 0 -%]
+                <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                    limit => limit, offset => (offset - limit)
+                }) %]'><span class="nav_arrow_fix">&#9668;</span>[% l('Previous') %]</a>
+            [%- END; -%]
+            [%- IF (ctx.bookbag_count - offset) > limit; -%] 
+                <a href='[% mkurl(ctx.opac_root _ '/myopac/lists', {
+                    limit => limit, offset => (offset + limit)
+                }) %]'>[% l('Next') %]<span class="nav_arrow_fix">&#9658;</span></a>
+            </span>
+            [%- END; -%]
         [% END %]
     </div>
     <div class="clear-both"></div>