1 var docid; var marc_html; var top_pane; var bottom_pane; var opac_frame; var opac_url;
3 var marc_view_reset = true;
4 var marc_edit_reset = true;
5 var copy_browser_reset = true;
6 var hold_browser_reset = true;
8 function $(id) { return document.getElementById(id); }
12 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
13 if (typeof JSAN == 'undefined') { throw(document.getElementById('offlineStrings').getString('common.jsan.missing')); }
14 JSAN.errorLevel = "die"; // none, warn, or die
15 JSAN.addRepository('..');
16 JSAN.use('util.error'); g.error = new util.error();
17 g.error.sdump('D_TRACE','my_init() for cat/opac.xul');
19 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
20 XML_HTTP_SERVER = g.data.server_unadorned;
22 // Pull in local customizations
23 var r = new XMLHttpRequest();
24 r.open("GET", xulG.url_prefix('/xul/server/skin/custom.js'), false);
26 if (r.status == 200) {
27 dump('Evaluating /xul/server/skin/custom.js\n');
28 eval( r.responseText );
31 window.help_context_set_locally = true;
33 JSAN.use('util.network'); g.network = new util.network();
36 try { authtime = g.cgi.param('authtime') || xulG.authtime; } catch(E) { g.error.sdump('D_ERROR',E); }
37 try { docid = g.cgi.param('docid') || xulG.docid; } catch(E) { g.error.sdump('D_ERROR',E); }
38 try { opac_url = g.cgi.param('opac_url') || xulG.opac_url; } catch(E) { g.error.sdump('D_ERROR',E); }
39 try { g.view_override = g.cgi.param('default_view') || xulG.default_view; } catch(E) { g.error.sdump('D_ERROR',E); }
41 JSAN.use('util.deck');
42 top_pane = new util.deck('top_pane');
43 bottom_pane = new util.deck('bottom_pane');
48 var err_msg = document.getElementById("offlineStrings").getFormattedString("common.exception", ["cat/opac.xul", E]);
49 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
54 function default_focus() {
55 opac_wrapper_set_help_context();
58 function opac_wrapper_set_help_context() {
60 dump('Entering opac.js, opac_wrapper_set_help_context\n');
61 var cw = bottom_pane.get_contentWindow();
62 if (cw && typeof cw['location'] != 'undefined') {
63 if (typeof cw.help_context_set_locally == 'undefined') {
65 'protocol' : cw.location.protocol,
66 'hostname' : cw.location.hostname,
67 'port' : cw.location.port,
68 'pathname' : cw.location.pathname,
71 xulG.set_help_context(help_params);
73 dump('\tcw.help_context_set_locally = ' + cw.help_context_set_locally + '\n');
74 if (typeof cw.default_focus == 'function') {
79 dump('opac.js: problem in opac_wrapper_set_help_context(): bottom_pane = ' + bottom_pane + ' cw = ' + cw + '\n');
80 dump('\tcw.location = ' + cw.location + '\n');
83 // We can expect some errors here if this called before the DOM is ready. Easiest to just trap and ignore
84 dump('Error in opac.js, opac_wrapper_set_help_context(): ' + E + '\n');
88 function set_brief_view() {
89 var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
90 dump('spawning ' + url + '\n');
95 'set_tab_name' : function(n) {
96 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
97 try { window.xulG.set_tab_name(document.getElementById('offlineStrings').getFormattedString("cat.bib_record", [n])); } catch(E) { alert(E); }
99 dump('no set_tab_name\n');
106 function set_marc_view() {
107 g.view = 'marc_view';
108 if (marc_view_reset) {
109 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
110 marc_view_reset = false;
112 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
114 opac_wrapper_set_help_context();
115 bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
118 function set_marc_edit() {
119 g.view = 'marc_edit';
120 var a = xulG.url_prefix( urls.XUL_MARC_EDIT );
123 'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid },
124 'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
126 var cat = { util: {} }; /* FIXME: kludge since we can't load remote JSAN libraries into chrome */
127 cat.util.spawn_copy_editor = function(params) {
129 if (!params.copy_ids && !params.copies) return;
130 if (params.copy_ids && params.copy_ids.length == 0) return;
131 if (params.copies && params.copies.length == 0) return;
132 if (params.copy_ids) params.copy_ids = js2JSON(params.copy_ids); // legacy
133 if (!params.caller_handles_update) params.handle_update = 1; // legacy
136 JSAN.use('util.network'); obj.network = new util.network();
137 JSAN.use('util.error'); obj.error = new util.error();
140 if (params.copy_ids && params.copy_ids.length > 1 && params.edit == 1)
141 title = $("offlineStrings").getString('staff.cat.util.copy_editor.batch_edit');
142 else if(params.copies && params.copies.length > 1 && params.edit == 1)
143 title = $("offlineStrings").getString('staff.cat.util.copy_editor.batch_view');
144 else if(params.copy_ids && params.copy_ids.length == 1)
145 title = $("offlineStrings").getString('staff.cat.util.copy_editor.edit');
147 title = $("offlineStrings").getString('staff.cat.util.copy_editor.view');
149 JSAN.use('util.window'); var win = new util.window();
150 var my_xulG = win.open(
151 (urls.XUL_COPY_EDITOR),
153 'chrome,modal,resizable',
156 if (!my_xulG.copies && params.edit) {
158 return my_xulG.copies;
162 JSAN.use('util.error'); var error = new util.error();
163 error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.spawn_copy_editor',E);
166 cat.util.fast_item_add = function(doc_id,cn_label,cp_barcode) {
170 JSAN.use('util.error'); error = new util.error();
171 JSAN.use('util.network'); var network = new util.network();
173 var acn_id = network.simple_request(
174 'FM_ACN_FIND_OR_CREATE',
175 [ ses(), cn_label, doc_id, ses('ws_ou') ]
178 if (typeof acn_id.ilsevent != 'undefined') {
179 error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.fast_item_add', acn_id);
183 var copy_obj = new acp();
186 copy_obj.barcode( cp_barcode );
187 copy_obj.call_number( acn_id );
188 copy_obj.circ_lib( ses('ws_ou') );
189 /* FIXME -- use constants */
192 copy_obj.deposit_amount(0);
193 copy_obj.fine_level(2);
194 copy_obj.loan_duration(2);
195 copy_obj.location(1);
197 copy_obj.circulate(get_db_true());
198 copy_obj.holdable(get_db_true());
199 copy_obj.opac_visible(get_db_true());
200 copy_obj.ref(get_db_false());
202 JSAN.use('util.window'); var win = new util.window();
203 return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
206 if (error) error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.fast_item_add #2',E); else alert('FIXME: ' + E);
209 return cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
211 alert('Error in chrome/content/cat/opac.js, set_marc_edit, fast_item_add: ' + E);
215 'label' : document.getElementById('offlineStrings').getString('cat.save_record'),
216 'func' : function (new_marcxml) {
218 var r = g.network.simple_request('MARC_XML_RECORD_UPDATE', [ ses(), docid, new_marcxml ]);
219 marc_view_reset = true;
220 copy_browser_reset = true;
221 hold_browser_reset = true;
222 if (typeof r.ilsevent != 'undefined') {
227 'oncomplete' : function() {}
231 g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString("cat.save.failure"), E);
236 if (marc_edit_reset) {
237 bottom_pane.reset_iframe( a,b,c );
238 marc_edit_reset = false;
240 bottom_pane.set_iframe( a,b,c );
242 opac_wrapper_set_help_context();
243 bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
246 function set_copy_browser() {
247 g.view = 'copy_browser';
248 if (copy_browser_reset) {
249 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
250 copy_browser_reset =false;
252 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
254 opac_wrapper_set_help_context();
255 bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
258 function set_hold_browser() {
259 g.view = 'hold_browser';
260 if (hold_browser_reset) {
261 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
262 hold_browser_reset = false;
264 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
266 opac_wrapper_set_help_context();
267 bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
270 function set_opac() {
273 var content_params = {
274 'show_nav_buttons' : true,
275 'show_print_button' : true,
276 'passthru_content_params' : {
278 'authtime' : ses('authtime'),
279 'window_open' : function(a,b,c) {
281 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
282 return window.open(a,b,c);
284 g.error.standard_unexpected_error_alert('window_open',E);
288 'on_url_load' : function(f) {
289 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
292 if (typeof f.contentWindow.wrappedJSObject.attachEvt != 'undefined') {
293 win = f.contentWindow.wrappedJSObject;
295 win = f.contentWindow;
298 win = f.contentWindow;
300 win.attachEvt("rdetail", "recordRetrieved",
303 if (docid == id) return;
307 g.error.standard_unexpected_error_alert('rdetail -> recordRetrieved',E);
312 g.f_record_start = null; g.f_record_prev = null; g.f_record_next = null; g.f_record_end = null;
313 $('record_start').disabled = true; $('record_next').disabled = true;
314 $('record_prev').disabled = true; $('record_end').disabled = true;
315 $('record_pos').setAttribute('value','');
317 win.attachEvt("rdetail", "nextPrevDrawn",
318 function(rIndex,rCount){
319 $('record_pos').setAttribute('value', document.getElementById('offlineStrings').getFormattedString('cat.record.counter', [(1+rIndex), rCount ? rCount : 1]));
320 if (win.rdetailNext) {
321 g.f_record_next = function() {
322 g.view_override = g.view;
325 $('record_next').disabled = false;
327 if (win.rdetailPrev) {
328 g.f_record_prev = function() {
329 g.view_override = g.view;
332 $('record_prev').disabled = false;
334 if (win.rdetailStart) {
335 g.f_record_start = function() {
336 g.view_override = g.view;
339 $('record_start').disabled = false;
341 if (win.rdetailEnd) {
342 g.f_record_end = function() {
343 g.view_override = g.view;
346 $('record_end').disabled = false;
351 'url_prefix' : xulG.url_prefix,
353 content_params.new_tab = xulG.new_tab;
354 content_params.set_tab = xulG.set_tab;
355 content_params.close_tab = xulG.close_tab;
356 content_params.new_patron_tab = xulG.new_patron_tab;
357 content_params.set_patron_tab = xulG.set_patron_tab;
358 content_params.volume_item_creator = xulG.volume_item_creator;
359 content_params.get_new_session = xulG.get_new_session;
360 content_params.holdings_maintenance_tab = xulG.holdings_maintenance_tab;
361 content_params.set_tab_name = xulG.set_tab_name;
362 content_params.open_chrome_window = xulG.open_chrome_window;
363 content_params.url_prefix = xulG.url_prefix;
364 content_params.network_meter = xulG.network_meter;
365 content_params.page_meter = xulG.page_meter;
366 content_params.set_statusbar = xulG.set_statusbar;
367 content_params.set_help_context = xulG.set_help_context;
369 if (opac_url) { content_params.url = opac_url; } else { content_params.url = xulG.url_prefix( urls.browser ); }
370 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_BROWSER) + '?name=Catalog', {}, content_params);
371 /* // Remember to use the REMOTE_BROWSER if we ever try to move this to remote xul again
372 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_REMOTE_BROWSER) + '?name=Catalog', {}, content_params);
375 g.error.sdump('D_ERROR','set_opac: ' + E);
377 opac_wrapper_set_help_context();
378 bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
381 function bib_in_new_tab() {
383 var url = browser_frame.contentWindow.g.browser.controller.view.browser_browser.contentWindow.wrappedJSObject.location.href;
384 var content_params = { 'session' : ses(), 'authtime' : ses('authtime'), 'opac_url' : url };
385 content_params.url_prefix = xulG.url_prefix;
386 content_params.new_tab = xulG.new_tab;
387 content_params.set_tab = xulG.set_tab;
388 content_params.close_tab = xulG.close_tab;
389 content_params.new_patron_tab = xulG.new_patron_tab;
390 content_params.set_patron_tab = xulG.set_patron_tab;
391 content_params.volume_item_creator = xulG.volume_item_creator;
392 content_params.get_new_session = xulG.get_new_session;
393 content_params.holdings_maintenance_tab = xulG.holdings_maintenance_tab;
394 content_params.set_tab_name = xulG.set_tab_name;
395 content_params.open_chrome_window = xulG.open_chrome_window;
396 content_params.url_prefix = xulG.url_prefix;
397 content_params.network_meter = xulG.network_meter;
398 content_params.page_meter = xulG.page_meter;
399 content_params.set_statusbar = xulG.set_statusbar;
400 content_params.set_help_context = xulG.set_help_context;
402 xulG.new_tab(xulG.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
404 g.error.sdump('D_ERROR',E);
408 function remove_me() {
409 var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
410 dump('removing ' + url + '\n');
411 try { top_pane.remove_iframe( url ); } catch(E) { dump(E + '\n'); }
412 $('nav').setAttribute('hidden','true');
415 function add_to_bucket() {
416 JSAN.use('util.window'); var win = new util.window();
418 xulG.url_prefix(urls.XUL_RECORD_BUCKETS_QUICK),
419 'sel_bucket_win' + win.window_name_increment(),
420 'chrome,resizable,modal,center',
422 record_ids: [ docid ]
427 function mark_for_overlay() {
428 g.data.marked_record = docid;
429 g.data.stash('marked_record');
430 var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
431 if (typeof robj.ilsevent == 'undefined') {
432 g.data.marked_record_mvr = robj;
434 g.data.marked_record_mvr = null;
435 g.error.standard_unexpected_error_alert('in mark_for_overlay',robj);
437 g.data.stash('marked_record_mvr');
438 if (g.data.marked_record_mvr) {
439 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.tcn.alert',[ g.data.marked_record_mvr.tcn() ]));
440 xulG.set_statusbar(1, $("offlineStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.tcn.label',[g.data.marked_record_mvr.tcn()]) );
442 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.record_id.alert',[ g.data.marked_record ]));
443 xulG.set_statusbar(1, $("offlineStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.record_id.label',[g.data.marked_record]) );
447 function mark_for_hold_transfer() {
448 g.data.marked_record_for_hold_transfer = docid;
449 g.data.stash('marked_record_for_hold_transfer');
450 var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
451 if (typeof robj.ilsevent == 'undefined') {
452 g.data.marked_record_for_hold_transfer_mvr = robj;
454 g.data.marked_record_for_hold_transfer_mvr = null;
455 g.error.standard_unexpected_error_alert('in mark_for_hold_transfer',robj);
457 g.data.stash('marked_record_for_hold_transfer_mvr');
458 if (g.data.marked_record_mvr) {
459 var m = $("offlineStrings").getFormattedString('staff.cat.opac.marked_record_for_hold_transfer_indicator.tcn.label',[g.data.marked_record_for_hold_transfer_mvr.tcn()]);
460 alert(m); xulG.set_statusbar(1, m );
462 var m = $("offlineStrings").getFormattedString('staff.cat.opac.marked_record_for_hold_transfer_indicator.record_id.label',[g.data.marked_record_for_hold_transfer]);
463 alert(m); xulG.set_statusbar(1, m );
467 function transfer_title_holds() {
468 g.data.stash_retrieve();
469 var target = g.data.marked_record_for_hold_transfer;
471 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.destination_needed.label');
475 var robj = g.network.simple_request('TRANSFER_TITLE_HOLDS',[ ses(), target, [ docid ] ]);
477 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.success.label');
480 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.failure.label');
483 hold_browser_reset = true;
484 if (g.view == 'hold_browser') { set_hold_browser(); };
487 function delete_record() {
488 if (g.error.yns_alert(
489 document.getElementById('offlineStrings').getFormattedString('cat.opac.delete_record.confirm', [docid]),
490 document.getElementById('offlineStrings').getString('cat.opac.delete_record'),
491 document.getElementById('offlineStrings').getString('cat.opac.delete'),
492 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
494 document.getElementById('offlineStrings').getString('cat.opac.record_deleted.confirm')) == 0) {
495 var robj = g.network.simple_request('FM_BRE_DELETE',[ses(),docid]);
496 if (typeof robj.ilsevent != 'undefined') {
497 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error', [docid, robj.textcode, robj.desc]) + '\n');
499 alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
500 refresh_display(docid);
505 function undelete_record() {
506 if (g.error.yns_alert(
507 document.getElementById('offlineStrings').getFormattedString('cat.opac.undelete_record.confirm', [docid]),
508 document.getElementById('offlineStrings').getString('cat.opac.undelete_record'),
509 document.getElementById('offlineStrings').getString('cat.opac.undelete'),
510 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
512 document.getElementById('offlineStrings').getString('cat.opac.record_undeleted.confirm')) == 0) {
514 var robj = g.network.simple_request('FM_BRE_UNDELETE',[ses(),docid]);
515 if (typeof robj.ilsevent != 'undefined') {
516 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_undeleted.error', [docid, robj.textcode, robj.desc]) + '\n');
518 alert(document.getElementById('offlineStrings').getString('cat.opac.record_undeleted'));
519 refresh_display(docid);
524 function refresh_display(id) {
526 marc_view_reset = true;
527 marc_edit_reset = true;
528 copy_browser_reset = true;
529 hold_browser_reset = true;
530 while(top_pane.node.lastChild) top_pane.node.removeChild( top_pane.node.lastChild );
531 var children = bottom_pane.node.childNodes;
532 for (var i = 0; i < children.length; i++) {
533 if (children[i] != browser_frame) bottom_pane.node.removeChild(children[i]);
537 $('nav').setAttribute('hidden','false');
538 var settings = g.network.simple_request(
540 [ ses(), g.data.list.au[0].id() ]
542 var view = settings['staff_client.catalog.record_view.default'];
543 if (g.view_override) {
544 view = g.view_override;
545 g.view_override = null;
548 case 'marc_view' : set_marc_view(); break;
549 case 'marc_edit' : set_marc_edit(); break;
550 case 'copy_browser' : set_copy_browser(); break;
551 case 'hold_browser' : set_hold_browser(); break;
553 default: set_opac(); break;
555 opac_wrapper_set_help_context();
557 g.error.standard_unexpected_error_alert('in refresh_display',E);
561 function set_default() {
562 var robj = g.network.simple_request(
564 [ ses(), g.data.list.au[0].id(), { 'staff_client.catalog.record_view.default' : g.view } ]
566 if (typeof robj.ilsevent != 'undefined') {
567 if (robj.ilsevent != 0) g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString('cat.preference.error'), robj);
571 function add_volumes() {
575 edit = g.network.request(
576 api.PERM_MULTI_ORG_CHECK.app,
577 api.PERM_MULTI_ORG_CHECK.method,
582 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
584 ).length == 0 ? 1 : 0;
586 g.error.sdump('D_ERROR','batch permission check: ' + E);
590 alert(document.getElementById('offlineStrings').getString('staff.circ.copy_status.add_volumes.perm_failure'));
591 return; // no read-only view for this interface
594 var title = document.getElementById('offlineStrings').getFormattedString('staff.circ.copy_status.add_volumes.title', [docid]);
596 JSAN.use('util.window'); var win = new util.window();
598 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
601 { 'doc_id' : docid, 'ou_ids' : [ ses('ws_ou') ] }
604 alert('Error in chrome/content/cat/opac.js, add_volumes(): ' + E);