JBAS-769 Holds pull list uses alt title/author as well
authorBill Erickson <berickxx@gmail.com>
Mon, 10 Aug 2015 20:55:58 +0000 (16:55 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
The CHS and pull list UI's use the same template code to display holds.
Modifying the template for one, means modifying for both.  This udpates
the hold pull list template to use the alternate title/author extraction
code (for 245ab and 100ac display) for consistency with the display
template.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/web/opac/extras/circ/alt_holds_print.js

index 366116e..c140d95 100644 (file)
@@ -1,11 +1,46 @@
 dojo.require("dojo.cookie");
 dojo.require("dojox.xml.parser");
-dojo.require("openils.BibTemplate");
 dojo.require("openils.widget.ProgressDialog");
 
 var authtoken;
 var cgi;
 
+// extract the title and author from a MARCXML string.
+function get_marc_bits(marcxml) {
+    var m100a = '';
+    var m100c = '';
+    var m245a = '';
+    var m245b = '';
+
+    var xmlDoc = new DOMParser().parseFromString(marcxml, 'text/xml');
+
+    dojo.forEach(
+        xmlDoc.documentElement.getElementsByTagName('datafield'), 
+        function(node) {
+            var tag = node.getAttribute('tag');
+            if (tag == '100') {
+                dojo.forEach(node.childNodes, function(sub_node) {
+                    var code = sub_node.getAttribute('code');
+                    if (code == 'a') m100a = sub_node.textContent;
+                    if (code == 'c') m100c = sub_node.textContent;
+                });
+            } else if (tag == '245') {
+                dojo.forEach(node.childNodes, function(sub_node) {
+                    var code = sub_node.getAttribute('code');
+                    if (code == 'a') m245a = sub_node.textContent;
+                    if (code == 'b') m245b = sub_node.textContent;
+                });
+            }
+        }
+    );
+
+    return {
+        title : m100a + ' ' + m100c,
+        author : m245a + ' ' + m245b
+    };
+}
+
+
 function do_pull_list() {
     progress_dialog.show(true);
 
@@ -42,6 +77,12 @@ function do_pull_list() {
                     hold.current_copy.parts_stringified += ' ' + part.label();
                 });
 
+                var bits = get_marc_bits(
+                    hold.current_copy.call_number.record.marc);
+
+                hold.title = bits.title;
+                hold.author = bits.author;
+
 
                 // clone the template's html
                 var tr = dojo.clone(
@@ -54,12 +95,6 @@ function do_pull_list() {
                     }
                 );
 
-                new openils.BibTemplate({
-                    root : tr,
-                    xml  : dojox.xml.parser.parse(hold.current_copy.call_number.record.marc),
-                    delay: false
-                });
-
                 dojo.place(tr, "target");
             });
           },
@@ -214,36 +249,11 @@ function do_clear_holds_from_cache(cache_key) {
                         var hold = hashify_fields(resp.hold_details);
                         hold.action = resp.action;
 
-                        var xmlDoc = new DOMParser().parseFromString(
-                            hold.current_copy.call_number.record.marc,"text/xml");
-
-                        var m100a = '';
-                        var m100c = '';
-                        var m245a = '';
-                        var m245b = '';
-
-                        dojo.forEach(
-                            xmlDoc.documentElement.getElementsByTagName('datafield'), 
-                            function(node) {
-                                var tag = node.getAttribute('tag');
-                                if (tag == '100') {
-                                    dojo.forEach(node.childNodes, function(sub_node) {
-                                        var code = sub_node.getAttribute('code');
-                                        if (code == 'a') m100a = sub_node.textContent;
-                                        if (code == 'c') m100c = sub_node.textContent;
-                                    });
-                                } else if (tag == '245') {
-                                    dojo.forEach(node.childNodes, function(sub_node) {
-                                        var code = sub_node.getAttribute('code');
-                                        if (code == 'a') m245a = sub_node.textContent;
-                                        if (code == 'b') m245b = sub_node.textContent;
-                                    });
-                                }
-                            }
-                        );
+                        var bits = get_marc_bits(
+                            hold.current_copy.call_number.record.marc);
 
-                        hold.author = m100a + ' ' + m100c;
-                        hold.title = m245a + ' ' + m245b;
+                        hold.title = bits.title;
+                        hold.author = bits.author;
 
                         if(resp.hold_details.hold_type) {
                             hold.hold_type = resp.hold_details.hold_type;