]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
dump() is a mozilla thing; use console.log instead
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / rdetail.js
1
2 /* */
3
4 detachAllEvt('common', 'run');
5 attachEvt("common", "run", rdetailDraw);
6 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
7 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
8 attachEvt("rdetail", "recordDrawn", rdetailGetPageIds);
9
10 /* Per-skin configuration settings */
11 var rdetailLocalOnly = true;
12 var rdetailShowLocal = true;
13 var rdetailShowCopyLocation = true;
14 var rdetailGoogleBookPreview = true;
15 var rdetailDisplaySerialHoldings = true;
16 var rdetailEnableRefWorks = false;
17 var rdetailRefWorksHost = 'http://www.refworks.com';
18
19 /* vars vars vars */
20 var record = null;
21 var cp_statuses = null;
22 var recordsCache = [];
23
24 var copyRowParent = null;
25 var copyRow = null;
26 var statusRow = null;
27 var numStatuses = null;
28 var defaultCN;
29 var callnumberCache = {};
30 var globalCNCache = {};
31 var localTOC;
32 var cachedRecords;
33 var _statusPositions = {};
34 var opac_strings;
35
36 var nextContainerIndex;
37
38 var nextRecord;
39 var prevRecord;
40
41 var rdetailPrev = null;
42 var rdetailNext = null;
43 var rdetailStart = null;
44 var rdetailEnd = null;
45
46 var mfhdDetails = [];
47 var orgHiding = false;
48
49 if(location.href.match(/&place_hold=1/)) {
50     // prevent load flicker between canvases
51     hideMe(dojo.byId('canvas_main'));
52 }
53
54 /* serials are currently the only use of Dojo strings in the OPAC */
55 if (rdetailDisplaySerialHoldings) {
56         dojo.require("dijit.Menu");
57         dojo.require("dijit.form.Button");
58         dojo.requireLocalization("openils.opac", "opac");
59         opac_strings = dojo.i18n.getLocalization("openils.opac", "opac");
60 }
61
62 function rdetailReload() {
63         var args = {};
64         args[PARAM_LOCATION] = getNewSearchLocation();
65         args[PARAM_DEPTH] = depthSelGetDepth();
66         goTo(buildOPACLink(args));
67 }
68
69 /* looks to see if we have a next and/or previous record in the
70    record cache, if so, set up the nav links */
71 function rdetailSetPaging(ids) {
72
73         cachedRecords = {};
74         cachedRecords.ids = ids;
75
76         for( var i = 0; i < cachedRecords.ids.length; i++ ) {
77                 var rec = cachedRecords.ids[i];
78                 if( rec == getRid() ) {
79                         if( i > 0 ) prevRecord = cachedRecords.ids[i-1];
80                         if( i < cachedRecords.ids.length - 1 )
81                                 nextRecord = cachedRecords.ids[i+1];
82                         break;
83                 }
84         }
85
86         $('np_offset').appendChild(text(i + 1));
87         $('np_count').appendChild(text(getHitCount()));
88
89         if(prevRecord) {
90                 unHideMe($('np_table'));
91                 unHideMe($('np_prev'));
92                 unHideMe($('np_start'));
93                 rdetailPrev = function() { _rdetailNav(prevRecord); };
94                 rdetailStart = function() { _rdetailNav(cachedRecords.ids[0]); };
95         }
96
97         if(nextRecord) {
98                 unHideMe($('np_table'));
99                 unHideMe($('np_next'));
100                 unHideMe($('np_end'));
101                 rdetailNext = function() { _rdetailNav(nextRecord); };
102                 rdetailEnd = function() { _rdetailNav(cachedRecords.ids[cachedRecords.ids.length-1]); };
103         }
104
105         runEvt('rdetail', 'nextPrevDrawn', i, cachedRecords.ids.length);
106 }
107
108
109 function _rdetailNav(id, offset) {
110         var args = {};
111         args[PARAM_RID] = id;
112         goTo(buildOPACLink(args));
113 }
114
115 function rdetailHandlePlaceHold() {
116     function reload() {
117         location.href = location.href.replace(/&place_hold=1/, '');
118     }
119     attachEvt("common", "holdUpdated", reload);
120     attachEvt("common", "holdUpdateCanceled", reload);
121     attachEvt("common", "loginCanceled", reload);
122     holdsDrawEditor({record:getRid(), type: 'T'});
123 }
124
125 function rdetailDraw() {
126
127     if(new CGI().param('place_hold')) {
128         rdetailHandlePlaceHold();
129         return;
130     }
131
132         detachAllEvt('common','depthChanged');
133         detachAllEvt('common','locationUpdated');
134         attachEvt('common','depthChanged', rdetailReload);
135         attachEvt('common','locationUpdated', rdetailReload);
136         attachEvt('common','holdUpdated', rdetailReload);
137         attachEvt('common','holdUpdateCanceled', rdetailReload);
138
139         copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
140         copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
141         statusRow = G.ui.rdetail.cp_status.parentNode;
142         statusRow.id = '__rdsrow';
143
144         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
145         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
146
147         if(getLocation() == globalOrgTree.id())
148                 hideMe(G.ui.rdetail.cp_info_all);
149
150     if(getRid()) {
151
152             var req = new Request(FETCH_RMODS, getRid());
153             req.callback(_rdetailDraw);
154             req.send();
155
156     } else { // No record ID was specified
157
158        // If we have an ISBN in the URL, let's try to find that record
159        // This allows direct linking by ISBN.
160        // Note, this uses the first record it finds
161        if(getRtype() == RTYPE_ISBN) { 
162             var req = new Request(FETCH_ADV_ISBN_RIDS, getAdvTerm() );
163             req.callback(
164                 function(r) {
165                     var blob = r.getResultObject();
166                     if(blob && blob.count > 0) 
167                         RID = blob.ids[0]; 
168                     var req2 = new Request(FETCH_RMODS, getRid());
169                     req2.callback(_rdetailDraw);
170                     req2.send();
171                 }
172             );
173             req.send();
174         }
175     }
176
177
178         if (rdetailDisplaySerialHoldings && (
179         isXUL() || !fetchOrgSettingDefault(
180             getLocation(), "opac.fully_compressed_serial_holdings")
181         )
182     ) {
183                 var req = new Request(FETCH_MFHD_SUMMARY, getRid());
184                 req.callback(_holdingsDraw);
185                 req.send();
186                 if (isXUL()) {
187                         var here = findOrgUnit(getLocation());
188                         dojo.place("<div id='mfhd_ad_menu'></div>", "rdetail_details_table", "after");
189                         var mfhd_add = new dijit.Menu({style:"float: right;"});
190                         new dijit.MenuItem({onClick:function(){
191                                 var req = new Request(CREATE_MFHD_RECORD, G.user.session, 1, here.id(), getRid());
192                                 var res = req.send();
193                                 alert(dojo.string.substitute(opac_strings.CREATED_MFHD_RECORD, [here.name()]));
194                         }, label:opac_strings.CREATE_MFHD}).placeAt(mfhd_add);
195                         mfhd_add.placeAt(mfhd_ad_menu);
196                 }
197         }
198
199         detachAllEvt("result", "idsReceived");
200         G.evt.result.hitCountReceived = [];
201         G.evt.result.recordReceived = [];
202         G.evt.result.copyCountsReceived = [];
203         G.evt.result.allRecordsReceived = [];
204
205     if(isXUL()) 
206         unHideMe($('rdetail_show_orders'));
207 }
208
209 function rdetailGetPageIds() {
210         attachEvt("result", "idsReceived", rdetailSetPaging );
211         resultFetchAllRecords = true;
212         rresultCollectIds(true);
213 }
214
215
216 function buildunAPISpan (span, type, id) {
217         var cgi = new CGI();
218         var d = new Date();
219
220         addCSSClass(span,'unapi-id');
221
222         span.setAttribute(
223                         'title', 'tag:' + cgi.server_name + ',' +
224                         d.getFullYear() + ':' + type + '/' + id
225                         );
226 }
227
228 function rdetailViewMarc(r,id) {
229         hideMe($('rdetail_extras_loading'));
230         $('rdetail_view_marc_box').innerHTML = r.getResultObject();
231
232         var div = elem('div', { "class" : 'hide_me' });
233         var span = div.appendChild( elem('abbr') );
234
235         buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
236
237         $('rdetail_view_marc_box').insertBefore(span, $('rdetail_view_marc_box').firstChild);
238 }
239
240
241 function rdetailShowLocalCopies() {
242         rdetailShowLocal = true;
243         rdetailBuildInfoRows();
244         hideMe(G.ui.rdetail.cp_info_local);
245         unHideMe(G.ui.rdetail.cp_info_all);
246         hideMe(G.ui.rdetail.cp_info_none); 
247 }
248
249 function rdetailShowAllCopies() {
250
251         rdetailShowLocal = false;
252         rdetailBuildInfoRows();
253         hideMe(G.ui.rdetail.cp_info_all);
254         unHideMe(G.ui.rdetail.cp_info_local);
255         hideMe(G.ui.rdetail.cp_info_none); 
256 }
257
258 function OpenMarcEditWindow(pcrud, rec) {
259         /*
260            To run in Firefox directly, must set signed.applets.codebase_principal_support
261            to true in about:config
262          */
263         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
264         win = window.open('/xul/server/cat/marcedit.xul'); // XXX version?
265         dojo.require('openils.PermaCrud');
266
267         win.xulG = {
268                 "record": {"marc": rec.marc(), "rtype": "sre"},
269                 "save": {
270                         "label": opac_strings.SAVE_MFHD_LABEL,
271                         "func": function(xmlString) {
272                                 rec.marc(xmlString);
273                                 rec.edit_date('now');
274                                 rec.ischanged(true);
275                                 pcrud.update(rec);
276                         }
277                 },
278         'lock_tab' : typeof xulG != 'undefined' ? (typeof xulG['lock_tab'] != 'undefined' ? xulG.lock_tab : undefined) : undefined,
279         'unlock_tab' : typeof xulG != 'undefined' ? (typeof xulG['unlock_tab'] != 'undefined' ? xulG.unlock_tab : undefined) : undefined
280         };
281 }
282
283 function loadMarcEditor(recId) {
284         var pcrud = new openils.PermaCrud({"authtoken": G.user.session});
285         var rec = pcrud.retrieve("sre", recId);
286         if (rec) {
287                 OpenMarcEditWindow(pcrud, rec);
288         }
289 }
290
291 /*
292  * This function could be written much more intelligently
293  * Limited brain power means that I'm brute-forcing it for now
294  */
295 function _holdingsDraw(h) {
296         holdings = h.getResultObject();
297         if (!holdings) { return null; }
298
299         dojo.forEach(holdings, _holdingsDrawMFHD);
300
301         // Populate XUL menus
302         if (isXUL()) {
303                 runEvt('rdetail','MFHDDrawn');
304         }
305 }
306
307 function _holdingsDrawMFHD(holdings, entryNum) {
308
309         var here = findOrgUnit(getLocation());
310         if (getDepth() > 0 || getDepth === 0 ) {
311                 while (getDepth() < findOrgDepth(here))
312                 here = findOrgUnit( here.parent_ou() );
313                 if (!orgIsMine(findOrgUnit(here), findOrgUnit(holdings.owning_lib()))) {
314                         return null;
315                 }
316         }
317
318         var hb = holdings.basic_holdings();
319         var hba = holdings.basic_holdings_add();
320         var hs = holdings.supplement_holdings();
321         var hsa = holdings.supplement_holdings_add();
322         var hi = holdings.index_holdings();
323         var hia = holdings.index_holdings_add();
324         var ho = holdings.online();
325         var hm = holdings.missing();
326         var hinc = holdings.incomplete();
327         var hloc = holdings.location() || 'MFHD';
328
329         if (    hb.length == 0 && hba.length == 0 && hs.length == 0 &&
330                 hsa.length == 0 && hi.length == 0 && hia.length == 0 &&
331                 ho.length == 0 && hm.length == 0 && hinc.length == 0
332         ) {
333
334                 if (isXUL()) {
335                         /* 
336                          * If we have a record, but nothing to show for it, then the
337                          * record is likely empty or corrupt. This gives cataloguers a
338                          * chance to add holdings or correct the record
339                          */
340                         hb = ['PLACEHOLDER'];
341                 } else {
342                         return null;
343                 }
344         }
345
346         // Show entryNum + 1 in staff client for better menu correlation
347         // Maybe this should be holdings.sre_id() instead? (which could get long after time)
348         var entryNumString = '';
349         if (isXUL()) {
350                 var entryNumInc = entryNum + 1;
351                 entryNumString = ' [Entry #'+entryNumInc+'] ';
352         }
353
354         var refNode;
355         if (entryNum > 0) {
356                 refNode = 'rdetail_holdings_table_' + (entryNum - 1);
357         } else {
358                 refNode = 'rdetail_details_table';
359         }
360
361         dojo.place("<table style='width: 100%;' id='rdetail_holdings_table_"+entryNum+"'><caption id='mfhdHoldingsCaption" + entryNum + "' class='rdetail_header color_1'>" +
362                 dojo.string.substitute(opac_strings.HOLDINGS_TABLE_CAPTION, [hloc]) + entryNumString +
363                 "</caption><tbody id='rdetail_holdings_tbody_" + entryNum +
364                 "'></tbody></table>", refNode, "after"
365         );
366         if (hb.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.BASIC_HOLDINGS, hb); }
367         if (hba.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.BASIC_HOLDINGS_ADD, hba); }
368         if (hs.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.SUPPLEMENT_HOLDINGS, hs); }
369         if (hsa.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.SUPPLEMENT_HOLDINGS_ADD, hsa); }
370         if (hi.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INDEX_HOLDINGS, hi); }
371         if (hia.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INDEX_HOLDINGS_ADD, hia); }
372         if (ho.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.ONLINE_VOLUMES, ho); }
373         if (hm.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.MISSING_VOLUMES, hm); }
374         if (hinc.length > 0) { _holdingsDrawMFHDEntry(entryNum, opac_strings.INCOMPLETE_VOLUMES, hinc); }
375
376         if (isXUL()) {
377                 mfhdDetails.push({ 'id' : holdings.sre_id(), 'label' : hloc, 'entryNum' : entryNum, 'owning_lib' : holdings.owning_lib() });
378                 dojo.require('openils.Event');
379                 dojo.require('openils.PermaCrud');
380                 var mfhd_edit = new dijit.Menu({});
381                 new dijit.MenuItem({onClick: function(){loadMarcEditor(holdings.sre_id())}, label:opac_strings.EDIT_MFHD_RECORD}).placeAt(mfhd_edit, "first");
382                 new dijit.MenuItem({onClick:function(){
383                         // Avoid accidental deletion of MFHD records
384                         if (!confirm(opac_strings.DELETE_MFHD_CONFIRM)) {
385                                 return;
386                         }
387                         var pcrud = new openils.PermaCrud({"authtoken": G.user.session});
388                         var mfhd_rec = pcrud.retrieve("sre", holdings.sre_id());
389                         if (mfhd_rec) {
390                                 pcrud.eliminate(mfhd_rec);
391                                 alert(dojo.string.substitute(opac_strings.DELETED_MFHD_RECORD, [holdings.sre_id()]));
392                         }
393                 }, label:opac_strings.DELETE_MFHD}).placeAt(mfhd_edit, "last");
394                 // new dijit.MenuItem({onClick:function(){alert("Edit properties " + holdings.sre_id());}, label:opac_strings.EDIT_PROPERTIES}).placeAt(mfhd_edit, "last");
395                 var mfhd_mb = new dijit.form.DropDownButton({dropDown: mfhd_edit, label:opac_strings.EDIT_MFHD_MENU, style:"float:right"});
396                 mfhd_mb.placeAt("mfhdHoldingsCaption" + entryNum, "last");
397                 mfhd_edit.startup();
398         }
399 }
400
401 function _holdingsDrawMFHDEntry(entryNum, entryName, entry) {
402         var flatEntry = entry.toString().replace(/,/g, ', ');
403         dojo.place("<tr><td> </td><td nowrap='nowrap' class='rdetail_desc'>" + entryName + "</td><td class='rdetail_item'>" + flatEntry + "</td></tr>", "rdetail_holdings_tbody_" + entryNum, "last");
404 }
405
406 function _rdetailDraw(r) {
407         record = r.getResultObject();
408
409         runEvt('rdetail', 'recordRetrieved', record.doc_id());
410
411         G.ui.rdetail.title.appendChild(text(record.title()));
412         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
413         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
414         G.ui.rdetail.edition.appendChild(text(record.edition()));
415         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
416         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
417         $('rdetail_physical_desc').appendChild(text(record.physical_description()));
418         r = record.types_of_resource();
419         if(r) {
420                 G.ui.rdetail.tor.appendChild(text(r[0]));
421                 setResourcePic( G.ui.rdetail.tor_pic, r[0]);
422         }
423         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
424
425         try{
426                 if(record.isbn()) {
427                         if(ENABLE_ADDED_CONTENT_ATTRIB_LINKS) {
428                                 unHideMe($('rdetail.jacket_attrib_div'));
429                                 var href = $('rdetail.jacket_attrib_link').getAttribute('href') +cleanISBN(record.isbn());
430                                 $('rdetail.jacket_attrib_link').setAttribute('href', href);
431                         }
432                         rdetailCheckForGBPreview();
433
434                 } else {
435                         hideMe($("rdetail.jacket_attrib_div"));
436                         hideMe($("rdetail_img_link"));
437                 }
438         } catch(E) {}
439
440
441         // see if the record has any external links 
442         var links = record.online_loc();
443         for( var i = 0; links && links.length > 0 && i < links.length; i = i + 3 ) {
444                 var href = links[i];
445                 // avoid matching "HTTP: The Complete Reference"
446                 if( href.match(/https?:\/|ftps?:\/|mailto:/i) ) {
447                         unHideMe($('rdetail_online_row'));
448                         // MODS can contain a display label (used for the text of the link)
449                         // as well as a note about the URL; many legacy systems conflate the
450                         // two and generate MARC records that expect the note to be used as
451                         // the text of the link, with no display label; here's the canonical
452                         // format:
453                         //
454                         // 856 40 $uhttp://localhost$yDisplay label$zPublic note
455                         //
456                         // Note that the MARC21slim2MODS XSL concatenates $3 and $y together
457                         // (as $y was defined later in MARC21's life as the display label)
458                         var displayLabel = '' + links[i+1];
459                         var note = '' + links[i+2];
460                         if(!displayLabel || displayLabel.match(/https?:\/|ftps?:\/|mailto:/i)) {
461                                 if(!note || note.match(/https?:\/|ftps?:\/|mailto:/i)) {
462                                         displayLabel = href;
463                                 } else {
464                                         displayLabel = note;
465                                 }
466                         }
467                         $('rdetail_online').appendChild(elem('a', {href:href,'class':'classic_link'}, displayLabel));
468                         if (note && note != displayLabel) {
469                                 $('rdetail_online').appendChild(elem('span', {'class':'url_note'}, ' - ' + note));
470                         }
471                         $('rdetail_online').appendChild(elem('br'));
472                 }
473         }
474
475         // Fill in our unAPI ID, if anyone cares
476         var abbrs = document.getElementsByTagName('abbr');
477         var span;
478         for (var i = 0; i < abbrs.length; i++) {
479                 if (abbrs[i].getAttribute('name') == 'unapi') {
480                         span = abbrs[i];
481                         break;
482                 }
483         }
484         buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
485
486         $('rdetail_place_hold').onclick = function() {
487         var src = location.href;
488
489         if(forceLoginSSL && src.match(/^http:/)) {
490
491             src = src.replace(/^http:/, 'https:');
492
493             if(!src.match(/&place_hold=1/)) {
494                 src += '&place_hold=1';
495             }
496
497             location.href = src;
498
499         } else {
500             holdsDrawEditor({record:record.doc_id(), type:'T'});
501         }
502     }
503
504
505         var RW = $('rdetail_exp_refworks');
506         if (RW && rdetailEnableRefWorks) {
507
508                 var here = (findOrgUnit(getLocation())).name();
509                 var org_name = here.replace(" ", "+");
510                 var cgi = new CGI();
511
512                 RW.setAttribute(
513                         'href',
514                         rdetailRefWorksHost + '/express/expressimport.asp?vendor='
515                         + org_name
516                         + '&filter=MARC+Format&database=All+MARC+Formats&encoding=65001&url=http%3A%2F%2F'
517                         + cgi.server_name + '/opac/extras/supercat/marctxt/record/'
518                         + record.doc_id()
519                );
520
521                 RW.setAttribute('target', 'RefWorksMain');
522
523                 unHideMe($('rdetail_exp_refworks_span'));
524         }
525
526         $('rdetail_img_link').setAttribute('href', buildISBNSrc(cleanISBN(record.isbn()), 'large'));
527         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
528         runEvt("rdetail", "recordDrawn");
529         recordsCache.push(record);
530
531         rdetailSetExtrasSelector();
532
533         var breq = new Request(FETCH_BRE, [getRid()]);
534         breq.callback( rdetailCheckDeleted );
535         breq.send();
536
537         //resultBuildCaches( [ record ] );
538         //resultDrawSubjects();
539         //resultDrawSeries();
540
541         // grab added content 
542
543     // Proxied through Evergreen AddedContent module
544         acCollectData(cleanISBN(record.isbn()), rdetailhandleAC);
545
546     var currentISBN = cleanISBN(record.isbn());
547
548     // Not proxied, cross-site javascript
549
550     // ChiliFresh
551     if (chilifresh && chilifresh != '(none)' && currentISBN) {
552         $('chilifreshReviewLink').setAttribute('id','isbn_'+currentISBN);
553         $('chilifreshReviewResult').setAttribute('id','chili_review_'+currentISBN);
554         unHideMe($('rdetail_reviews_link'));
555         unHideMe($('rdetail_chilifresh_reviews'));
556         try {
557             chili_init();
558         } catch(E) {
559             console.log(E + '\n');
560             hideMe($('rdetail_reviews_link'));
561             hideMe($('rdetail_chilifresh_reviews'));
562         }
563     }
564
565     // Novelist
566     if (novelist && currentISBN) {
567         unHideMe($('rdetail_novelist_link'));
568     }
569 }
570
571
572
573 function rdetailCheckDeleted(r) {
574         var br = r.getResultObject()[0];
575         if( isTrue(br.deleted()) ) {
576                 hideMe($('rdetail_place_hold'));
577                 $('rdetail_more_actions_selector').disabled = true;
578                 unHideMe($('rdetail_deleted_exp'));
579         }
580 }
581
582 function rdetailSetExtrasSelector() {
583         if(!grabUser()) return;
584         unHideMe($('rdetail_more_actions'));
585
586         var req = new Request( 
587                         FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
588         req.callback(rdetailAddBookbags);
589         req.send();
590 }
591
592 function rdetailAddBookbags(r) {
593
594         var containers = r.getResultObject();
595         var selector = $('rdetail_more_actions_selector');
596         var found = false;
597         var index = 3;
598         doSelectorActions(selector);
599
600         for( var i = 0; i < containers.length; i++ ) {
601                 found = true;
602                 var container = containers[i];
603                 insertSelectorVal( selector, index++, container.name(), 
604                                 "container_" + container.id(), rdetailAddToBookbag,  1 );
605         }
606
607         nextContainerIndex = index;
608 }
609
610 var _actions = {};
611 function rdetailNewBookbag() {
612         var name = prompt($('rdetail_bb_new').innerHTML,"");
613         if(!name) return;
614
615         var id;
616         if( id = containerCreate( name ) ) {
617                 alert($('rdetail_bb_success').innerHTML);
618                 var selector = $('rdetail_more_actions_selector');
619                 insertSelectorVal( selector, nextContainerIndex++, name, 
620                                 "container_" + id, rdetailAddToBookbag, 1 );
621                 setSelector( selector, 'start' );
622         }
623 }
624
625
626 function rdetailAddToBookbag() {
627         var selector = $('rdetail_more_actions_selector');
628         var id = selector.options[selector.selectedIndex].value;
629         setSelector( selector, 'start' );
630
631         if( containerCreateItem( id.substring(10), record.doc_id() )) {
632                 alert($('rdetail_bb_item_success').innerHTML);
633         }
634 }
635
636
637 var rdetailMarcFetched = false;
638 function rdetailShowExtra(type, args) {
639
640         hideMe($('rdetail_copy_info_div'));
641         hideMe($('rdetail_summary_div'));
642         hideMe($('rdetail_reviews_div'));
643         hideMe($('rdetail_toc_div'));
644         hideMe($('rdetail_anotes_div'));
645         hideMe($('rdetail_excerpt_div'));
646         hideMe($('rdetail_preview_div'));
647         hideMe($('rdetail_marc_div'));
648         hideMe($('cn_browse'));
649         hideMe($('rdetail_cn_browse_div'));
650         hideMe($('rdetail_novelist_div'));
651         hideMe($('rdetail_notes_div'));
652
653         removeCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
654         removeCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
655         removeCSSClass($('rdetail_summary_link'), 'rdetail_extras_selected');
656         removeCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
657         removeCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
658         removeCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
659         removeCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
660         removeCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
661         removeCSSClass($('rdetail_annotation_link'), 'rdetail_extras_selected');
662         removeCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
663         removeCSSClass($('rdetail_novelist_link'), 'rdetail_extras_selected');
664
665         switch(type) {
666
667                 case "copyinfo": 
668                         unHideMe($('rdetail_copy_info_div')); 
669                         addCSSClass($('rdetail_copy_info_link'), 'rdetail_extras_selected');
670                         break;
671
672         case "summary":
673             addCSSClass($('rdetail_summary_link'), 'rdetail_extras_selected');
674             unHideMe($('rdetail_summary_div'));
675             break;
676
677                 case "reviews": 
678                         addCSSClass($('rdetail_reviews_link'), 'rdetail_extras_selected');
679                         unHideMe($('rdetail_reviews_div')); 
680                         break;
681
682                 case "excerpt": 
683                         addCSSClass($('rdetail_excerpt_link'), 'rdetail_extras_selected');
684                         unHideMe($('rdetail_excerpt_div'));
685                         break;
686
687                 case "preview": 
688                         addCSSClass($('rdetail_preview_link'), 'rdetail_extras_selected');
689                         unHideMe($('rdetail_preview_div'));
690                         rdetailDisplayGBPreview();
691                         break;
692
693                 case "anotes": 
694                         addCSSClass($('rdetail_anotes_link'), 'rdetail_extras_selected');
695                         unHideMe($('rdetail_anotes_div'));
696                         break;
697
698                 case "toc": 
699                         addCSSClass($('rdetail_toc_link'), 'rdetail_extras_selected');
700                         unHideMe($('rdetail_toc_div'));
701                         break;
702
703                 case "marc": 
704                         addCSSClass($('rdetail_viewmarc_link'), 'rdetail_extras_selected');
705                         unHideMe($('rdetail_marc_div')); 
706                         if(rdetailMarcFetched) return;
707                         unHideMe($('rdetail_extras_loading'));
708                         rdetailMarcFetched = true;
709                         var req = new Request( FETCH_MARC_HTML, record.doc_id() );
710                         req.callback(rdetailViewMarc); 
711                         req.send();
712                         break;
713
714                 case "novelist": 
715                         addCSSClass($('rdetail_novelist_link'), 'rdetail_extras_selected');
716                         unHideMe($('rdetail_novelist_div')); 
717                         break;
718
719                 case 'cn':
720                         addCSSClass($('rdetail_viewcn_link'), 'rdetail_extras_selected');
721                         unHideMe($('rdetail_cn_browse_div'));
722                         rdetailShowCNBrowse(defaultCN, getLocation(), null, true);
723                         break;
724
725         }
726 }
727
728 function rdetailVolumeDetails(args) {
729         var row = $(args.rowid);
730         var tbody = row.parentNode;
731         cpdBuild( tbody, row, record, args.cn, args.org, args.depth, args.copy_location );
732         return;
733 }
734
735 function rdetailBuildCNList() {
736
737         var select = $('cn_browse_selector');
738         var index = 0;
739         var arr = [];
740         for( var cn in callnumberCache ) arr.push( cn );
741         arr.sort();
742
743         if( arr.length == 0 ) {
744                 hideMe($('rdetail_cn_browse_select_div'));
745                 return;
746         }
747
748         for( var i = 0; i < arr.length; i++ ) {
749                 var cn = arr[i];
750                 var opt = new Option(cn);
751                 select.options[index++] = opt;
752         }
753         select.onchange = rdetailGatherCN;
754 }
755
756 function rdetailGatherCN() {
757         var cn = getSelectorVal($('cn_browse_selector'));
758         rdetailShowCNBrowse( cn, getLocation(), getDepth(), true );
759         setSelector( $('cn_browse_selector'), cn );
760 }
761
762
763 function rdetailShowCNBrowse( cn, loc, depth, fromOnclick ) {
764
765         if(!cn) {
766                 unHideMe($('cn_browse_none'));
767                 hideMe($('rdetail_cn_browse_select_div'));
768                 return;
769         }
770
771         unHideMe($('rdetail_cn_browse_select_div'));
772         rdetailBuildCNList();
773         setSelector( $('cn_browse_selector'), cn );
774         hideMe($('rdetail_copy_info_div'));
775         hideMe($('rdetail_reviews_div'));
776         hideMe($('rdetail_summary_div'));
777         hideMe($('rdetail_toc_div'));
778         hideMe($('rdetail_marc_div'));
779         unHideMe($('rdetail_cn_browse_div'));
780         unHideMe($('cn_browse'));
781         if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
782         cnBrowseGo(cn, loc, depth);
783 }
784
785 function rdetailhandleAC(data) {
786
787         if( data.summary.html ) {
788                 $('rdetail_summary_div').innerHTML = data.summary.html;
789                 unHideMe($('rdetail_summary_link'));
790         }
791
792         if( data.reviews.html ) {
793                 $('rdetail_review_container').innerHTML = data.reviews.html;
794                 unHideMe($('rdetail_reviews_link'));
795         }
796
797         if( data.toc.html ) {
798                 $('rdetail_toc_div').innerHTML = data.toc.html;
799                 unHideMe($('rdetail_toc_link'));
800         }
801
802         if( data.excerpt.html ) {
803                 $('rdetail_excerpt_div').innerHTML = data.excerpt.html;
804                 unHideMe($('rdetail_excerpt_link'));
805         }
806
807         if( data.anotes.html ) {
808                 $('rdetail_anotes_div').innerHTML = data.anotes.html;
809                 unHideMe($('rdetail_anotes_link'));
810         }
811 }
812
813 function rdetailShowReviews(r) {
814         hideMe($('rdetail_extras_loading'));
815         var res = r.getResultObject();
816         var par = $('rdetail_reviews_div');
817         var template = par.removeChild($('rdetail_review_template'));
818         if( res && res.length > 0 ) {
819                 unHideMe($('rdetail_reviews_link'));
820                 for( var i = 0; i < res.length; i++ ) {
821                         var rev = res[i];       
822                         if( rev.text && rev.info ) {
823                                 var node = template.cloneNode(true);
824                                 $n(node, 'review_header').appendChild(text(rev.info));
825                                 $n(node, 'review_text').appendChild(text(rev.text));
826                                 par.appendChild(node);
827                         }
828                 }
829         }
830 }
831
832
833 function rdetailShowTOC(r) {
834         hideMe($('rdetail_extras_loading'));
835         var resp = r.getResultObject();
836         if(resp) {
837                 unHideMe($('rdetail_toc_link'));
838                 $('rdetail_toc_div').innerHTML = resp;
839         }
840 }
841
842 function rdetailBuildInfoRows() {
843         var req;
844         var method = FETCH_COPY_COUNTS_SUMMARY;
845         if (rdetailShowCopyLocation)
846                 method = FETCH_COPY_LOCATION_COUNTS_SUMMARY;
847
848         if( rdetailShowLocal ) 
849                 req = new Request(method, record.doc_id(), getLocation(), getDepth())
850         else
851                 req = new Request(method, record.doc_id());
852         req.callback(_rdetailBuildInfoRows);
853         req.send();
854 }
855
856 function _rdetailRows(node) {
857
858         if( rdetailShowLocal && getLocation() != globalOrgTree.id() ) {
859                 var loc = findOrgUnit(getLocation());
860                 if( node ) {
861                         if( !orgIsMine(node, loc) && !orgIsMine(loc,node) ) return;
862                 } else {
863             var kids = globalOrgTree.children();
864             if (kids) {
865                         for( var i = 0; i < kids.length; i++ ) {
866                                 var org = findOrgUnit(kids[i]);
867                                 if( orgIsMine(org, loc) ) {
868                                         node = org;
869                                         break;
870                                 }
871                 }
872                         }
873                 } 
874         }
875
876         if(!node && findOrgType(globalOrgTree.ou_type()).can_have_vols())
877                 node = globalOrgTree;
878
879
880         /* don't show hidden orgs */
881
882         if(node) {
883
884                 if(!isXUL() && !isTrue(node.opac_visible())) return;
885
886                 if (orgHiding) {
887                         if (isTrue( findOrgType(node.ou_type()).can_have_vols() )) {
888                                 if ( ! orgIsMine( orgHiding.org, node, orgHiding.depth ) ) {
889                                         return;
890                                 }
891                         }
892                 }
893
894                 var row = copyRow.cloneNode(true);
895                 row.id = "cp_info_" + node.id();
896
897                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
898                 var cntd  = findNodeByName( row, config.names.rdetail.cn_cell );
899                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
900                 var actions = $n(row, 'rdetail_actions_cell');
901
902                 var p = libtd.getElementsByTagName('a')[0];
903                 libtd.insertBefore(text(node.name()), p);
904                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
905
906                 if(!findOrgType(node.ou_type()).can_have_vols()) {
907
908                         row.removeChild(cntd);
909                         row.removeChild(cpctd);
910                         row.removeChild(actions);
911                         row.setAttribute('novols', '1');
912
913                         libtd.setAttribute("colspan", numStatuses + 3 );
914                         libtd.colSpan = numStatuses + 3;
915                         addCSSClass(row, 'copy_info_region_row');
916                 } 
917
918                 copyRowParent.appendChild(row);
919
920         } else { node = globalOrgTree; }
921
922     var kids = node.children();
923     if (kids) {
924         for( var c = 0; c < kids.length; c++ ) 
925                 _rdetailRows(kids[c]);
926     }
927 }
928
929 function rdetailCNPrint(orgid, cn) {
930         var div = cpdBuildPrintWindow( record, orgid);
931         var template = div.removeChild($n(div, 'cnrow'));
932         var rowNode = $("cp_info_" + orgid);
933         cpdStylePopupWindow(div);
934         openWindow(div.innerHTML);
935 }
936
937 var localCNFound = false;
938 var ctr = 0;
939 function _rdetailBuildInfoRows(r) {
940
941         if (rdetailShowCopyLocation)
942                 unHideMe( $n( $('rdetail_copy_info_table'), 'rdetail_copylocation_header' ) );
943
944         removeChildren(copyRowParent);
945
946         orgHiding = checkOrgHiding();
947
948         _rdetailRows();
949
950         var summary = r.getResultObject();
951         if(!summary) return;
952
953         var found = false;
954         for( var i = 0; i < summary.length; i++ ) {
955
956                 var arr = summary[i];
957                 globalCNCache[arr[1]] = 1;
958                 var thisOrg = findOrgUnit(arr[0]);
959                 var rowNode = $("cp_info_" + thisOrg.id());
960                 if(!rowNode) continue;
961
962                 if(rowNode.getAttribute("used")) {
963
964                         if( rowNode.nextSibling ) {
965                                 sib = rowNode.nextSibling;
966                                 o ='cp_info_'+thisOrg.id()+'_';
967                                 /* push the new row on as the last row for this org unit */
968                                 while( sib && sib.id.match(o) ) {
969                                         sib = sib.nextSibling;
970                                 }
971                                 if(sib)
972                                         rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), sib);
973                                 else
974                                         rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
975                         } else {
976                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
977                         }
978
979                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
980                         n.appendChild(text(thisOrg.name()));
981                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
982                         rowNode.id = "cp_info_" + thisOrg.id() + '_' + (++ctr); 
983
984                 } else {
985                         rowNode.setAttribute("used", "1");
986                 }
987
988                 var cpc_temp = rowNode.removeChild(
989                                 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
990
991                 var statuses = arr[2];
992                 var cl = '';
993                 if (rdetailShowCopyLocation) {
994                         cl = arr[2];
995                         statuses = arr[3];
996                 }
997
998
999                 rdetailApplyStatuses(rowNode, cpc_temp, statuses);
1000
1001                 var isLocal = false;
1002                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { 
1003                         found = true; 
1004                         isLocal = true; 
1005                         if(!localCNFound) {
1006                                 localCNFound = true;
1007                                 defaultCN = arr[1];
1008                         }
1009                 }
1010
1011                 //if(isLocal) unHideMe(rowNode);
1012                 unHideMe(rowNode);
1013
1014                 rdetailSetPath( thisOrg, isLocal );
1015                 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal, thisOrg, cl );
1016
1017                 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
1018         }
1019
1020         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
1021 }
1022
1023 function rdetailBuildBrowseInfo(row, cn, local, orgNode, cl) {
1024
1025         if(local) {
1026                 var cache = callnumberCache[cn];
1027                 if( cache ) cache.count++;
1028                 else callnumberCache[cn] = { count : 1 };
1029         }
1030
1031         var depth = getDepth();
1032         if( !local ) depth = findOrgDepth(globalOrgTree);
1033
1034         $n(row, 'rdetail_callnumber_cell').appendChild(text(cn));
1035
1036         if (rdetailShowCopyLocation) {
1037                 var cl_cell = $n(row, 'rdetail_copylocation_cell');
1038                 cl_cell.appendChild(text(cl));
1039                 unHideMe(cl_cell);
1040         }
1041
1042         _debug('setting action clicks for cn ' + cn);
1043
1044         var dHref = 'javascript:rdetailVolumeDetails('+
1045                         '{copy_location : "'+cl.replace(/\"/g, '\\"')+'", rowid : "'+row.id+'", cn :"'+cn.replace(/\"/g, '\\"')+'", depth:"'+depth+'", org:"'+orgNode.id()+'", local: '+local+'});';
1046
1047         var bHref = 'javascript:rdetailShowCNBrowse("' + cn.replace(/\"/g, '\\"') + '", '+orgNode.id()+', "'+depth+'");'; 
1048
1049         unHideMe( $n(row, 'details') )
1050                 $n(row, 'details').setAttribute('href', dHref);
1051         unHideMe( $n(row, 'browse') )
1052                 $n(row, 'browse').setAttribute('href', bHref);
1053
1054         if(isXUL()) {
1055                 unHideMe($n(row, 'hold_div'));
1056                 $n(row, 'hold').onclick = function() {
1057                         var req = new Request(FETCH_VOLUME_BY_INFO, cn, record.doc_id(), orgNode.id());
1058                         req.callback(
1059                                         function(r) {
1060                                         var vol = r.getResultObject();
1061                                         holdsDrawEditor({type: 'V', volumeObject : vol});
1062                                         }
1063                                     );
1064                         req.send();
1065                 };
1066         }
1067 }
1068
1069 // sets the path to org as 'active' and displays the path if it's local 
1070 function rdetailSetPath(org, local) {
1071         if( findOrgDepth(org) == 0 ) return;
1072         var row = $("cp_info_" + org.id());
1073         row.setAttribute("hasinfo", "1");
1074         unHideMe(row);
1075         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
1076 }
1077
1078 //Append all the statuses for a given summary to the 
1079 //copy summary table 
1080 function rdetailApplyStatuses( row, template, statuses ) {
1081         for( var j in _statusPositions ) {
1082                 var stat = _statusPositions[j];
1083                 var val = statuses[stat.id()];
1084                 var nn = template.cloneNode(true);
1085                 if(val) nn.appendChild(text(val));
1086                 else nn.appendChild(text(0));
1087                 row.appendChild(nn);
1088         }
1089 }
1090
1091 //Add one td (creating a new column) to the copy summary
1092 //table for each opac_visible copy status
1093 function rdetailBuildStatusColumns() {
1094
1095         rdetailGrabCopyStatuses();
1096         var parent = statusRow;
1097         var template = parent.removeChild(G.ui.rdetail.cp_status);
1098
1099         var i = 0;
1100         for( i = 0; i < cp_statuses.length; i++ ) {
1101
1102                 var c = cp_statuses[i];
1103                 if( c && isTrue(c.opac_visible()) ) {
1104                         var name = c.name();
1105                         _statusPositions[i] = c;
1106                         var node = template.cloneNode(true);
1107                         var data = findNodeByName( node, config.names.rdetail.cp_status);
1108
1109                         data.appendChild(text(name));
1110                         parent.appendChild(node);
1111                 }
1112         }       
1113
1114         numStatuses = 0;
1115         for(x in _statusPositions) numStatuses++; 
1116 }
1117
1118 function rdetailGrabCopyStatuses() {
1119         if(cp_statuses) return cp_statuses;
1120         var req = new Request(FETCH_COPY_STATUSES);
1121         req.send(true);
1122         cp_statuses = req.result();
1123         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
1124 }
1125
1126 function _rdetailSortStatuses(a, b) {
1127         return parseInt(a.id()) - parseInt(b.id());
1128 }
1129
1130 /**
1131  * Check for a Google Book preview after the main page loads
1132  */
1133 function rdetailCheckForGBPreview() {
1134         if (!rdetailGoogleBookPreview) return;
1135         dojo.addOnLoad(function() {
1136                 searchForGBPreview( cleanISBN(record.isbn()) );
1137         });
1138 }
1139
1140 /**
1141  *
1142  * @param {DOM object} isbn The form element containing the input parameters "isbns"
1143  */
1144 function searchForGBPreview( isbn ) {
1145         dojo.require("dojo.io.script");
1146         dojo.io.script.get({"url": "https://www.google.com/jsapi"});
1147         dojo.io.script.get({"url": "http://books.google.com/books", "content": { "bibkeys": isbn, "jscmd": "viewapi", "callback": "GBPreviewCallback"}});
1148 }
1149
1150 /**
1151  * This function is the call-back function for the JSON scripts which 
1152  * executes a Google book search response.
1153  *
1154  * XXX I18N of text needed
1155  *
1156  * @param {JSON} GBPBookInfo is the JSON object pulled from the Google books service.
1157  */
1158 function GBPreviewCallback(GBPBookInfo) {
1159         var GBPreviewDiv = document.getElementById("rdetail_preview_div");
1160         var GBPBook;
1161
1162         for ( i in GBPBookInfo ) {
1163                 GBPBook = GBPBookInfo[i];
1164         }
1165
1166         if ( !GBPBook ) {
1167                 return;
1168         }
1169
1170         if ( GBPBook.preview != "noview" ) {
1171                 // Add a button below the book cover image to load the preview.
1172                 GBPBadge = document.createElement( 'img' );
1173                 GBPBadge.src = 'http://books.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif';
1174                 GBPBadge.title = $('rdetail_preview_badge').innerHTML;
1175                 GBPBadge.style.border = 0;
1176                 GBPBadgelink = document.createElement( 'a' );
1177                 GBPBadgelink.href = 'javascript:rdetailShowExtra("preview");';
1178                 GBPBadgelink.appendChild( GBPBadge );
1179                 $('rdetail_image_cell').appendChild( GBPBadgelink );
1180                 $('rdetail_preview_div').style.height = 600;
1181
1182                 /* Display the "Preview" tab in the Extras section */
1183                 unHideMe( $('rdetail_preview_link' ) );
1184         }
1185 }
1186
1187 /**
1188  *  This is called when the user clicks on the 'Preview' link.  We assume
1189  *  a preview is available from Google if this link was made visible.
1190  *
1191  * XXX I18N of Google Book Preview language attribute needed
1192  */
1193 function rdetailDisplayGBPreview() {
1194         unHideMe($('rdetail_extras_loading'));
1195         GBPreviewPane = $('rdetail_preview_div');
1196         if ( GBPreviewPane.getAttribute('loaded') == null ||
1197                 GBPreviewPane.getAttribute('loaded') == "false" ) {
1198                 google.load("books", "0", {"callback" : rdetailGBPViewerLoadCallback, "language": "en"} );
1199                 GBPreviewPane.setAttribute('loaded', 'true');
1200         }
1201 }
1202
1203 function rdetailGBPViewerLoadCallback() {
1204         hideMe($('rdetail_extras_loading'));
1205         var GBPViewer = new google.books.DefaultViewer(document.getElementById('rdetail_preview_div'));
1206         GBPViewer.load('ISBN:' + cleanISBN(record.isbn()) );
1207
1208 }
1209
1210 function rdetailDrawExpandedHoldings(anchor, bibid, type) {
1211     var offsets = {"basic": 0, "index": 0, "supplement": 0};
1212     var limit = 10; /* XXX give user control over this? */
1213     var target_id = "holding_type_" + type;
1214     var target = dojo.byId(target_id);
1215
1216     anchor.innerHTML = "[-]";
1217     anchor.oldonclick = anchor.onclick;
1218     anchor.onclick = function() {
1219         anchor.onclick = anchor.oldonclick;
1220         anchor.innerHTML = "[+]";
1221         dojo.empty(target);
1222     };
1223
1224     function _load() {
1225         dojo.empty(target);
1226         fieldmapper.standardRequest(
1227             ["open-ils.serial",
1228                 "open-ils.serial.received_siss.retrieve.by_bib.atomic"], {
1229                 "params": [bibid, {"offset": offsets[type], "limit": limit}],
1230                 "async": true,
1231                 "oncomplete": function(r) {
1232                     try {
1233                         if (msg = r.recv().content()) { /* sic, assignment */
1234                             offsets[type] += msg.length;
1235                             dojo.forEach(
1236                                 msg, function(o) {
1237                                     dojo.create("br", null, target);
1238                                     dojo.create(
1239                                         "span", {
1240                                             "innerHTML": o.issuance.label(),
1241                                             "style": {"padding": "0 2em"}
1242                                         }, target
1243                                     );
1244
1245                                     if (!o.has_units) return;
1246                                     /* can't place holds if no units */
1247                                     dojo.create(
1248                                         "a", {
1249                                             "href":"javascript:void(0);",
1250                                             "onclick": function() {
1251                                                 holdsDrawEditor({
1252                                                     "type": "I",
1253                                                     "issuance": o.issuance.id()
1254                                                 });
1255                                             },
1256                                             "innerHTML": "[" +
1257                                                 opac_strings.PLACE_HOLD + "]"
1258                                         }, target
1259                                     );
1260                                 }
1261                             );
1262                             if (msg.length == limit) {
1263                                 dojo.create("br", null, target);
1264                                 dojo.create(
1265                                     "a", {
1266                                         "href": "javascript:void(0);",
1267                                         "innerHTML":
1268                                             "[" + opac_strings.MORE + "]",
1269                                         "onclick": _load
1270                                     }, target
1271                                 );
1272                             }
1273                         }
1274                     } catch (E) {
1275                         void(0);
1276                     }
1277                 }
1278             }
1279         );
1280     }
1281     _load();
1282 }