KMAIN 1558
authorMichael Glass <mglass@catalystitservices.com>
Thu, 2 Apr 2015 23:49:39 +0000 (16:49 -0700)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Added a javscript sort to browse_results.tt2 to display cross references
in alphabetical order. 1558 Made sort more modular

modified:   KCLS/openils/var/templates_kcls/opac/browse_results.tt2

Signed-off-by: Michael Glass<mglass@catalystitservices.com
Conflicts:
KCLS/openils/var/templates_kcls/opac/browse_results.tt2

KCLS/openils/var/templates_kcls/opac/browse_results.tt2

index bf11734..ecbf1bc 100644 (file)
@@ -1,3 +1,4 @@
+[% USE Dumper %]
 [%- # This is the bib and authority combined record browser.
 
     PROCESS "opac/parts/header.tt2";
 
                                             # get_authority_fields is fast and cache-y.
                                             acs = ctx.get_authority_fields(a.control_set);
-                                            FOR field_group IN a.headings;
+                                            FOR field_group IN a.headings.sort('field_group.values.0.headings.heading');
                                                 field_id = field_group.keys.0;
                                                 field = acs.$field_id;
                                                 headings = field_group.values.0;
 
                                             # get_authority_fields is fast and cache-y.
                                             acs = ctx.get_authority_fields(a.control_set);
-                                            FOR field_group IN a.headings;
+                                            FOR field_group IN a.headings.sort;
                                                 field_id = field_group.keys.0;
                                                 field = acs.$field_id;
                                                 headings = field_group.values.0;
         [% END;
     END;    # end of BLOCK authority_notes %]
     <script>
+               function sortList(ul){
+                       var new_ul = ul.cloneNode(false);
+
+                       // Add all lis to an array
+                       var lis = [];
+                       for(var i = ul.childNodes.length; i--;){
+                               if(ul.childNodes[i].nodeName === 'LI')
+                                       lis.push(ul.childNodes[i]);
+                       }
+                       // Sort the lis in descending order
+                       lis.sort(function(a, b){
+                          return ((b.textContent.trim()) < (a.textContent.trim())) ? 1 : -1;
+                       });
+
+                       // Add them into the ul in order
+                       for(var i = 0; i < lis.length; i++)
+                               new_ul.appendChild(lis[i]);
+                       ul.parentNode.replaceChild(new_ul, ul);
+               }
+               for (var i = 0; i < document.getElementsByClassName('browse-result-authority-headings').length; i++) {
+                       sortList(document.getElementsByClassName('browse-result-authority-headings')[i]);
+               }
+       </script>
+    <script>
         replaceContentInContainer('staff-client-link');
         replaceContentInContainer('see-reference-no-link');
     </script>