KMAIN-383 - Added link to bib record
authorBill Erickson <berickxx@gmail.com>
Wed, 29 Oct 2014 21:07:02 +0000 (17:07 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
    Cross-port: 9982f43

KCLS/openils/var/templates_kcls/cat/authority/list_id.tt2
Open-ILS/web/js/ui/kcls/cat/authority/list_id.js

index 855e001..cbc81fe 100644 (file)
@@ -5,8 +5,9 @@
 <style type="text/css">
     .authEntry { clear: both; }
     .authEntry > *:first-child { float: left; width: 20%; }
-    .authEntry > .text { float: left; width: 46%; }
+    .authEntry > .text { float: left; width: 48%; }
     .authEntry > .authority-control-set { float: right; width: 16%; ; font-style: italic; }
+    .authEntry > .bibrecord { visibility: hidden }
     .authority-control-set .acs-name { font-weight: bold; }
     .authority-control-set .acs-id { }
 </style>
index e28627f..6c9ef38 100644 (file)
@@ -101,7 +101,8 @@ function displayAuthorities(data) {
         dojo.place(
             '<div class="authEntry" id="auth' + auth.id + '">' +
             '<div class="text" id="authLabel' + auth.id + '">' +
-            '<span class="text">' + auth.text + '</span></div><div class="authority-control-set"><span>ID: ' +
+            '<span class="text" onclick="toggleBibsForAuthority('+
+                               auth.id + ');">' + auth.text + '</span></div><div class="authority-control-set"><span>ID: ' +
             auth.id + '</span></div>' +
             '<div class="authority-control-set">Control Set: <span class="acs-name">' +
             fetch_control_set(auth.thesaurus).name() +
@@ -196,7 +197,7 @@ function displayAuthorities(data) {
         auth_menu.startup();
     });
 
-    showBibCount(idArr);
+    getAssociatedBibs(idArr);
     if (foundOne == 0) {
         window.alert("No Authority Record was found. \nPlease enter a valid Authority ID.");
     }
@@ -254,33 +255,62 @@ function confirmDelete(recId) {
     }
 }
 
-function showBibCount(authIds) {
-    /* Decorate the list with # of bibs linked to each authority record */
-    var ses = new OpenSRF.ClientSession('open-ils.cat');
-    var req = ses.request('open-ils.cat.authority.records.count_linked_bibs', authIds);
-    var linkedIds = [];
+function getAssociatedBibs(authIds) {
+       var ses = new OpenSRF.ClientSession('open-ils.cat');
+    var req = ses.request('open-ils.cat.authority.records.titled_linked_bibs', authIds);
+
     req.oncomplete = function(r) {
         var msg = r.recv().content();
-        dojo.forEach(msg, function(auth) {
-                linkedIds.push(auth.authority);
-                dojo.place('<span class="bibcount">' + auth.bibs + '</span> ', 'authLabel' + auth.authority, 'first');
-            }
-        );
+        for (var i in authIds){
+                       if (authIds[i] in msg){
+                               var count = 0;
+                               for (var bib in msg[authIds[i]]){
+                                       count ++;
+                               dojo.place('<div class="bibrecord forAuth' +
+                                       authIds[i] + '"><a href="/eg/opac/record/' + authIds[i] + '" target="_blank"> - ' + msg[authIds[i]][bib] +
+                                       '</a></div> ',
+                                       'auth' + authIds[i],
+                                       'last');
+                               }
+                               dojo.place('<span class="bibcount" id="bibcount' + authIds[i] +
+                                       '" onclick="toggleBibsForAuthority('+
+                                       authIds[i] + ');">&#9658; ' + count +
+                                       '</span>',
+                                       'authLabel' + authIds[i], 'first');
+                       }
+                       else{
+                               dojo.place('<span class="bibcount">0</span> ', 'authLabel' + authIds[i], 'first');
+                               dojo.place('<div class="bibrecord"><span>-</span></div> ', 'auth' + authIds[i], 'last');
+                       }
+               }
+    }
+    req.send();
+}
 
-        /* Assign counts of 0 for every non-linked authority */
-        dojo.forEach(authIds, function (id) {
-            var found = false;
-            dojo.forEach(linkedIds, function (lid) {
-                if (id == lid) {
-                    found = true;
-                }
-            });
-            if (!found) {
-                dojo.place('<span class="bibcount">0</span> ', 'authLabel' + id, 'first');
+function toggleBibsForAuthority(authId){
+       var bibs = document.getElementsByClassName("forAuth" + authId);
+       var show = true;
+       for (var i in bibs){
+               if (bibs[i] != undefined && bibs[i].style != undefined){
+                       if (bibs[i].style.visibility == "" || bibs[i].style.visibility == "hidden"){
+                               bibs[i].style.visibility = "visible";
+                               show = true;
+                       }
+                       else{
+                               bibs[i].style.visibility = "hidden";
+                               show = false;
             }
-        });
+        }
     }
-    req.send();
+
+       var textToChange = document.getElementById("bibcount" + authId).innerHTML;
+       if (show){
+               var changedText = textToChange.replace(textToChange.substring(0,1), String.fromCharCode(9660));
+       }
+       else{
+               var changedText = textToChange.replace(textToChange.substring(0,1), String.fromCharCode(9658));
+       }
+       document.getElementById("bibcount" + authId).innerHTML = changedText;
 }
 
 function loadMarcEditor(pcrud, rec) {