Add resolver support to search results feature/resolver
authorDan Scott <dan@coffeecode.net>
Mon, 30 May 2011 16:53:41 +0000 (12:53 -0400)
committerDan Scott <dan@coffeecode.net>
Mon, 30 May 2011 16:53:41 +0000 (12:53 -0400)
Again, we use the SFX_TARGET variable as our placeholder for the
to-be-written automatic skin deployment script.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/web/opac/skin/default/xml/rdetail/rdetail_summary.xml
Open-ILS/web/opac/skin/default/xml/result/result_table.xml

index 8523487..0a3afa5 100644 (file)
                                        }
 
                                        var ses = new OpenSRF.ClientSession('open-ils.resolver');       
-                                       var req = ses.request('open-ils.resolver.resolve_holdings.raw', 'issn', issn);  
+                                       var req = ses.request(
+                                               'open-ils.resolver.resolve_holdings.raw',
+                                               'issn',
+                                               issn,
+                                               SFX_TARGET
+                                       );
                                        req.oncomplete = function(r) {
                                                var msg;
                                                dojo.forEach(r.recv().content(), function(entry) {
index 5ff3ba8..8498151 100644 (file)
                                 </td>
                             </tr>
 
+                            <tr name="local_callnumber_list" class="result_table_title_cell">
+                                <td>
+                                <!--
+                                    we snag the record id from the 901 field, and then use it
+                                    for lining up the resolver content
+                                -->
+                                <span type='opac/slot-data' query='datafield[tag="901"] subfield[code="c"]' class='hide_me'>
+                                <span class='hide_me' debug='true' type='opac/slot-format'><![CDATA[
+                                    curr_title_id = dojo.trim(BT.textContent(item));
+                                ]]></span>
+                                </span>
+                                <!--
+                                    this is very close to the layout in rdetail, we need to find the
+                                    record id in order to place the resolver info in the right spot
+                                -->
+                                <span type='opac/slot-data' query='datafield[tag="022"] subfield' class='hide_me'>
+                                <span class='hide_me' debug='true' type='opac/slot-format'><![CDATA[
+                                    var this_title_id = curr_title_id;
+                                    var issn = '';
+                                    issn = BT.textContent(item) + '';
+                                    issn = issn.replace(/^(\s|.)*?(\d{4}).(\d{3,4}[xX]?)(\s|.)*/, "$2-$3");
+
+                                    var SFX_TARGET = null;
+                                    if (issn.length > 0 && SFX_TARGET) {
+                                        try {
+                                            var ses = new OpenSRF.ClientSession('open-ils.resolver');
+                                            var req = ses.request(
+                                                'open-ils.resolver.resolve_holdings.raw',
+                                                'issn',
+                                                issn,
+                                                SFX_TARGET
+                                            );
+                                            req.oncomplete = function(r) {
+                                                var resolverInfo = "";
+                                                dojo.forEach(r.recv().content(), function(entry) {
+                                                    resolverInfo = entry.public_name + "_" + entry.target_coverage;
+                                                    if (title_list.indexOf(this_title_id) == -1) {
+                                                        url_list = "";
+                                                    }
+                                                    if (url_list.indexOf(resolverInfo) == -1) {
+                                                        var resolverNode = null;
+                                                        dojo.query('.recid').forEach(function(recinfo) {
+                                                            if (parseFloat(dojo.trim(BT.textContent(recinfo))) == parseFloat(this_title_id)) {
+                                                                resolverNode = recinfo;
+                                                            }
+                                                        });
+                                                        url_list += resolverInfo;
+                                                        var output = null;
+                                                        if (resolverNode != null) {
+                                                            var parent = resolverNode.parentNode;
+                                                            if (parent) {
+                                                                parent = parent.parentNode;
+                                                            }
+                                                            if (parent) {
+                                                                dojo.removeClass(parent,'hide_me');
+                                                            }
+                                                            output = dojo.create('div',{"style":"background-color:#EEFFEE;"},resolverNode,"last");
+                                                            dojo.addClass(output,"result_table_sfx_cell");
+                                                            title_list += this_title_id;
+                                                            var link = dojo.create('a',  {"style": "margin-left: 1em;", "class":"search_link", "href":  entry.target_url});
+                                                            var link_text = dojo.doc.createTextNode( entry.public_name);
+                                                            link.appendChild(link_text);
+                                                            output.appendChild(link);
+                                                            var coverage_text = dojo.doc.createTextNode(' - ' + entry.target_coverage
+                                                                    + (entry.target_embargo ? (' / ' + entry.target_embargo) : ''));
+                                                            output.appendChild(coverage_text);
+                                                            resolved[this_title_id] = true;
+                                                        }
+                                                    }
+                                                });
+                                            };
+                                            req.send();
+                                        } catch (err) { alert(err.message);}
+                                    }
+                                ]]></span>
+                                </span>
+                                <span type='opac/slot-data+holdings_xml-full' query='volumes'>
+                                <span class='hide_me' debug='true' type='opac/slot-format'><![CDATA[
+                                    var output = dojo.create('span'); 
+
+                                    var item_cnt = 0;
+                                    var max_items = 4;
+
+                                    dojo.query('volume', item).forEach(function(vol) {
+                                        if (item_cnt >= max_items) {
+                                            return output.innerHTML;
+                                        }
+                                        dojo.query('copy', vol).forEach(function (cp) {
+                                            if (item_cnt >= max_items) {
+                                                return;
+                                            }
+                                            if (cp.getAttribute('deleted') == 't') {
+                                                return;
+                                            }
+                                            if (cp.getAttribute('opac_visible') == 'f') {
+                                                return;
+                                            }
+                                            var cp_entry = dojo.create('div');
+                                            var loc_visible;
+                                            var vol_appended = false;
+                                            dojo.query('location', cp).forEach(function (location) {
+                                                loc_visible = location.getAttribute('opac_visible');
+                                                if (loc_visible == 't') {
+                                                    if (!vol_appended) {
+                                                        var cn = dojo.create('span', { style: "font-weight: bold;" }, cp_entry);
+                                                        var cn_txt = dojo.doc.createTextNode(vol.getAttribute('label'));
+                                                        cn.appendChild(cn_txt);
+                                                        vol_appended = true;
+                                                    }
+                                                    var loc = dojo.create('span', { "style": "font-weight: bold;"}, cp_entry);
+                                                    var loc_txt = dojo.doc.createTextNode(' - ' + BT.textContent(location));
+                                                    loc.appendChild(loc_txt);
+                                                }
+                                            });
+                                            if (loc_visible != 't') {
+                                                return;
+                                            }
+                                            dojo.query('circ_lib', cp).forEach(function (circ_lib) {
+                                                var cp_lib = dojo.create('span', { "style": "font-weight: bold;" }, cp_entry, "first");
+                                                var cp_lib_txt = dojo.doc.createTextNode(circ_lib.getAttribute('name') + ' - ');
+                                                cp_lib.appendChild(cp_lib_txt);
+                                            });
+                                            dojo.query('status', cp).forEach(function (status) {
+                                                var cp_status = dojo.create('span', { "style": "font-weight: bold;" }, cp_entry);
+                                                var cp_status_txt = dojo.doc.createTextNode(' (' + BT.textContent(status) + ')');
+                                                cp_status.appendChild(cp_status_txt);
+                                            });
+
+                                            item_cnt++;
+                                            if (item_cnt >= max_items) {
+                                                dojo.create('br', null, cp_entry);
+                                                cp_entry.appendChild(dojo.doc.createTextNode(opac_strings.MORE_COPIES_FULL_RECORD));
+                                            }
+                                            output.appendChild(cp_entry);
+                                        });
+                                    });
+
+                                return output.innerHTML;
+                                ]]></span>
+                                </span>
+
+                                <!-- Be lenient in what we accept; disabled until we figure out how to prevent both URIs and SFX -->
+                                <span type='opac/slot-data+marcxml-full' query='record'>
+                                    <span class='hide_me' type='opac/slot-format'><![CDATA[
+                                        var found_issn = false;
+                                        dojo.query('datafield[tag="022"]', item).forEach(function(issn) {
+                                            found_issn = true;
+                                        });
+                                        if (found_issn) { return; }
+
+                                        var output = dojo.create('span'); 
+                                        dojo.query('volumes volume uris uri', item).forEach(function(xitem) {
+                                            var this_title_id = curr_title_id;
+                                            if (resolved[this_title_id]) { return; }
+                                            var uri = new Object;
+                                            uri.href = xitem.getAttribute('href');
+                                            uri.label = xitem.getAttribute('label');
+                                            uri.use = xitem.getAttribute('use_restriction');
+                                            if (uri.href == uri.label) {
+                                                if (uri.use && uri.use != uri.label) {
+                                                    uri.label = uri.use;
+                                                    uri.use = null;
+                                                }
+                                            }
+                                            var link = dojo.create('a', {"class":"search_link", "href": uri.href});
+                                            var link_text = dojo.doc.createTextNode(uri.label);
+                                            link.appendChild(link_text);
+                                            output.appendChild(link);
+                            
+                                            if (uri.use) {
+                                                var use_text = dojo.doc.createTextNode(' (' + uri.use + ')');
+                                                output.appendChild(use_text);
+                                            }
+                                            dojo.create('br', null, output);
+                                        });
+                                        return output.innerHTML;
+                                    ]]></span>
+                                </span>
+                              </td>
+                            </tr>
                             <tr style='height:1em;' >
                                 <td name='result_table_format_cell' class='result_table_format_cell'>
 
 
                                 </td>
                             </tr>
-                            <tr name="local_callnumber_list" class="result_table_title_cell">
-                                <td>
-                                <span type='opac/slot-data+holdings_xml-full' query='volumes'>
-                                <span class='hide_me' debug='true' type='opac/slot-format'><![CDATA[
-                                    var output = dojo.create('span'); 
-
-                                    var item_cnt = 0;
-                                    var max_items = 4;
-
-                                    dojo.query('volume', item).forEach(function(vol) {
-                                        if (item_cnt >= max_items) {
-                                            return output.innerHTML;
-                                        }
-                                        dojo.query('copy', vol).forEach(function (cp) {
-                                            if (item_cnt >= max_items) {
-                                                return;
-                                            }
-                                            if (cp.getAttribute('deleted') == 't') {
-                                                return;
-                                            }
-                                            if (cp.getAttribute('opac_visible') == 'f') {
-                                                return;
-                                            }
-                                            var cp_entry = dojo.create('div');
-                                            var loc_visible;
-                                            var vol_appended = false;
-                                            dojo.query('location', cp).forEach(function (location) {
-                                                loc_visible = location.getAttribute('opac_visible');
-                                                if (loc_visible == 't') {
-                                                    if (!vol_appended) {
-                                                        var cn = dojo.create('span', { style: "font-weight: bold;" }, cp_entry);
-                                                        var cn_txt = dojo.doc.createTextNode(vol.getAttribute('label'));
-                                                        cn.appendChild(cn_txt);
-                                                        vol_appended = true;
-                                                    }
-                                                    var loc = dojo.create('span', { "style": "font-weight: bold;"}, cp_entry);
-                                                    var loc_txt = dojo.doc.createTextNode(' - ' + BT.textContent(location));
-                                                    loc.appendChild(loc_txt);
-                                                }
-                                            });
-                                            if (loc_visible != 't') {
-                                                return;
-                                            }
-                                            dojo.query('circ_lib', cp).forEach(function (circ_lib) {
-                                                var cp_lib = dojo.create('span', { "style": "font-weight: bold;" }, cp_entry, "first");
-                                                var cp_lib_txt = dojo.doc.createTextNode(circ_lib.getAttribute('name') + ' - ');
-                                                cp_lib.appendChild(cp_lib_txt);
-                                            });
-                                            dojo.query('status', cp).forEach(function (status) {
-                                                var cp_status = dojo.create('span', { "style": "font-weight: bold;" }, cp_entry);
-                                                var cp_status_txt = dojo.doc.createTextNode(' (' + BT.textContent(status) + ')');
-                                                cp_status.appendChild(cp_status_txt);
-                                            });
-
-                                            item_cnt++;
-                                            if (item_cnt >= max_items) {
-                                                dojo.create('br', null, cp_entry);
-                                                cp_entry.appendChild(dojo.doc.createTextNode(opac_strings.MORE_COPIES_FULL_RECORD));
-                                            }
-                                            output.appendChild(cp_entry);
-                                        });
-                                    });
-
-                                return output.innerHTML;
-                                ]]></span>
-                                </span>
-                                </td>
-                            </tr>
                             <!-- Placeholder for ChiliFresh Review -->
                             <tr class="hide_me" name="chilifreshReview">
                                 <td valign="top" colspan="2">