From d325184f557aa4c1f6bf13f7ca12145b80868593 Mon Sep 17 00:00:00 2001 From: dbs Date: Thu, 4 Jun 2009 20:31:39 +0000 Subject: [PATCH] Get our default, MFHD-friendly rdetail.js into Subversion git-svn-id: svn://svn.open-ils.org/ILS-Contrib/conifer/trunk@514 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- web/opac/skin/default/js/rdetail.js | 111 +++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/web/opac/skin/default/js/rdetail.js b/web/opac/skin/default/js/rdetail.js index 139d02fae3..7aa9db6147 100644 --- a/web/opac/skin/default/js/rdetail.js +++ b/web/opac/skin/default/js/rdetail.js @@ -27,7 +27,14 @@ var rdetailShowLocal = true; var rdetailShowCopyLocation = true; var googleBookPreview = true; var enableHoldsOnAvailable = false; +var displaySerialHoldings = true; +var opac_strings; +/* serials are currently the only use of Dojo strings in the OPAC */ +if (displaySerialHoldings) { + dojo.requireLocalization("openils.opac", "opac"); + opac_strings = dojo.i18n.getLocalization("openils.opac", "opac"); +} var nextContainerIndex; @@ -118,6 +125,12 @@ function rdetailDraw() { req.callback(_rdetailDraw); req.send(); + if (displaySerialHoldings) { + var req = new Request(FETCH_MFHD_SUMMARY, getRid()); + req.callback(_holdingsDraw); + req.send(); + } + detachAllEvt("result", "idsReceived"); G.evt.result.hitCountReceived = []; G.evt.result.recordReceived = []; @@ -174,6 +187,102 @@ function rdetailShowAllCopies() { hideMe(G.ui.rdetail.cp_info_none); } +function OpenMarcEditWindow(pcrud, rec) { + /* + To run in Firefox directly, must set signed.applets.codebase_principal_support + to true in about:config + */ + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); + win = window.open('/xul/server/cat/marcedit.xul'); // XXX version? + dojo.require('openils.PermaCrud'); + + win.xulG = { + "record" : {"marc" : rec.marc()}, + "save" : { + "label": opac_strings.SAVE_MFHD_LABEL, + "func": function(xmlString) { + rec.marc(xmlString); + rec.ischanged(true); + pcrud.update(rec); + } + } + }; +} + +function loadMarcEditor(recId) { + var pcrud = new openils.PermaCrud({"authtoken": G.user.session}); + var rec = pcrud.retrieve("sre", recId); + if (rec) { + OpenMarcEditWindow(pcrud, rec); + } +} + +/* + * This function could be written much more intelligently + * Limited brain power means that I'm brute-forcing it for now + */ +function _holdingsDraw(h) { + holdings = h.getResultObject(); + if (!holdings) { return null; } + + dojo.forEach(holdings, _holdingsDrawMFHD); +} + +function _holdingsDrawMFHD(holdings, entryNum) { + var here = findOrgUnit(getLocation()); + if (getDepth() > 0 || getDepth === 0 ) { + while (getDepth() < findOrgDepth(here)) + here = findOrgUnit( here.parent_ou() ); + if (!orgIsMine(findOrgUnit(here), findOrgUnit(holdings.owning_lib()))) { + return null; + } + } + var hh = holdings.holdings(); + var hch = holdings.current_holdings(); + var hs = holdings.supplements(); + var hcs = holdings.current_supplements(); + var hi = holdings.indexes(); + var hci = holdings.current_indexes(); + var ho = holdings.online(); + var hm = holdings.missing(); + var hinc = holdings.incomplete(); + + if ( hh.length == 0 && hch.length == 0 && hs.length == 0 && + hcs.length == 0 && hi.length == 0 && hci.length == 0 && + ho.length == 0 && hm.length == 0 && hinc.length == 0 + ) { + return null; + } + + dojo.place("
" + + dojo.string.substitute(opac_strings.HOLDINGS_TABLE_CAPTION, [holdings.location()]) + + "
", "rdetail_details_table", "after" + ); + if (hh.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.HOLDINGS, hh); } + if (hch.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.CURRENT_HOLDINGS, hch); } + if (hs.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.SUPPLEMENTS, hs); } + if (hcs.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.CURRENT_SUPPLEMENTS, hcs); } + if (hi.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INDEXES, hi); } + if (hci.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.CURRENT_INDEXES, hci); } + if (ho.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.ONLINE_VOLUMES, ho); } + if (hm.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.MISSING_VOLUMES, hm); } + if (hinc.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INCOMPLETE_VOLUMES, hinc); } + + if (isXUL()) { + dojo.require('openils.Event'); + dojo.require('openils.PermaCrud'); + dojo.place(" - " + opac_strings.EDIT_LABEL + "", + "mfhdHoldingsCaption", "last" + ); + } +} + +function _holdingsDrawMFHDEntry(entryNum, entryName, entry) { + var flatEntry = entry.toString().replace(/,/g, ', '); + dojo.place(" " + entryName + "" + flatEntry + "", "rdetail_holdings_tbody_" + entryNum, "last"); +} function _rdetailDraw(r) { record = r.getResultObject(); @@ -244,7 +353,7 @@ function _rdetailDraw(r) { } } $('rdetail_online').appendChild(elem('a', {href:href,'class':'classic_link'}, displayLabel)); - if (!note && note != displayLabel) { + if (note && note != displayLabel) { $('rdetail_online').appendChild(elem('span', {'class':'url_note'}, ' - ' + note)); } $('rdetail_online').appendChild(elem('br')); -- 2.11.0