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 if (opac_url) { content_params.url = opac_url; } else { content_params.url = xulG.url_prefix( urls.browser ); }
301 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_BROWSER) + '?name=Catalog', {}, content_params);
302 /* // Remember to use the REMOTE_BROWSER if we ever try to move this to remote xul again
303 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_REMOTE_BROWSER) + '?name=Catalog', {}, content_params);
306 g.error.sdump('D_ERROR','set_opac: ' + E);
310 function bib_in_new_tab() {
312 var url = browser_frame.contentWindow.g.browser.controller.view.browser_browser.contentWindow.wrappedJSObject.location.href;
313 var content_params = { 'session' : ses(), 'authtime' : ses('authtime'), 'opac_url' : url };
314 xulG.new_tab(xulG.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
316 g.error.sdump('D_ERROR',E);
320 function remove_me() {
321 var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
322 dump('removing ' + url + '\n');
323 try { top_pane.remove_iframe( url ); } catch(E) { dump(E + '\n'); }
324 $('nav').setAttribute('hidden','true');
327 function add_to_bucket() {
328 JSAN.use('util.window'); var win = new util.window();
330 xulG.url_prefix(urls.XUL_RECORD_BUCKETS_QUICK),
331 'sel_bucket_win' + win.window_name_increment(),
332 'chrome,resizable,modal,center',
334 record_ids: [ docid ]
339 function mark_for_overlay() {
340 g.data.marked_record = docid;
341 g.data.stash('marked_record');
342 var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
343 if (typeof robj.ilsevent == 'undefined') {
344 g.data.marked_record_mvr = robj;
346 g.data.marked_record_mvr = null;
347 g.error.standard_unexpected_error_alert('in mark_for_overlay',robj);
349 g.data.stash('marked_record_mvr');
350 if (g.data.marked_record_mvr) {
351 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.tcn.alert',[ g.data.marked_record_mvr.tcn() ]));
352 xulG.set_statusbar(1, $("offlineStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.tcn.label',[g.data.marked_record_mvr.tcn()]) );
354 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.record_id.alert',[ g.data.marked_record ]));
355 xulG.set_statusbar(1, $("offlineStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.record_id.label',[g.data.marked_record]) );
359 function mark_for_hold_transfer() {
360 g.data.marked_record_for_hold_transfer = docid;
361 g.data.stash('marked_record_for_hold_transfer');
362 var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
363 if (typeof robj.ilsevent == 'undefined') {
364 g.data.marked_record_for_hold_transfer_mvr = robj;
366 g.data.marked_record_for_hold_transfer_mvr = null;
367 g.error.standard_unexpected_error_alert('in mark_for_hold_transfer',robj);
369 g.data.stash('marked_record_for_hold_transfer_mvr');
370 if (g.data.marked_record_mvr) {
371 var m = $("offlineStrings").getFormattedString('staff.cat.opac.marked_record_for_hold_transfer_indicator.tcn.label',[g.data.marked_record_for_hold_transfer_mvr.tcn()]);
372 alert(m); xulG.set_statusbar(1, m );
374 var m = $("offlineStrings").getFormattedString('staff.cat.opac.marked_record_for_hold_transfer_indicator.record_id.label',[g.data.marked_record_for_hold_transfer]);
375 alert(m); xulG.set_statusbar(1, m );
379 function transfer_title_holds() {
380 g.data.stash_retrieve();
381 var target = g.data.marked_record_for_hold_transfer;
383 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.destination_needed.label');
387 var robj = g.network.simple_request('TRANSFER_TITLE_HOLDS',[ ses(), target, [ docid ] ]);
389 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.success.label');
392 var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.failure.label');
395 hold_browser_reset = true;
396 if (g.view == 'hold_browser') { set_hold_browser(); };
399 function delete_record() {
400 if (g.error.yns_alert(
401 document.getElementById('offlineStrings').getFormattedString('cat.opac.delete_record.confirm', [docid]),
402 document.getElementById('offlineStrings').getString('cat.opac.delete_record'),
403 document.getElementById('offlineStrings').getString('cat.opac.delete'),
404 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
406 document.getElementById('offlineStrings').getString('cat.opac.record_deleted.confirm')) == 0) {
407 var robj = g.network.simple_request('FM_BRE_DELETE',[ses(),docid]);
408 if (typeof robj.ilsevent != 'undefined') {
409 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error', [docid, robj.textcode, robj.desc]) + '\n');
411 alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
412 refresh_display(docid);
417 function undelete_record() {
418 if (g.error.yns_alert(
419 document.getElementById('offlineStrings').getFormattedString('cat.opac.undelete_record.confirm', [docid]),
420 document.getElementById('offlineStrings').getString('cat.opac.undelete_record'),
421 document.getElementById('offlineStrings').getString('cat.opac.undelete'),
422 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
424 document.getElementById('offlineStrings').getString('cat.opac.record_undeleted.confirm')) == 0) {
426 var robj = g.network.simple_request('FM_BRE_UNDELETE',[ses(),docid]);
427 if (typeof robj.ilsevent != 'undefined') {
428 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_undeleted.error', [docid, robj.textcode, robj.desc]) + '\n');
430 alert(document.getElementById('offlineStrings').getString('cat.opac.record_undeleted'));
431 refresh_display(docid);
436 function refresh_display(id) {
438 marc_view_reset = true;
439 marc_edit_reset = true;
440 copy_browser_reset = true;
441 hold_browser_reset = true;
442 while(top_pane.node.lastChild) top_pane.node.removeChild( top_pane.node.lastChild );
443 var children = bottom_pane.node.childNodes;
444 for (var i = 0; i < children.length; i++) {
445 if (children[i] != browser_frame) bottom_pane.node.removeChild(children[i]);
449 $('nav').setAttribute('hidden','false');
450 var settings = g.network.simple_request(
452 [ ses(), g.data.list.au[0].id() ]
454 var view = settings['staff_client.catalog.record_view.default'];
455 if (g.view_override) {
456 view = g.view_override;
457 g.view_override = null;
460 case 'marc_view' : set_marc_view(); break;
461 case 'marc_edit' : set_marc_edit(); break;
462 case 'copy_browser' : set_copy_browser(); break;
463 case 'hold_browser' : set_hold_browser(); break;
465 default: set_opac(); break;
468 g.error.standard_unexpected_error_alert('in refresh_display',E);
472 function set_default() {
473 var robj = g.network.simple_request(
475 [ ses(), g.data.list.au[0].id(), { 'staff_client.catalog.record_view.default' : g.view } ]
477 if (typeof robj.ilsevent != 'undefined') {
478 if (robj.ilsevent != 0) g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString('cat.preference.error'), robj);
482 function add_volumes() {
486 edit = g.network.request(
487 api.PERM_MULTI_ORG_CHECK.app,
488 api.PERM_MULTI_ORG_CHECK.method,
493 [ 'CREATE_VOLUME', 'CREATE_COPY' ]
495 ).length == 0 ? 1 : 0;
497 g.error.sdump('D_ERROR','batch permission check: ' + E);
501 alert(document.getElementById('offlineStrings').getString('staff.circ.copy_status.add_volumes.perm_failure'));
502 return; // no read-only view for this interface
505 var title = document.getElementById('offlineStrings').getFormattedString('staff.circ.copy_status.add_volumes.title', [docid]);
507 JSAN.use('util.window'); var win = new util.window();
509 window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
512 { 'doc_id' : docid, 'ou_ids' : [ ses('ws_ou') ] }
515 alert('Error in chrome/content/cat/opac.js, add_volumes(): ' + E);