From: McCanna Date: Wed, 18 Apr 2018 20:51:42 +0000 (-0400) Subject: PINES Customization for Syndetics X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a290466303ad23590d042c1734d0533ff183c775;p=evergreen%2Fpines.git PINES Customization for Syndetics - Eliminates the multiple Syndetics calls for every type of content. - Creates new modal popup for Syndetics content instead of screenscraping. - Also requires move of Syndetics url & id from opensrf.xml to eg_vhost.conf. - Updates extras.tt2 to always expand added content section of Syndetics content is available. Signed-off-by: McCanna --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Syndetic.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Syndetic.pm index ad908ef7e1..dd6d945aa1 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Syndetic.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Syndetic.pm @@ -17,16 +17,6 @@ sub new { return bless($args, $class); } -sub base_url { - my $self = shift; - return $self->{base_url}; -} - -sub userid { - my $self = shift; - return $self->{userid}; -} - sub expects_keyhash { # we expect a keyhash as opposed to a simple scalar containing an ISBN return 1; @@ -52,170 +42,14 @@ sub jacket_large { } # -------------------------------------------------------------------------- - -sub toc_html { - my( $self, $key ) = @_; - return $self->send_html( - $self->fetch_content('toc.html', $key)); -} - -sub toc_xml { - my( $self, $key ) = @_; - return $self->send_xml( - $self->fetch_content('toc.xml', $key)); -} - -sub toc_json { - my( $self, $key ) = @_; - return $self->send_json( - $self->fetch_content('toc.xml', $key)); -} - -# -------------------------------------------------------------------------- - -sub anotes_html { - my( $self, $key ) = @_; - return $self->send_html( - $self->fetch_content('anotes.html', $key)); -} - -sub anotes_xml { - my( $self, $key ) = @_; - return $self->send_xml( - $self->fetch_content('anotes.xml', $key)); -} - -sub anotes_json { - my( $self, $key ) = @_; - return $self->send_json( - $self->fetch_content('anotes.xml', $key)); -} - - -# -------------------------------------------------------------------------- - -sub excerpt_html { - my( $self, $key ) = @_; - return $self->send_html( - $self->fetch_content('dbchapter.html', $key)); -} - -sub excerpt_xml { - my( $self, $key ) = @_; - return $self->send_xml( - $self->fetch_content('dbchapter.xml', $key)); -} - -sub excerpt_json { - my( $self, $key ) = @_; - return $self->send_json( - $self->fetch_content('dbchapter.xml', $key)); -} - -# -------------------------------------------------------------------------- - -sub reviews_html { - my( $self, $key ) = @_; - - my %reviews; - - $reviews{ljreview} = $self->fetch_content('ljreview.html', $key); # Library Journal - $reviews{pwreview} = $self->fetch_content('pwreview.html', $key); # Publishers Weekly - $reviews{sljreview} = $self->fetch_content('sljreview.html', $key); # School Library Journal - $reviews{chreview} = $self->fetch_content('chreview.html', $key); # CHOICE Review - $reviews{blreview} = $self->fetch_content('blreview.html', $key); # Booklist Review - $reviews{hbreview} = $self->fetch_content('hbreview.html', $key); # Horn Book Review - $reviews{kireview} = $self->fetch_content('kireview.html', $key); # Kirkus Reviews - #$reviews{abreview} = $self->fetch_content('abreview.html', $key); # Bookseller+Publisher - #$reviews{criticasreview} = $self->fetch_content('criticasreview.html', $key); # Criticas - $reviews{nyreview} = $self->fetch_content('nyreview.html', $key); # New York Times - #$reviews{gdnreview} = $self->fetch_content('gdnreview.html', $key); # Guardian Review - #$reviews{doodysreview} = $self->fetch_content('doodysreview.html', $key); # Doody's Reviews - - for(keys %reviews) { - if( ! $self->data_exists($reviews{$_}) ) { - delete $reviews{$_}; - next; - } - $reviews{$_} =~ s///og; # Strip any doctype declarations - } - - return 0 if scalar(keys %reviews) == 0; - - #my $html = "
"; - my $html; - $html .= $reviews{$_} for keys %reviews; - #$html .= "
"; - - return $self->send_html($html); -} - -# we have to aggregate the reviews -sub reviews_xml { - my( $self, $key ) = @_; - my %reviews; - - $reviews{ljreview} = $self->fetch_content('ljreview.xml', $key); - $reviews{pwreview} = $self->fetch_content('pwreview.xml', $key); - $reviews{sljreview} = $self->fetch_content('sljreview.xml', $key); - $reviews{chreview} = $self->fetch_content('chreview.xml', $key); - $reviews{blreview} = $self->fetch_content('blreview.xml', $key); - $reviews{hbreview} = $self->fetch_content('hbreview.xml', $key); - $reviews{kireview} = $self->fetch_content('kireview.xml', $key); - #$reviews{abreview} = $self->fetch_content('abreview.xml', $key); - #$reviews{criticasreview} = $self->fetch_content('criticasreview.xml', $key); - $reviews{nyreview} = $self->fetch_content('nyreview.xml', $key); - #$reviews{gdnreview} = $self->fetch_content('gdnreview.xml', $key); - #$reviews{doodysreview} = $self->fetch_content('doodysreview.xml', $key); - - for(keys %reviews) { - if( ! $self->data_exists($reviews{$_}) ) { - delete $reviews{$_}; - next; - } - # Strip the xml and doctype declarations - $reviews{$_} =~ s/<\?xml.*?>//og; - $reviews{$_} =~ s///og; - } - - return 0 if scalar(keys %reviews) == 0; - - my $xml = ""; - $xml .= $reviews{$_} for keys %reviews; - $xml .= ""; - - return $self->send_xml($xml); -} - - -sub reviews_json { - my( $self, $key ) = @_; - return $self->send_json( - $self->fetch_content('dbchapter.xml', $key)); -} - -# -------------------------------------------------------------------------- +# See if summary.html exists for this record sub summary_html { my( $self, $key ) = @_; return $self->send_html( - $self->fetch_content('summary.html', $key)); + $self->fetch_content('summary.html', $key)); } -sub summary_xml { - my( $self, $key ) = @_; - return $self->send_xml( - $self->fetch_content('summary.xml', $key)); -} - -sub summary_json { - my( $self, $key ) = @_; - return $self->send_json( - $self->fetch_content('summary.xml', $key)); -} - -# -------------------------------------------------------------------------- - sub data_exists { my( $self, $data ) = @_; return 0 if $data =~ m/No Data Available<\/title>/iog; @@ -223,49 +57,9 @@ sub data_exists { return 1; } - -sub send_json { - my( $self, $xml ) = @_; - return 0 unless $self->data_exists($xml); - my $doc; - - try { - $doc = XML::LibXML->new->parse_string($xml); - } catch Error with { - my $err = shift; - $logger->error("added content XML parser error: $err\n\n$xml"); - $doc = undef; - }; - - return 0 unless $doc; - my $perl = OpenSRF::Utils::SettingsParser::XML2perl($doc->documentElement); - my $json = OpenSRF::Utils::JSON->perl2JSON($perl); - return { content_type => 'text/plain', content => $json }; -} - -sub send_xml { - my( $self, $xml ) = @_; - return 0 unless $self->data_exists($xml); - return { content_type => 'application/xml', content => $xml }; -} - sub send_html { my( $self, $content ) = @_; return 0 unless $self->data_exists($content); - - # Hide anything that might contain a link since it will be broken - my $HTML = <<" HTML"; - <div> - <style type='text/css'> - div.ac input, div.ac a[href],div.ac img, div.ac button { display: none; visibility: hidden } - </style> - <div class='ac'> - $content - </div> - </div> - HTML - - return { content_type => 'text/html', content => $HTML }; } sub send_img { @@ -279,15 +73,14 @@ sub send_img { # returns the raw content returned from the URL fetch sub fetch_content { - my( $self, $page, $key ) = @_; - return $self->fetch_response($page, $key)->content; + my( $self, $key ) = @_; + return $self->fetch_response($key)->content; } # returns the HTTP response object from the URL fetch sub fetch_response { - my( $self, $page, $keys, $notype ) = @_; - my $uname = $self->userid; - + my( $self, $keys) = @_; + # Fetch single isbn, upc, and issn my $isbn = $keys->{isbn}[0]; my $upc = $keys->{upc}[0]; @@ -297,7 +90,8 @@ sub fetch_response { $upc = '' if !defined($upc); $issn = '' if !defined($issn); - my $url = $self->base_url . "?isbn=$isbn/$page&upc=$upc&issn=$issn&client=$uname" . (($notype) ? '' : "&type=rw12"); + my $url = $ENV{OILS_SYNDETICS_URL} . "?isbn=$isbn/summary.html&upc=$upc&issn=$issn&client=" . $ENV{OILS_SYNDETICS_ID}; + return $AC->get_url($url); } 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 2e48ce394c..a58924e364 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm @@ -7,9 +7,12 @@ 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']; +# PINES Customization: only check for summary +# our $ac_types = ['toc', 'anotes', 'excerpt', 'summary', 'reviews']; +our $ac_types = ['summary']; # context additions: # record : bre object diff --git a/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2 b/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2 index dd9181a8c2..27fa5d8a22 100644 --- a/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/addedcontent.tt2 @@ -1,56 +1,100 @@ -<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'> - [% - 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 %] - <div class="[% tab_class %]" id="ac:[% type %]"> - <a href="[% mkurl('', {ac => type}) _ '#addedcontent' %]" rel="nofollow" vocab="">[% ac_types.$type %]</a> - </div> - [% END; - END; - %] - </div> +<!-- PINES CUSTOMIZATION: Use complete Syndetic content in modal pop-up instead of screenscraped from page --> +[% IF attrs.isbn_clean || attrs.upc || attrs.issn %] + <style> + /* The Syndetics Modal Stylesheet */ + .smodal { + display: none; /* Hidden by default */ + position: fixed; /* Stay in place */ + z-index: 1; /* Sit on top */ + padding-top: 30px; /* Location of the box */ + left: 0; + top: 0; + width: 100%; /* Full width */ + height: 100%; /* Full height */ + overflow: auto; /* Enable scroll if needed */ + background-color: rgb(0,0,0); /* Fallback color */ + background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ + } + + /* Modal Content */ + .smodal-content { + background-color: #fefefe; + margin: auto; + padding: 0px; + border: 1px solid #888; + width: 80%; + } + + /* Iframe Content */ + .smodal-iframe { + margin: auto; + padding:0px; + border: 0px; + width: 100%; + height: 600px; + } + + /* Launch Button */ + .smodal-button { + margin: 20px; + } + + /* The Close Button */ + .close { + color: #aaaaaa; + float: right; + font-size: 28px; + font-weight: bold; + } + + .close:hover, + .close:focus { + color: #000; + text-decoration: none; + cursor: pointer; + } + + </style> + + + <div class='rdetail_extras_div'> + <button class="smodal-button" id="sBtn">See Summary, Reviews, and More from Syndetics</button> + <div id="sModal" class="smodal"> + <div class="smodal-content"> + <span class="close">×</span> + <iframe class="smodal-iframe" src="[%- ENV.OILS_SYNDETICS_URL -%]?isbn=[%- attrs.isbn_clean -%]/index.html&client=[%- ENV.OILS_SYNDETICS_ID -%]&type=rn12&close=no&popup=no&upc=[%- attrs.upc -%]&issn=[%- attrs.issn -%]"> + <p>[% l("This browser does not support this type of content.") %]</p> + </iframe> + </div> + </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; - ELSIF all_hidden; - l('No Content Available'); - END; - %] </div> -</div> + <script> + // Get the Syndetics modal + var modal = document.getElementById('sModal'); + + // Get the button that opens the modal + var btn = document.getElementById("sBtn"); + + // Get the <span> element that closes the modal + var span = document.getElementsByClassName("close")[0]; + + // When the user clicks the button, open the modal + btn.onclick = function() { + modal.style.display = "block"; + } + + // When the user clicks on <span> (x), close the modal + span.onclick = function() { + modal.style.display = "none"; + } + // When the user clicks anywhere outside of the modal, close it + window.onclick = function(event) { + if (event.target == modal) { + modal.style.display = "none"; + } + } + </script> +[% END %] \ No newline at end of file diff --git a/Open-ILS/src/templates/opac/parts/record/extras.tt2 b/Open-ILS/src/templates/opac/parts/record/extras.tt2 index c6c55cb335..8519275936 100644 --- a/Open-ILS/src/templates/opac/parts/record/extras.tt2 +++ b/Open-ILS/src/templates/opac/parts/record/extras.tt2 @@ -38,17 +38,13 @@ END; # 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'); + IF ctx.added_content.summary.status != '2'; # not available hide_ac = 1; - 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; + ELSE; + IF !attrs.isbn_clean && !attrs.upc && !attrs.issn; + hide_ac = 1; + ELSE; + hide_ac = 0; END; END; @@ -71,33 +67,20 @@ <div class="rdetail_extras"> <div class="rdetail_extras_hr"></div> <div class="rdetail_extras_link"> - [% - IF tab_is_active(name); + [% + IF tab_is_active(name) OR name == 'awards' OR name == 'addedcontent'; href = mkurl('', {}, ['expand', 'ac']); - arrow = arrow_down; - ELSIF name == 'awards'; - href = mkurl('', {}, ['expand', 'ac']); - arrow = arrow_down; + arrow = arrow_down; ELSE; - IF name == 'addedcontent' AND default_ac; - href = mkurl('', {expand => name, ac => default_ac}) _ '#' _ name; - ELSE; - IF name == 'addedcontent' AND default_ac; - href = mkurl('', {expand => name, ac => default_ac}) _ '#' _ name; - ELSIF name == 'awards'; - href = mkurl('', {}, ['expand', 'ac']); - ELSE; - href = mkurl('', {expand => name}) _ '#' _ name; - END; - arrow = arrow_right; - END; + href = mkurl('', {expand => name}) _ '#' _ name; + arrow = arrow_right; END; %] <a name='[% name %]' href='[% href %]' class="rdetail_extras_lbl" rel="nofollow" vocab="">[% arrow %] [% extra.label | html %]</a> </div> </div> <div class='rdetail_extras_div'> - [% IF tab_is_active(name) OR name == 'awards'; + [% IF tab_is_active(name) OR name == 'awards' OR name == 'addedcontent'; IF name == 'marchtml'; ctx.marchtml; ELSE;