[open-ils-commits] [GIT] Evergreen ILS branch master updated. f30c649e795496000b49cde1b9b32900ee2606b6

Evergreen Git git at git.evergreen-ils.org
Fri May 25 08:57:05 EDT 2012


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  f30c649e795496000b49cde1b9b32900ee2606b6 (commit)
       via  a352eb833c9c7e1e11b68560525b2797e2d56085 (commit)
       via  551b0ab65ce8f34db142f72ccb7a4e0a42518dd1 (commit)
       via  918166be5e75e2ab3dd1d0764c2be2f3075edfb1 (commit)
       via  baad6d08cfdf0c6b4dad7985d37e74bfbfbd387b (commit)
       via  5a6956654d190aab736366bee72501eef06d09be (commit)
      from  b53d7120da33d7f027b535cf64feca7828178618 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f30c649e795496000b49cde1b9b32900ee2606b6
Author: Bill Erickson <berick at esilibrary.com>
Date:   Thu May 24 10:30:09 2012 -0400

    tpac : uri escape added content key
    
    The added content key may have spaces, etc.  URI escape the key to
    prevent Net::HTTP from croaking in the URL.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
index 0a3935b..c7e9b4d 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
@@ -440,7 +440,7 @@ sub added_content_stage1 {
             }
 
             my $http_type = ($type eq $sel_type) ? 'GET' : 'HEAD';
-            $req->write_request($http_type => "/opac/extras/ac/$type/html/$key");
+            $req->write_request($http_type => "/opac/extras/ac/$type/html/" . uri_escape($key));
             $ctx->{added_content}->{$type}->{request} = $req;
         }
     }

commit a352eb833c9c7e1e11b68560525b2797e2d56085
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri May 18 13:23:53 2012 -0400

    tpac added content default type improvements
    
    * In the pre-JS state, only choose a default display type when the type
    is known to have data.
    
    * If no default type is chosen for the main tab link, because no data
    was available to the template, set the default from the first added
    content type determined to be available via JS.
    
    * Move added content JS to separate template file for easier override.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/templates/opac/parts/acjs.tt2 b/Open-ILS/src/templates/opac/parts/acjs.tt2
new file mode 100644
index 0000000..fe15569
--- /dev/null
+++ b/Open-ILS/src/templates/opac/parts/acjs.tt2
@@ -0,0 +1,55 @@
+
+<script type="text/javascript">
+
+    /* Checks to see if a given type of added content has data to show.
+     * The first arg to callback() is boolean indicating the presence of data */
+    function acIsAvailable(ident, type, callback) {
+        var url = '/opac/extras/ac/' + type + '/html/' + ident;
+        dojo.xhr('HEAD', {
+            url : url, 
+            failOk : true, // http://bugs.dojotoolkit.org/ticket/11568
+            error : function(err) { callback(false, ident, type); },
+            load : function(result) { callback(true, ident, type); }
+        });
+    }
+
+    [%-  # XXX revisit when ident=ctx.bre_id
+        ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc; 
+        IF ident; 
+            FOR type IN ctx.added_content.keys;
+                IF ctx.added_content.$type.status == '3' # status unknown %]
+
+                    dojo.addOnLoad(function() {
+                        var ident = '[% ident %]';
+                        var type = '[% type %]';
+
+                        acIsAvailable(ident, type, function(avail, ident, type) { 
+                            if (avail) {
+
+                                [% IF CGI.param('expand') == 'addedcontent' %]
+
+                                    // if the content is available, un-hide the tab
+                                    dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
+
+                                [% ELSE %]
+                                    // if no default type is selected on the main tab link
+                                    // set one here, since we have available content
+
+                                    var link = dojo.query('[name=addedcontent]')[0];
+                                    var href = link.getAttribute('href');
+                                    if (!href.match('[\&;]ac=')) {
+                                        href = href.replace('#addedcontent', ';ac=' + type + '#addedcontent');
+                                        dojo.attr(link, 'href', href);
+                                        dojo.attr(dojo.query('[name=addedcontent_lbl]')[0], 'href', href);
+                                    }
+
+                                [% END %]
+                            }
+                        });
+                    });
+                [% END; # IF status unknown
+            END; 
+        END; # IF ident
+    %]
+</script>
+
diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2
index ff2cb29..7029554 100644
--- a/Open-ILS/src/templates/opac/parts/js.tt2
+++ b/Open-ILS/src/templates/opac/parts/js.tt2
@@ -77,40 +77,6 @@
 </script>
 [% END; # use_autosuggest %]
 
-
-[% IF ctx.page == 'record' %]
-<script type="text/javascript">
-
-    /* Checks to see if a given type of added content has data to show.
-     * The first arg to callback() is boolean indicating the presence of data.
-     */
-    function acIsAvailable(ident, type, callback) {
-        var url = '/opac/extras/ac/' + type + '/html/' + ident;
-        dojo.xhr('HEAD', {
-            url : url, 
-            failOk : true, // http://bugs.dojotoolkit.org/ticket/11568
-            error : function(err) { callback(false, ident, type); },
-            load : function(result) { callback(true, ident, type); }
-        });
-    }
-    [%-  # XXX revisit when ident=ctx.bre_id
-        ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc; 
-        IF ident; 
-            FOR type IN ctx.added_content.keys;
-                IF ctx.added_content.$type.status == '3' # status unknown %]
-                    dojo.addOnLoad(function() {
-                        var ident = '[% ident %]';
-                        var type = '[% type %]';
-                        acIsAvailable(ident, type, function(avail, ident, type) { 
-                            // if the content is available, un-hide the tab
-                            if (avail) dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
-                        });
-                    });
-                [% END; # IF status unknown
-            END; 
-        END; # IF ident
-    %]
-</script>
-[% END; # page=record -%]
+[% INCLUDE "opac/parts/acjs.tt2" IF ctx.page == 'record' %]
 
 [%- END; # want_dojo -%]
diff --git a/Open-ILS/src/templates/opac/parts/record/extras.tt2 b/Open-ILS/src/templates/opac/parts/record/extras.tt2
index 7b5c378..276c969 100644
--- a/Open-ILS/src/templates/opac/parts/record/extras.tt2
+++ b/Open-ILS/src/templates/opac/parts/record/extras.tt2
@@ -27,6 +27,8 @@
             FOR type IN ctx.added_content.keys;
                 IF ctx.added_content.$type.status != '2'; # not available
                     hide_ac = 0;
+                END;
+                IF ctx.added_content.$type.status == '1';
                     SET default_ac = type UNLESS default_ac;
                 END;
             END;
@@ -66,7 +68,7 @@
                     END;
                 %]
                 <a name='[% name %]' href='[% href %]'><img alt='[% extra.label %]' src='[% img_url %]'/></a>
-                <a href='[% href %]' class="rdetail_extras_lbl">[% extra.label %]</a>
+                <a name='[% name %]_lbl' href='[% href %]' class="rdetail_extras_lbl">[% extra.label %]</a>
             </div>
         </div>
         <div class='rdetail_extras_div'>

commit 551b0ab65ce8f34db142f72ccb7a4e0a42518dd1
Author: Bill Erickson <berick at esilibrary.com>
Date:   Tue May 15 10:11:37 2012 -0400

    TPAC added content data retrieval sanity check
    
    On the backend, avoid fetching added content data when initial request
    returns 404.  This prevents edge case where a specific type may be
    selected (e.g. via bookmark) even though no data exists for the type.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
index f7d09f6..0a3935b 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
@@ -472,7 +472,7 @@ sub added_content_stage2 {
                 $content->{status} = $code eq '200' ? 1 : 2;
                 $logger->debug("tpac: added content request for $type returned $code");
 
-                if ($type eq $sel_type) {
+                if ($code eq '200' and $type eq $sel_type) {
                     while (1) {
                         my $buf;
                         my $n = $req->read_entity_body($buf, 1024);

commit 918166be5e75e2ab3dd1d0764c2be2f3075edfb1
Author: Bill Erickson <berick at esilibrary.com>
Date:   Tue May 15 09:56:27 2012 -0400

    TPAC added content shows default tab
    
    Use the first available content as the default tab to show when the main
    added content tab is expanded.
    
    Note, if no content is known to exist until after JS has run, it's still
    possible to expand the main tab and have no content selected by default.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/templates/opac/parts/record/extras.tt2 b/Open-ILS/src/templates/opac/parts/record/extras.tt2
index d02efb0..7b5c378 100644
--- a/Open-ILS/src/templates/opac/parts/record/extras.tt2
+++ b/Open-ILS/src/templates/opac/parts/record/extras.tt2
@@ -19,12 +19,16 @@
             END;
         END;
 
-        # if no added content is available, hide the main tab
+        # if no added content is available, hide the main tab.
+        # if any content is available, use the first tab as the default display tab.
+        default_ac = '';
         IF !tab_is_active('addedcontent');
             hide_ac = 1;
             FOR type IN ctx.added_content.keys;
-                SET hide_ac = 0 IF 
-                    ctx.added_content.$type.status != '2'; # not available
+                IF ctx.added_content.$type.status != '2'; # not available
+                    hide_ac = 0;
+                    SET default_ac = type UNLESS default_ac;
+                END;
             END;
         END;
 
@@ -53,7 +57,11 @@
                         href = mkurl('', {}, ['expand', 'ac']);
                         img_url = ctx.media_prefix _ '/images/rdetail_arrow_down.png';
                     ELSE;
-                        href = mkurl('', {expand => name}) _ '#' _ name; 
+                        IF name == 'addedcontent' AND default_ac;
+                            href = mkurl('', {expand => name, ac => default_ac}) _ '#' _ name; 
+                        ELSE;
+                            href = mkurl('', {expand => name}) _ '#' _ name; 
+                        END;
                         img_url = ctx.media_prefix _ '/images/rdetail_arrow.png';
                     END;
                 %]

commit baad6d08cfdf0c6b4dad7985d37e74bfbfbd387b
Author: Bill Erickson <berick at esilibrary.com>
Date:   Tue May 15 09:46:11 2012 -0400

    TPAC added content improvements
    
    * Style the sub-tabs to indicate which is selected
    * If the template knows there is no content, hide the main tab
    * cleanup
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2
index b29a0bc..ff2cb29 100644
--- a/Open-ILS/src/templates/opac/parts/js.tt2
+++ b/Open-ILS/src/templates/opac/parts/js.tt2
@@ -77,8 +77,9 @@
 </script>
 [% END; # use_autosuggest %]
 
+
+[% IF ctx.page == 'record' %]
 <script type="text/javascript">
-    [% ac_types = ['toc',  'anotes', 'excerpt', 'summary', 'reviews'] %]
 
     /* Checks to see if a given type of added content has data to show.
      * The first arg to callback() is boolean indicating the presence of data.
@@ -92,27 +93,24 @@
             load : function(result) { callback(true, ident, type); }
         });
     }
-
-    [% 
-        IF ctx.page == 'record';
-            # XXX revisit when ident=ctx.bre_id
-            ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc; 
-            IF ident; 
-                FOR type IN ac_types;
-                    IF ctx.added_content.$type.status == '3' # status unknown %]
-                        dojo.addOnLoad(function() {
-                            var ident = '[% ident %]';
-                            var type = '[% type %]';
-                            acIsAvailable(ident, type, function(avail, ident, type) { 
-                                // if the content is available, un-hide the tab
-                                if (avail) dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
-                            });
+    [%-  # XXX revisit when ident=ctx.bre_id
+        ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc; 
+        IF ident; 
+            FOR type IN ctx.added_content.keys;
+                IF ctx.added_content.$type.status == '3' # status unknown %]
+                    dojo.addOnLoad(function() {
+                        var ident = '[% ident %]';
+                        var type = '[% type %]';
+                        acIsAvailable(ident, type, function(avail, ident, type) { 
+                            // if the content is available, un-hide the tab
+                            if (avail) dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
                         });
-                    [% END; # IF status unknown
-                END; 
-            END; # IF ident
-        END;
+                    });
+                [% END; # IF status unknown
+            END; 
+        END; # IF ident
     %]
 </script>
+[% END; # page=record -%]
 
 [%- END; # want_dojo -%]
diff --git a/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2 b/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2
index 21e81ef..477d278 100644
--- a/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2
+++ b/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2
@@ -18,9 +18,13 @@
 %]
 
     <div id='ac_tab_wrapper'>
-        [% FOR type IN ac_types.keys;
+    [% 
+        all_hidden = 1;
+        FOR type IN ac_types.keys;
             tab_class = 'ac_tab';
+            SET tab_class = tab_class _ ' ac_tab_selected' IF type == selected_type; 
             IF ctx.added_content.$type.status != '2'; # no content
+                all_hidden = 0;
                 IF ctx.added_content.$type.status == '3' AND want_dojo; # status unknown
                     tab_class = tab_class _ ' hidden';
                 END %]
@@ -28,7 +32,8 @@
                 <a href="[% mkurl('', {ac => type}) _ '#addedcontent' %]">[% ac_types.$type %]</a>
             </div>
             [% END;
-        END %]
+        END;
+    %]
     </div>
 
     <div id='ac_content'>
@@ -41,6 +46,8 @@
                 ELSE;
                     l('No Content Available');
                 END;
+            ELSIF all_hidden;
+                l('No Content Available');
             END;
         %]
     </div>
diff --git a/Open-ILS/src/templates/opac/parts/record/extras.tt2 b/Open-ILS/src/templates/opac/parts/record/extras.tt2
index 63f82ee..d02efb0 100644
--- a/Open-ILS/src/templates/opac/parts/record/extras.tt2
+++ b/Open-ILS/src/templates/opac/parts/record/extras.tt2
@@ -3,6 +3,11 @@
 
         [%  # Hidden extras are not yet implemented.  Some may require JS
 
+        MACRO tab_is_active(tab) BLOCK;
+            exp_name = 'expand_' _ tab;
+            IF ctx.$exp_name OR ctx.expand_all; 1; END;
+        END;
+
         # Let's see if we should hide the content cafe / simple summary content
         hide_summary = 1;
         IF attrs.summary.0; hide_summary = 0; ELSE;
@@ -14,6 +19,15 @@
             END;
         END;
 
+        # if no added content is available, hide the main tab
+        IF !tab_is_active('addedcontent');
+            hide_ac = 1;
+            FOR type IN ctx.added_content.keys;
+                SET hide_ac = 0 IF 
+                    ctx.added_content.$type.status != '2'; # not available
+            END;
+        END;
+
         extras = [
             {name => 'summaryplus',  label => l('Summaries &amp; More'), hide => hide_summary}, 
             {name => 'contents',  label => l('Contents'), hide => !attrs.contents},
@@ -22,16 +36,11 @@
             {name => 'excerpt',  label => l('Excerpt'), hide => 1},
             {name => 'issues',   label => l('Issues Held'), hide => !(ctx.have_holdings_to_show || ctx.have_mfhd_to_show)},
             {name => 'preview',  label => l('Preview'), hide => 1}, 
-            {name => 'addedcontent',  label => l('Additional Content')},  # hide if all content is known to not exist
+            {name => 'addedcontent',  label => l('Additional Content'), hide => hide_ac},  # hide if all content is known to not exist
             {name => 'cnbrowse', label => l('Shelf Browser')},
             {name => 'marchtml', label => l('MARC Record')}
         ];
 
-        MACRO tab_is_active(tab) BLOCK;
-            exp_name = 'expand_' _ tab;
-            IF ctx.$exp_name OR ctx.expand_all; 1; END;
-        END;
-
         FOREACH extra IN extras;
             IF extra.hide; NEXT; END; 
             name = extra.name;
diff --git a/Open-ILS/web/css/skin/default/opac/style.css b/Open-ILS/web/css/skin/default/opac/style.css
index de20865..6e69772 100644
--- a/Open-ILS/web/css/skin/default/opac/style.css
+++ b/Open-ILS/web/css/skin/default/opac/style.css
@@ -1433,5 +1433,7 @@ a.preflib_change {
 }
 
 #ac_tab_wrapper { width : 100%; }
-.ac_tab { float: left; padding-right: 10px; font-size: 110%;  }
+.ac_tab { float: left; padding-right: 10px; font-size: 110%; padding: 5px; border: 1px solid #417860; }
+.ac_tab_selected { background-color: #417860; }
+.ac_tab_selected a { color: #FFF; }
 #ac_content { clear: both; width: 100%; margin-top: 10px; }

commit 5a6956654d190aab736366bee72501eef06d09be
Author: Bill Erickson <berick at esilibrary.com>
Date:   Mon May 14 15:22:08 2012 -0400

    TPAC added content integration
    
    https://bugs.launchpad.net/evergreen/+bug/984963
    
    This adds a new tab on the detail page called Additional Content
    (suggestions welcome).  When the tab is expanded, available content is
    presented to the user via a series of sub-tabs.
    
    At the start of loading the record detail page, kick off a series of
    asynchronous HTTP HEAD requests, one per type of added content.  At the
    end of context loading, read the results of the HTTP requests for any
    that have completed.  If the status for a type is 200, the type is
    marked as available.  If it's not 200 (usually 404) it's marked as not
    available.  Otherwise, it's marked as unknown.
    
    In the template, available content produces a link the user can click
    to view the content.  Non-available content produces no links.  Unknown
    content produces a link that may lead to content or no content when
    JS/dojo is disabled.  When dojo is enabled, unknown content sends a
    series of JS queries to determine the state of the content
    asynchronously and results in displayed links for any type that is later
    determined to have content.
    
    TODO: when the user expands the Additional Content tab, no type is
    chosen by default.  A default (available) type needs to be selected on
    initial display.
    
    TODO: better styling, particularly in the sub-tabs.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
index af1c3fc..f7d09f6 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
@@ -5,8 +5,12 @@ use OpenSRF::Utils::Logger qw/$logger/;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Utils::Fieldmapper;
 use OpenILS::Application::AppUtils;
+use Net::HTTP::NB;
+use IO::Select;
 my $U = 'OpenILS::Application::AppUtils';
 
+our $ac_types = ['toc',  'anotes', 'excerpt', 'summary', 'reviews'];
+
 # context additions: 
 #   record : bre object
 sub load_record {
@@ -15,6 +19,13 @@ sub load_record {
     $ctx->{page} = 'record';  
 
     $self->timelog("load_record() began");
+
+    my $rec_id = $ctx->{page_args}->[0]
+        or return Apache2::Const::HTTP_BAD_REQUEST;
+
+    $self->added_content_stage1($rec_id);
+    $self->timelog("past added content stage 1");
+
     my $org = $self->_get_search_lib();
     my $org_name = $ctx->{get_aou}->($org)->shortname;
     my $pref_ou = $self->_get_pref_lib();
@@ -29,9 +40,6 @@ sub load_record {
     my $copy_limit = int($self->cgi->param('copy_limit') || 10);
     my $copy_offset = int($self->cgi->param('copy_offset') || 0);
 
-    my $rec_id = $ctx->{page_args}->[0]
-        or return Apache2::Const::HTTP_BAD_REQUEST;
-
     $self->get_staff_search_settings;
     if ($ctx->{staff_saved_search_size}) {
         $ctx->{saved_searches} = ($self->staff_load_searches)[1];
@@ -126,6 +134,11 @@ sub load_record {
     }
 
     $self->timelog("past expandies");
+
+    $self->added_content_stage2($rec_id);
+
+    $self->timelog("past added content stage 2");
+
     return Apache2::Const::OK;
 }
 
@@ -398,4 +411,114 @@ sub load_email_record {
     return Apache2::Const::OK;
 }
 
+# for each type, fire off the reqeust to see if content is available
+# ctx.added_content.$type.status:
+#   1 == available
+#   2 == not available
+#   3 == unknown
+sub added_content_stage1 {
+    my $self = shift;
+    my $rec_id = shift;
+    my $ctx = $self->ctx;
+    my $sel_type = $self->cgi->param('ac') || '';
+    my $key = $self->get_ac_key($rec_id);
+    ($key = $key->{value}) =~ s/^\s+//g if $key;
+
+    $ctx->{added_content} = {};
+    for my $type (@$ac_types) {
+        $ctx->{added_content}->{$type} = {content => ''};
+        $ctx->{added_content}->{$type}->{status} = $key ? 3 : 2;
+
+        if ($key) {
+            $logger->debug("tpac: starting added content request for $key => $type");
+
+            my $req = Net::HTTP::NB->new(Host => $self->apache->hostname);
+
+            if (!$req) {
+                $logger->warn("Unable to fetch added content from " . $self->apache->hostname . ": $@");
+                next;
+            }
+
+            my $http_type = ($type eq $sel_type) ? 'GET' : 'HEAD';
+            $req->write_request($http_type => "/opac/extras/ac/$type/html/$key");
+            $ctx->{added_content}->{$type}->{request} = $req;
+        }
+    }
+}
+
+# check each outstanding request.  If it's ready, read the HTTP 
+# status and use it to determine if content is available.  Otherwise,
+# leave the status as unknown.
+sub added_content_stage2 {
+    my $self = shift;
+    my $ctx = $self->ctx;
+    my $sel_type = $self->cgi->param('ac') || '';
+
+    for my $type (keys %{$ctx->{added_content}}) {
+        my $content = $ctx->{added_content}->{$type};
+
+        if ($content->{status} == 3) {
+            $logger->debug("tpac: finishing added content request for $type");
+
+            my $req = $content->{request};
+            my $sel = IO::Select->new($req);
+
+            # if we are requesting a specific type of content, give the 
+            # backend code a little extra time to retrieve the content.
+            my $wait = $type eq $sel_type ? 3 : 0; # TODO: config?
+
+            if ($sel->can_read($wait)) {
+                my ($code) = $req->read_response_headers;
+                $content->{status} = $code eq '200' ? 1 : 2;
+                $logger->debug("tpac: added content request for $type returned $code");
+
+                if ($type eq $sel_type) {
+                    while (1) {
+                        my $buf;
+                        my $n = $req->read_entity_body($buf, 1024);
+                        last unless $n;
+                        $content->{content} .= $buf;
+                    }
+                }
+            }
+        }
+    }
+}
+
+# XXX this is copied directly from AddedContent.pm in 
+# working/user/jeff/ac_by_record_id_rebase.  When Jeff's
+# branch is merged and Evergreen gets added content 
+# lookup by ID, this can be removed.
+# returns [{tag => $tag, value => $value}, {tag => $tag2, value => $value2}]
+sub get_ac_key {
+    my $self = shift;
+    my $rec_id = shift;
+    my $key_data = $self->editor->json_query({
+        select => {mfr => ['tag', 'value']},
+        from => 'mfr',
+        where => {
+            record => $rec_id,
+            '-or' => [
+                {
+                    '-and' => [
+                        {tag => '020'},
+                        {subfield => 'a'}
+                    ]
+                }, {
+                    '-and' => [
+                        {tag => '024'},
+                        {subfield => 'a'},
+                        {ind1 => 1}
+                    ]
+                }
+            ]
+        }
+    });
+
+    return (
+        grep {$_->{tag} eq '020'} @$key_data,
+        grep {$_->{tag} eq '024'} @$key_data
+    )[0];
+}
+
 1;
diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2
index df50a03..b29a0bc 100644
--- a/Open-ILS/src/templates/opac/parts/js.tt2
+++ b/Open-ILS/src/templates/opac/parts/js.tt2
@@ -77,4 +77,42 @@
 </script>
 [% END; # use_autosuggest %]
 
+<script type="text/javascript">
+    [% ac_types = ['toc',  'anotes', 'excerpt', 'summary', 'reviews'] %]
+
+    /* Checks to see if a given type of added content has data to show.
+     * The first arg to callback() is boolean indicating the presence of data.
+     */
+    function acIsAvailable(ident, type, callback) {
+        var url = '/opac/extras/ac/' + type + '/html/' + ident;
+        dojo.xhr('HEAD', {
+            url : url, 
+            failOk : true, // http://bugs.dojotoolkit.org/ticket/11568
+            error : function(err) { callback(false, ident, type); },
+            load : function(result) { callback(true, ident, type); }
+        });
+    }
+
+    [% 
+        IF ctx.page == 'record';
+            # XXX revisit when ident=ctx.bre_id
+            ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc; 
+            IF ident; 
+                FOR type IN ac_types;
+                    IF ctx.added_content.$type.status == '3' # status unknown %]
+                        dojo.addOnLoad(function() {
+                            var ident = '[% ident %]';
+                            var type = '[% type %]';
+                            acIsAvailable(ident, type, function(avail, ident, type) { 
+                                // if the content is available, un-hide the tab
+                                if (avail) dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
+                            });
+                        });
+                    [% END; # IF status unknown
+                END; 
+            END; # IF ident
+        END;
+    %]
+</script>
+
 [%- END; # want_dojo -%]
diff --git a/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2 b/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2
new file mode 100644
index 0000000..21e81ef
--- /dev/null
+++ b/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2
@@ -0,0 +1,49 @@
+<div class='rdetail_extras_div'> 
+
+[% 
+    ac_types = {
+        reviews => l('Reviews'),
+        anotes  => l('Author Notes'),
+        toc     => l('Table of Contents'),
+        excerpt => l('Excerpt'),
+        summary => l('Summary')
+    };
+
+    selected_type = CGI.param('ac');
+    
+    # For each type of added content, render the link if it's known to have
+    # content, do not render the link if it's known to not have content.  If 
+    # the content status is unknown, render the link, but hide the link via CSS
+    # if dojo is enabled.  If dojo is not enabled, render and display the link.
+%]
+
+    <div id='ac_tab_wrapper'>
+        [% FOR type IN ac_types.keys;
+            tab_class = 'ac_tab';
+            IF ctx.added_content.$type.status != '2'; # no content
+                IF ctx.added_content.$type.status == '3' AND want_dojo; # status unknown
+                    tab_class = tab_class _ ' hidden';
+                END %]
+            <div class="[% tab_class %]" id="ac:[% type %]">
+                <a href="[% mkurl('', {ac => type}) _ '#addedcontent' %]">[% ac_types.$type %]</a>
+            </div>
+            [% END;
+        END %]
+    </div>
+
+    <div id='ac_content'>
+        <hr/>
+        [% 
+            IF selected_type; 
+                content = ctx.added_content.$selected_type.content;
+                IF content;
+                    content;
+                ELSE;
+                    l('No Content Available');
+                END;
+            END;
+        %]
+    </div>
+</div>
+
+
diff --git a/Open-ILS/src/templates/opac/parts/record/body.tt2 b/Open-ILS/src/templates/opac/parts/record/body.tt2
index b7efd51..664abc9 100644
--- a/Open-ILS/src/templates/opac/parts/record/body.tt2
+++ b/Open-ILS/src/templates/opac/parts/record/body.tt2
@@ -2,6 +2,7 @@
     PROCESS "opac/parts/misc_util.tt2";
     PROCESS get_marc_attrs args=attrs;
     stop_parms = ['expand','cnoffset'];
+    ctx.record_attrs = attrs; # capture for JS
 %]
 <div id='canvas_main' class='canvas' itemscope itemtype='[% args.schema.itemtype %]'>
 
diff --git a/Open-ILS/src/templates/opac/parts/record/extras.tt2 b/Open-ILS/src/templates/opac/parts/record/extras.tt2
index 4a473c3..63f82ee 100644
--- a/Open-ILS/src/templates/opac/parts/record/extras.tt2
+++ b/Open-ILS/src/templates/opac/parts/record/extras.tt2
@@ -22,6 +22,7 @@
             {name => 'excerpt',  label => l('Excerpt'), hide => 1},
             {name => 'issues',   label => l('Issues Held'), hide => !(ctx.have_holdings_to_show || ctx.have_mfhd_to_show)},
             {name => 'preview',  label => l('Preview'), hide => 1}, 
+            {name => 'addedcontent',  label => l('Additional Content')},  # hide if all content is known to not exist
             {name => 'cnbrowse', label => l('Shelf Browser')},
             {name => 'marchtml', label => l('MARC Record')}
         ];
@@ -40,7 +41,7 @@
             <div class="rdetail_extras_link">
                 [%  
                     IF tab_is_active(name);
-                        href = mkurl('', {}, ['expand']);
+                        href = mkurl('', {}, ['expand', 'ac']);
                         img_url = ctx.media_prefix _ '/images/rdetail_arrow_down.png';
                     ELSE;
                         href = mkurl('', {expand => name}) _ '#' _ name; 
diff --git a/Open-ILS/web/css/skin/default/opac/style.css b/Open-ILS/web/css/skin/default/opac/style.css
index 0a33df7..de20865 100644
--- a/Open-ILS/web/css/skin/default/opac/style.css
+++ b/Open-ILS/web/css/skin/default/opac/style.css
@@ -1431,3 +1431,7 @@ a.preflib_change {
     margin: 1em;
     border: thick solid red;
 }
+
+#ac_tab_wrapper { width : 100%; }
+.ac_tab { float: left; padding-right: 10px; font-size: 110%;  }
+#ac_content { clear: both; width: 100%; margin-top: 10px; }

-----------------------------------------------------------------------

Summary of changes:
 .../perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm |  129 +++++++++++++++++++-
 Open-ILS/src/templates/opac/parts/acjs.tt2         |   55 +++++++++
 Open-ILS/src/templates/opac/parts/js.tt2           |    2 +
 .../templates/opac/parts/record/addedcontent.tt2   |   56 +++++++++
 Open-ILS/src/templates/opac/parts/record/body.tt2  |    1 +
 .../src/templates/opac/parts/record/extras.tt2     |   36 +++++--
 Open-ILS/web/css/skin/default/opac/style.css       |    6 +
 7 files changed, 274 insertions(+), 11 deletions(-)
 create mode 100644 Open-ILS/src/templates/opac/parts/acjs.tt2
 create mode 100644 Open-ILS/src/templates/opac/parts/record/addedcontent.tt2


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list