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