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 JSAN.use('util.network'); g.network = new util.network();
25 try { authtime = g.cgi.param('authtime') || xulG.authtime; } catch(E) { g.error.sdump('D_ERROR',E); }
26 try { docid = g.cgi.param('docid') || xulG.docid; } catch(E) { g.error.sdump('D_ERROR',E); }
27 try { opac_url = g.cgi.param('opac_url') || xulG.opac_url; } catch(E) { g.error.sdump('D_ERROR',E); }
28 try { g.view_override = g.cgi.param('default_view') || xulG.default_view; } catch(E) { g.error.sdump('D_ERROR',E); }
30 JSAN.use('util.deck');
31 top_pane = new util.deck('top_pane');
32 bottom_pane = new util.deck('bottom_pane');
37 var err_msg = document.getElementById("offlineStrings").getFormattedString("common.exception", ["cat/opac.xul", E]);
38 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
43 function set_brief_view() {
44 var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
45 dump('spawning ' + url + '\n');
50 'set_tab_name' : function(n) {
51 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
52 try { window.xulG.set_tab_name(document.getElementById('offlineStrings').getFormattedString("cat.bib_record", [n])); } catch(E) { alert(E); }
54 dump('no set_tab_name\n');
61 function set_marc_view() {
63 if (marc_view_reset) {
64 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
65 marc_view_reset = false;
67 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
71 function set_marc_edit() {
73 var a = xulG.url_prefix( urls.XUL_MARC_EDIT );
76 'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid },
77 'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
79 var cat = { util: {} }; /* FIXME: kludge since we can't load remote JSAN libraries into chrome */
80 cat.util.spawn_copy_editor = function(params) {
82 if (!params.copy_ids && !params.copies) return;
83 if (params.copy_ids && params.copy_ids.length == 0) return;
84 if (params.copies && params.copies.length == 0) return;
85 if (params.copy_ids) params.copy_ids = js2JSON(params.copy_ids); // legacy
86 if (!params.caller_handles_update) params.handle_update = 1; // legacy
89 JSAN.use('util.network'); obj.network = new util.network();
90 JSAN.use('util.error'); obj.error = new util.error();
93 if (params.copy_ids && params.copy_ids.length > 1 && params.edit == 1)
94 title = $("offlineStrings").getString('staff.cat.util.copy_editor.batch_edit');
95 else if(params.copies && params.copies.length > 1 && params.edit == 1)
96 title = $("offlineStrings").getString('staff.cat.util.copy_editor.batch_view');
97 else if(params.copy_ids && params.copy_ids.length == 1)
98 title = $("offlineStrings").getString('staff.cat.util.copy_editor.edit');
100 title = $("offlineStrings").getString('staff.cat.util.copy_editor.view');
102 JSAN.use('util.window'); var win = new util.window();
103 var my_xulG = win.open(
104 (urls.XUL_COPY_EDITOR),
106 'chrome,modal,resizable',
109 if (!my_xulG.copies && params.edit) {
111 return my_xulG.copies;
115 JSAN.use('util.error'); var error = new util.error();
116 error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.spawn_copy_editor',E);
119 cat.util.fast_item_add = function(doc_id,cn_label,cp_barcode) {
123 JSAN.use('util.error'); error = new util.error();
124 JSAN.use('util.network'); var network = new util.network();
126 var acn_id = network.simple_request(
127 'FM_ACN_FIND_OR_CREATE',
128 [ ses(), cn_label, doc_id, ses('ws_ou') ]
131 if (typeof acn_id.ilsevent != 'undefined') {
132 error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.fast_item_add', acn_id);
136 var copy_obj = new acp();
139 copy_obj.barcode( cp_barcode );
140 copy_obj.call_number( acn_id );
141 copy_obj.circ_lib( ses('ws_ou') );
142 /* FIXME -- use constants */
145 copy_obj.deposit_amount(0);
146 copy_obj.fine_level(2);
147 copy_obj.loan_duration(2);
148 copy_obj.location(1);
150 copy_obj.circulate(get_db_true());
151 copy_obj.holdable(get_db_true());
152 copy_obj.opac_visible(get_db_true());
153 copy_obj.ref(get_db_false());
155 JSAN.use('util.window'); var win = new util.window();
156 return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
159 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);
162 return cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
164 alert('Error in chrome/content/cat/opac.js, set_marc_edit, fast_item_add: ' + E);
168 'label' : document.getElementById('offlineStrings').getString('cat.save_record'),
169 'func' : function (new_marcxml) {
171 var r = g.network.simple_request('MARC_XML_RECORD_UPDATE', [ ses(), docid, new_marcxml ]);
172 marc_view_reset = true;
173 copy_browser_reset = true;
174 hold_browser_reset = true;
175 if (typeof r.ilsevent != 'undefined') {
180 'oncomplete' : function() {}
184 g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString("cat.save.failure"), E);
189 if (marc_edit_reset) {
190 bottom_pane.reset_iframe( a,b,c );
191 marc_edit_reset = false;
193 bottom_pane.set_iframe( a,b,c );
197 function set_copy_browser() {
198 g.view = 'copy_browser';
199 if (copy_browser_reset) {
200 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
201 copy_browser_reset =false;
203 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
207 function set_hold_browser() {
208 g.view = 'hold_browser';
209 if (hold_browser_reset) {
210 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
211 hold_browser_reset = false;
213 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
217 function set_opac() {
220 var content_params = {
221 'show_nav_buttons' : true,
222 'show_print_button' : true,
223 'passthru_content_params' : {
225 'authtime' : ses('authtime'),
226 'window_open' : function(a,b,c) {
228 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
229 return window.open(a,b,c);
231 g.error.standard_unexpected_error_alert('window_open',E);
235 'on_url_load' : function(f) {
236 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
239 if (typeof f.contentWindow.wrappedJSObject.attachEvt != 'undefined') {
240 win = f.contentWindow.wrappedJSObject;
242 win = f.contentWindow;
245 win = f.contentWindow;
247 win.attachEvt("rdetail", "recordRetrieved",
250 if (docid == id) return;
254 g.error.standard_unexpected_error_alert('rdetail -> recordRetrieved',E);
259 g.f_record_start = null; g.f_record_prev = null; g.f_record_next = null; g.f_record_end = null;
260 $('record_start').disabled = true; $('record_next').disabled = true;
261 $('record_prev').disabled = true; $('record_end').disabled = true;
262 $('record_pos').setAttribute('value','');
264 win.attachEvt("rdetail", "nextPrevDrawn",
265 function(rIndex,rCount){
266 $('record_pos').setAttribute('value', document.getElementById('offlineStrings').getFormattedString('cat.record.counter', [(1+rIndex), rCount ? rCount : 1]));
267 if (win.rdetailNext) {
268 g.f_record_next = function() {
269 g.view_override = g.view;
272 $('record_next').disabled = false;
274 if (win.rdetailPrev) {
275 g.f_record_prev = function() {
276 g.view_override = g.view;
279 $('record_prev').disabled = false;
281 if (win.rdetailStart) {
282 g.f_record_start = function() {
283 g.view_override = g.view;
286 $('record_start').disabled = false;
288 if (win.rdetailEnd) {
289 g.f_record_end = function() {
290 g.view_override = g.view;
293 $('record_end').disabled = false;
298 'url_prefix' : xulG.url_prefix,
300 content_params.new_tab = xulG.new_tab;
301 content_params.set_tab = xulG.set_tab;
302 content_params.close_tab = xulG.close_tab;
303 content_params.new_patron_tab = xulG.new_patron_tab;
304 content_params.set_patron_tab = xulG.set_patron_tab;
305 content_params.volume_item_creator = xulG.volume_item_creator;
306 content_params.get_new_session = xulG.get_new_session;
307 content_params.holdings_maintenance_tab = xulG.holdings_maintenance_tab;
308 content_params.set_tab_name = xulG.set_tab_name;
309 content_params.open_chrome_window = xulG.open_chrome_window;
310 content_params.url_prefix = xulG.url_prefix;
311 content_params.network_meter = xulG.network_meter;
312 content_params.set_statusbar = xulG.set_statusbar;
314 if (opac_url) { content_params.url = opac_url; } else { content_params.url = xulG.url_prefix( urls.browser ); }
315 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_BROWSER) + '?name=Catalog', {}, content_params);
316 /* // Remember to use the REMOTE_BROWSER if we ever try to move this to remote xul again
317 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_REMOTE_BROWSER) + '?name=Catalog', {}, content_params);
320 g.error.sdump('D_ERROR','set_opac: ' + E);
324 function bib_in_new_tab() {
326 var url = browser_frame.contentWindow.g.browser.controller.view.browser_browser.contentWindow.wrappedJSObject.location.href;
327 var content_params = { 'session' : ses(), 'authtime' : ses('authtime'), 'opac_url' : url };
328 xulG.new_tab(xulG.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
330 g.error.sdump('D_ERROR',E);
334 function remove_me() {
335 var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
336 dump('removing ' + url + '\n');
337 try { top_pane.remove_iframe( url ); } catch(E) { dump(E + '\n'); }
338 $('nav').setAttribute('hidden','true');
341 function add_to_bucket() {
342 JSAN.use('util.window'); var win = new util.window();
344 xulG.url_prefix(urls.XUL_RECORD_BUCKETS_QUICK),
345 'sel_bucket_win' + win.window_name_increment(),
346 'chrome,resizable,modal,center',
348 record_ids: [ docid ]
353 function mark_for_overlay() {
354 g.data.marked_record = docid;
355 g.data.stash('marked_record');
356 var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
357 if (typeof robj.ilsevent == 'undefined') {
358 g.data.marked_record_mvr = robj;
360 g.data.marked_record_mvr = null;
361 g.error.standard_unexpected_error_alert('in mark_for_overlay',robj);
363 g.data.stash('marked_record_mvr');
364 if (g.data.marked_record_mvr) {
365 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.tcn.alert',[ g.data.marked_record_mvr.tcn() ]));
366 xulG.set_statusbar(1, $("offlineStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.tcn.label',[g.data.marked_record_mvr.tcn()]) );
368 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.record_id.alert',[ g.data.marked_record ]));
369 xulG.set_statusbar(1, $("offlineStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.record_id.label',[g.data.marked_record]) );
373 function mark_for_hold_transfer() {
374 g.data.marked_record_for_hold_transfer = docid;
375 g.data.stash('marked_record_for_hold_transfer');
376 var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
377 if (typeof robj.ilsevent == 'undefined') {
378 g.data.marked_record_for_hold_transfer_mvr = robj;
380 g.data.marked_record_for_hold_transfer_mvr = null;
381 g.error.standard_unexpected_error_alert('in mark_for_hold_transfer',robj);
383 g.data.stash('marked_record_for_hold_transfer_mvr');
384 if (g.data.marked_record_mvr) {
385 var m = $("offlineStrings").getFormattedString('staff.cat.opac.marked_record_for_hold_transfer_indicator.tcn.label',[g.data.marked_record_for_hold_transfer_mvr.tcn()]);
386 alert(m); xulG.set_statusbar(1, m );
388 var m = $("offlineStrings").getFormattedString('staff.cat.opac.marked_record_for_hold_transfer_indicator.record_id.label',[g.data.marked_record_for_hold_transfer]);
389 alert(m); xulG.set_statusbar(1, m );
393 function transfer_title_holds() {
394 g.data.stash_retrieve();
395 var target = g.data.marked_record_for_hold_transfer;
397 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.destination_needed.label');
401 var robj = g.network.simple_request('TRANSFER_TITLE_HOLDS',[ ses(), target, [ docid ] ]);
403 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.success.label');
406 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.failure.label');
409 hold_browser_reset = true;
410 if (g.view == 'hold_browser') { set_hold_browser(); };
413 function delete_record() {
414 if (g.error.yns_alert(
415 document.getElementById('offlineStrings').getFormattedString('cat.opac.delete_record.confirm', [docid]),
416 document.getElementById('offlineStrings').getString('cat.opac.delete_record'),
417 document.getElementById('offlineStrings').getString('cat.opac.delete'),
418 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
420 document.getElementById('offlineStrings').getString('cat.opac.record_deleted.confirm')) == 0) {
421 var robj = g.network.simple_request('FM_BRE_DELETE',[ses(),docid]);
422 if (typeof robj.ilsevent != 'undefined') {
423 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error', [docid, robj.textcode, robj.desc]) + '\n');
425 alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
426 refresh_display(docid);
431 function undelete_record() {
432 if (g.error.yns_alert(
433 document.getElementById('offlineStrings').getFormattedString('cat.opac.undelete_record.confirm', [docid]),
434 document.getElementById('offlineStrings').getString('cat.opac.undelete_record'),
435 document.getElementById('offlineStrings').getString('cat.opac.undelete'),
436 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
438 document.getElementById('offlineStrings').getString('cat.opac.record_undeleted.confirm')) == 0) {
440 var robj = g.network.simple_request('FM_BRE_UNDELETE',[ses(),docid]);
441 if (typeof robj.ilsevent != 'undefined') {
442 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_undeleted.error', [docid, robj.textcode, robj.desc]) + '\n');
444 alert(document.getElementById('offlineStrings').getString('cat.opac.record_undeleted'));
445 refresh_display(docid);
450 function refresh_display(id) {
452 marc_view_reset = true;
453 marc_edit_reset = true;
454 copy_browser_reset = true;
455 hold_browser_reset = true;
456 while(top_pane.node.lastChild) top_pane.node.removeChild( top_pane.node.lastChild );
457 var children = bottom_pane.node.childNodes;
458 for (var i = 0; i < children.length; i++) {
459 if (children[i] != browser_frame) bottom_pane.node.removeChild(children[i]);
463 $('nav').setAttribute('hidden','false');
464 var settings = g.network.simple_request(
466 [ ses(), g.data.list.au[0].id() ]
468 var view = settings['staff_client.catalog.record_view.default'];
469 if (g.view_override) {
470 view = g.view_override;
471 g.view_override = null;
474 case 'marc_view' : set_marc_view(); break;
475 case 'marc_edit' : set_marc_edit(); break;
476 case 'copy_browser' : set_copy_browser(); break;
477 case 'hold_browser' : set_hold_browser(); break;
479 default: set_opac(); break;
482 g.error.standard_unexpected_error_alert('in refresh_display',E);
486 function set_default() {
487 var robj = g.network.simple_request(
489 [ ses(), g.data.list.au[0].id(), { 'staff_client.catalog.record_view.default' : g.view } ]
491 if (typeof robj.ilsevent != 'undefined') {
492 if (robj.ilsevent != 0) g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString('cat.preference.error'), robj);
496 function add_volumes() {
500 edit = g.network.request(
501 api.PERM_MULTI_ORG_CHECK.app,
502 api.PERM_MULTI_ORG_CHECK.method,
507 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
509 ).length == 0 ? 1 : 0;
511 g.error.sdump('D_ERROR','batch permission check: ' + E);
515 alert(document.getElementById('offlineStrings').getString('staff.circ.copy_status.add_volumes.perm_failure'));
516 return; // no read-only view for this interface
519 var title = document.getElementById('offlineStrings').getFormattedString('staff.circ.copy_status.add_volumes.title', [docid]);
521 JSAN.use('util.window'); var win = new util.window();
523 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
526 { 'doc_id' : docid, 'ou_ids' : [ ses('ws_ou') ] }
529 alert('Error in chrome/content/cat/opac.js, add_volumes(): ' + E);