LP1741162: remove dojo from added content user/sandbergja/lp1741162_added_content_vanilla_js
authorJane Sandberg <sandbergja@gmail.com>
Sun, 16 Oct 2022 15:05:55 +0000 (08:05 -0700)
committerJane Sandberg <sandbergja@gmail.com>
Sun, 16 Oct 2022 15:08:54 +0000 (08:08 -0700)
Largely based on Dan Scott's commit 2d46db2562dfc062b84a8ffde1cd35f00b14eed3.

Also, removes the bootstrap-specific version of this file, since they are largely duplicates.

Co-authored-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/templates-bootstrap/opac/parts/acjs.tt2 [deleted file]
Open-ILS/src/templates/opac/parts/acjs.tt2 [changed mode: 0644->0755]

diff --git a/Open-ILS/src/templates-bootstrap/opac/parts/acjs.tt2 b/Open-ILS/src/templates-bootstrap/opac/parts/acjs.tt2
deleted file mode 100755 (executable)
index fa76861..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-
-<script>
-
-    /* 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(bre_id, type, callback) {
-        var url = '/opac/extras/ac/' + type + '/html/r/' + bre_id;
-        dojo.xhr('HEAD', {
-            url : url,
-            failOk : true, // http://bugs.dojotoolkit.org/ticket/11568
-            error : function(err) { callback(false, bre_id, type); },
-            load : function(result) { callback(true, bre_id, type); }
-        });
-    }
-
-    [%-
-        FOR type IN ctx.added_content.keys;
-            IF ctx.added_content.$type.status == '3' # status unknown %]
-
-                dojo.addOnLoad(function() {
-                    var bre_id = '[% ctx.bre_id %]';
-                    var type = '[% type %]';
-
-                    acIsAvailable(bre_id, type, function(avail, bre_id, 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; # FOR type
-
-        ident = ctx.record_attrs.isbn_clean || ctx.record_attrs.upc;
-        IF ident;
-    -%]
-
-[%- IF ENV.OILS_NOVELIST_URL -%]
-            /* Load novelist content */
-            setTimeout( function() {
-            novSelect.loadContentForQuery(
-                {
-                    ClientIdentifier : '[% ident %]',
-                    ISBN : '[% ident %]',
-                    version : '2.1'
-                },
-                '[% ENV.OILS_NOVELIST_PROFILE %]',
-                '[% ENV.OILS_NOVELIST_PASSWORD %]',
-                function(d){
-                    // note if d.length == 0, there is no content to display
-                    // hide the Loading... text
-                    dojo.byId('novelist-loading').innerHTML = '';
-                }
-            )}, 100);
-[%- END; # Novelist -%]
-
-        [% END; # IF ident
-    %]
-</script>
old mode 100644 (file)
new mode 100755 (executable)
index 9d4eaa2..f725550
@@ -1,47 +1,40 @@
 
-<script type="text/javascript">
+<script>
 
     /* 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(bre_id, type, callback) {
-        var url = '/opac/extras/ac/' + type + '/html/r/' + bre_id;
-        dojo.xhr('HEAD', {
-            url : url,
-            failOk : true, // http://bugs.dojotoolkit.org/ticket/11568
-            error : function(err) { callback(false, bre_id, type); },
-            load : function(result) { callback(true, bre_id, type); }
-        });
+     * Returns a promise of a boolean value */
+    async function acIsAvailable(bre_id, type) {
+        const url = '/opac/extras/ac/' + type + '/html/r/' + bre_id;
+        const response = await fetch(url, {method: 'HEAD'});
+        return response.ok;
     }
 
     [%-
         FOR type IN ctx.added_content.keys;
             IF ctx.added_content.$type.status == '3' # status unknown %]
 
-                dojo.addOnLoad(function() {
+                window.addEventListener('load', () => {
                     var bre_id = '[% ctx.bre_id %]';
                     var type = '[% type %]';
 
-                    acIsAvailable(bre_id, type, function(avail, bre_id, type) {
+                    acIsAvailable(bre_id, type).then((avail) => {
                         if (avail) {
-
-                            [% IF CGI.param('expand') == 'addedcontent' %]
-
+                            let params = (new URL(document.location)).searchParams;
+                            if (params.get('expand') === 'addedcontent') {
                                 // if the content is available, un-hide the tab
-                                dojo.removeClass(dojo.byId('ac:' + type), 'hidden');
-
-                            [% ELSE %]
+                                document.getElementById('ac:' + type)).classList.remove('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 link = document.querySelector('[name="addedcontent"]');
                                 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);
+                                    link.setAttribute('href', href);
+                                    document.querySelector('[name="addedcontent_lbl"]').setAttribute('href', href);
                                 }
-
-                            [% END %]
+                            }
                         }
                     });
                 });
@@ -66,7 +59,7 @@
                 function(d){
                     // note if d.length == 0, there is no content to display
                     // hide the Loading... text
-                    dojo.byId('novelist-loading').innerHTML = '';
+                    document.getElementById('novelist-loading').innerHTML = '';
                 }
             )}, 100);
 [%- END; # Novelist -%]