tpac ac part 1
authorBill Erickson <berick@esilibrary.com>
Mon, 14 May 2012 19:22:08 +0000 (15:22 -0400)
committerBill Erickson <berick@esilibrary.com>
Mon, 14 May 2012 19:22:08 +0000 (15:22 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Record.pm
Open-ILS/src/templates/opac/parts/js.tt2
Open-ILS/src/templates/opac/parts/record/addedcontent.tt2 [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/record/body.tt2
Open-ILS/src/templates/opac/parts/record/extras.tt2
Open-ILS/web/css/skin/default/opac/style.css

index af1c3fc..bf38575 100644 (file)
@@ -7,6 +7,8 @@ use OpenILS::Utils::Fieldmapper;
 use OpenILS::Application::AppUtils;
 my $U = 'OpenILS::Application::AppUtils';
 
+our $ac_types = ['toc',  'anotes', 'excerpt', 'summary', 'reviews'];
+
 # context additions: 
 #   record : bre object
 sub load_record {
@@ -398,4 +400,26 @@ sub load_email_record {
     return Apache2::Const::OK;
 }
 
+sub added_content_avail1 {
+    my $self = shift;
+    my $ctx = $self->ctx;
+    $ctx->{added_content} = {
+        map {$_ => {status => 3, content => ''}} @$ac_types;
+    };
+
+    # fire requests
+}
+
+sub added_content_avail2 {
+    my $self = shift;
+    my $ctx = $self->ctx;
+
+    # collect requests
+}
+
+sub added_content_get_type {
+    my $self = shift;
+    my $ctx = $self->ctx;
+}
+
 1;
index df50a03..1b1fb8a 100644 (file)
 </script>
 [% END; # use_autosuggest %]
 
+<script type="text/javascript">
+    [% acTypes = ['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 acTypes;
+                    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 (file)
index 0000000..f5ba965
--- /dev/null
@@ -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')
+    };
+
+    tab_class = 'ac_tab';
+    
+    # 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 
+            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 %]
+    </div>
+
+    <div id='ac_content'>
+        <hr/>
+        [% 
+            ac_type = CGI.param('ac'); 
+            IF ac_type; 
+                content = ctx.added_content.$ac_type.content;
+                IF content;
+                    content;
+                ELSE;
+                    l('No Content Available');
+                END;
+            END;
+        %]
+    </div>
+</div>
+
+
index b7efd51..664abc9 100644 (file)
@@ -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 %]'>
 
index 4a473c3..63f82ee 100644 (file)
@@ -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; 
index 0a33df7..de20865 100644 (file)
@@ -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; }