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); }
29 JSAN.use('util.deck');
30 top_pane = new util.deck('top_pane');
31 bottom_pane = new util.deck('bottom_pane');
36 var err_msg = document.getElementById("offlineStrings").getFormattedString("common.exception", ["cat/opac.xul", E]);
37 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
42 function set_brief_view() {
43 var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
44 dump('spawning ' + url + '\n');
49 'set_tab_name' : function(n) {
50 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
51 try { window.xulG.set_tab_name(document.getElementById('offlineStrings').getFormattedString("cat.bib_record", [n])); } catch(E) { alert(E); }
53 dump('no set_tab_name\n');
60 function set_marc_view() {
62 if (marc_view_reset) {
63 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
64 marc_view_reset = false;
66 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
70 function set_marc_edit() {
72 var a = xulG.url_prefix( urls.XUL_MARC_EDIT );
75 'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid },
76 'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
78 var cat = { util: {} }; /* FIXME: kludge since we can't load remote JSAN libraries into chrome */
79 cat.util.spawn_copy_editor = function(params) {
81 if (!params.copy_ids && !params.copies) return;
82 if (params.copy_ids && params.copy_ids.length == 0) return;
83 if (params.copies && params.copies.length == 0) return;
84 if (params.copy_ids) params.copy_ids = js2JSON(params.copy_ids); // legacy
85 if (!params.caller_handles_update) params.handle_update = 1; // legacy
88 JSAN.use('util.network'); obj.network = new util.network();
89 JSAN.use('util.error'); obj.error = new util.error();
92 if (params.copy_ids && params.copy_ids.length > 1 && params.edit == 1)
93 title = $("offlineStrings").getString('staff.cat.util.copy_editor.batch_edit');
94 else if(params.copies && params.copies.length > 1 && params.edit == 1)
95 title = $("offlineStrings").getString('staff.cat.util.copy_editor.batch_view');
96 else if(params.copy_ids && params.copy_ids.length == 1)
97 title = $("offlineStrings").getString('staff.cat.util.copy_editor.edit');
99 title = $("offlineStrings").getString('staff.cat.util.copy_editor.view');
101 JSAN.use('util.window'); var win = new util.window();
102 var my_xulG = win.open(
103 (urls.XUL_COPY_EDITOR),
105 'chrome,modal,resizable',
108 if (!my_xulG.copies && params.edit) {
110 return my_xulG.copies;
114 JSAN.use('util.error'); var error = new util.error();
115 error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.spawn_copy_editor',E);
118 cat.util.fast_item_add = function(doc_id,cn_label,cp_barcode) {
122 JSAN.use('util.error'); error = new util.error();
123 JSAN.use('util.network'); var network = new util.network();
125 var acn_id = network.simple_request(
126 'FM_ACN_FIND_OR_CREATE',
127 [ ses(), cn_label, doc_id, ses('ws_ou') ]
130 if (typeof acn_id.ilsevent != 'undefined') {
131 error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.fast_item_add', acn_id);
135 var copy_obj = new acp();
138 copy_obj.barcode( cp_barcode );
139 copy_obj.call_number( acn_id );
140 copy_obj.circ_lib( ses('ws_ou') );
141 /* FIXME -- use constants */
144 copy_obj.deposit_amount(0);
145 copy_obj.fine_level(2);
146 copy_obj.loan_duration(2);
147 copy_obj.location(1);
149 copy_obj.circulate(get_db_true());
150 copy_obj.holdable(get_db_true());
151 copy_obj.opac_visible(get_db_true());
152 copy_obj.ref(get_db_false());
154 JSAN.use('util.window'); var win = new util.window();
155 return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
158 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);
161 return cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
163 alert('Error in chrome/content/cat/opac.js, set_marc_edit, fast_item_add: ' + E);
167 'label' : document.getElementById('offlineStrings').getString('cat.save_record'),
168 'func' : function (new_marcxml) {
170 var r = g.network.simple_request('MARC_XML_RECORD_UPDATE', [ ses(), docid, new_marcxml ]);
171 marc_view_reset = true;
172 copy_browser_reset = true;
173 hold_browser_reset = true;
174 if (typeof r.ilsevent != 'undefined') {
179 'oncomplete' : function() {}
183 g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString("cat.save.failure"), E);
188 if (marc_edit_reset) {
189 bottom_pane.reset_iframe( a,b,c );
190 marc_edit_reset = false;
192 bottom_pane.set_iframe( a,b,c );
196 function set_copy_browser() {
197 g.view = 'copy_browser';
198 if (copy_browser_reset) {
199 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
200 copy_browser_reset =false;
202 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
206 function set_hold_browser() {
207 g.view = 'hold_browser';
208 if (hold_browser_reset) {
209 bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
210 hold_browser_reset = false;
212 bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
216 function set_opac() {
219 var content_params = {
220 'show_nav_buttons' : true,
221 'show_print_button' : true,
222 'passthru_content_params' : {
224 'authtime' : ses('authtime'),
225 'window_open' : function(a,b,c) {
227 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
228 return window.open(a,b,c);
230 g.error.standard_unexpected_error_alert('window_open',E);
234 'on_url_load' : function(f) {
235 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
238 if (typeof f.contentWindow.wrappedJSObject.attachEvt != 'undefined') {
239 win = f.contentWindow.wrappedJSObject;
241 win = f.contentWindow;
244 win = f.contentWindow;
246 win.attachEvt("rdetail", "recordRetrieved",
249 if (docid == id) return;
253 g.error.standard_unexpected_error_alert('rdetail -> recordRetrieved',E);
258 g.f_record_start = null; g.f_record_prev = null; g.f_record_next = null; g.f_record_end = null;
259 $('record_start').disabled = true; $('record_next').disabled = true;
260 $('record_prev').disabled = true; $('record_end').disabled = true;
261 $('record_pos').setAttribute('value','');
263 win.attachEvt("rdetail", "nextPrevDrawn",
264 function(rIndex,rCount){
265 $('record_pos').setAttribute('value', document.getElementById('offlineStrings').getFormattedString('cat.record.counter', [(1+rIndex), rCount ? rCount : 1]));
266 if (win.rdetailNext) {
267 g.f_record_next = function() {
268 g.view_override = g.view;
271 $('record_next').disabled = false;
273 if (win.rdetailPrev) {
274 g.f_record_prev = function() {
275 g.view_override = g.view;
278 $('record_prev').disabled = false;
280 if (win.rdetailStart) {
281 g.f_record_start = function() {
282 g.view_override = g.view;
285 $('record_start').disabled = false;
287 if (win.rdetailEnd) {
288 g.f_record_end = function() {
289 g.view_override = g.view;
292 $('record_end').disabled = false;
297 'url_prefix' : xulG.url_prefix,
299 if (opac_url) { content_params.url = opac_url; } else { content_params.url = xulG.url_prefix( urls.browser ); }
300 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_BROWSER) + '?name=Catalog', {}, content_params);
301 /* // Remember to use the REMOTE_BROWSER if we ever try to move this to remote xul again
302 browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_REMOTE_BROWSER) + '?name=Catalog', {}, content_params);
305 g.error.sdump('D_ERROR','set_opac: ' + E);
309 function bib_in_new_tab() {
311 var url = browser_frame.contentWindow.g.browser.controller.view.browser_browser.contentWindow.wrappedJSObject.location.href;
312 var content_params = { 'session' : ses(), 'authtime' : ses('authtime'), 'opac_url' : url };
313 xulG.new_tab(xulG.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
315 g.error.sdump('D_ERROR',E);
319 function remove_me() {
320 var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
321 dump('removing ' + url + '\n');
322 try { top_pane.remove_iframe( url ); } catch(E) { dump(E + '\n'); }
323 $('nav').setAttribute('hidden','true');
326 function add_to_bucket() {
327 JSAN.use('util.window'); var win = new util.window();
329 xulG.url_prefix(urls.XUL_RECORD_BUCKETS_QUICK),
330 'sel_bucket_win' + win.window_name_increment(),
331 'chrome,resizable,modal,center',
333 record_ids: [ docid ]
338 function mark_for_overlay() {
339 g.data.marked_record = docid;
340 g.data.stash('marked_record');
341 var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
342 if (typeof robj.ilsevent == 'undefined') {
343 g.data.marked_record_mvr = robj;
345 g.data.marked_record_mvr = null;
346 g.error.standard_unexpected_error_alert('in mark_for_overlay',robj);
348 g.data.stash('marked_record_mvr');
349 if (g.data.marked_record_mvr) {
350 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.tcn.alert',[ g.data.marked_record_mvr.tcn() ]));
352 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.record_id.alert',[ g.data.marked_record ]));
356 function delete_record() {
357 if (g.error.yns_alert(
358 document.getElementById('offlineStrings').getFormattedString('cat.opac.delete_record.confirm', [docid]),
359 document.getElementById('offlineStrings').getString('cat.opac.delete_record'),
360 document.getElementById('offlineStrings').getString('cat.opac.delete'),
361 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
363 document.getElementById('offlineStrings').getString('cat.opac.record_deleted.confirm')) == 0) {
364 var robj = g.network.simple_request('FM_BRE_DELETE',[ses(),docid]);
365 if (typeof robj.ilsevent != 'undefined') {
366 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error', [docid, robj.textcode, robj.desc]) + '\n');
368 alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
369 refresh_display(docid);
374 function undelete_record() {
375 if (g.error.yns_alert(
376 document.getElementById('offlineStrings').getFormattedString('cat.opac.undelete_record.confirm', [docid]),
377 document.getElementById('offlineStrings').getString('cat.opac.undelete_record'),
378 document.getElementById('offlineStrings').getString('cat.opac.undelete'),
379 document.getElementById('offlineStrings').getString('cat.opac.cancel'),
381 document.getElementById('offlineStrings').getString('cat.opac.record_undeleted.confirm')) == 0) {
383 var robj = g.network.simple_request('FM_BRE_UNDELETE',[ses(),docid]);
384 if (typeof robj.ilsevent != 'undefined') {
385 alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_undeleted.error', [docid, robj.textcode, robj.desc]) + '\n');
387 alert(document.getElementById('offlineStrings').getString('cat.opac.record_undeleted'));
388 refresh_display(docid);
393 function refresh_display(id) {
395 marc_view_reset = true;
396 marc_edit_reset = true;
397 copy_browser_reset = true;
398 hold_browser_reset = true;
399 while(top_pane.node.lastChild) top_pane.node.removeChild( top_pane.node.lastChild );
400 var children = bottom_pane.node.childNodes;
401 for (var i = 0; i < children.length; i++) {
402 if (children[i] != browser_frame) bottom_pane.node.removeChild(children[i]);
406 $('nav').setAttribute('hidden','false');
407 var settings = g.network.simple_request(
409 [ ses(), g.data.list.au[0].id() ]
411 var view = settings['staff_client.catalog.record_view.default'];
412 if (g.view_override) {
413 view = g.view_override;
414 g.view_override = null;
417 case 'marc_view' : set_marc_view(); break;
418 case 'marc_edit' : set_marc_edit(); break;
419 case 'copy_browser' : set_copy_browser(); break;
420 case 'hold_browser' : set_hold_browser(); break;
422 default: set_opac(); break;
425 g.error.standard_unexpected_error_alert('in refresh_display',E);
429 function set_default() {
430 var robj = g.network.simple_request(
432 [ ses(), g.data.list.au[0].id(), { 'staff_client.catalog.record_view.default' : g.view } ]
434 if (typeof robj.ilsevent != 'undefined') {
435 if (robj.ilsevent != 0) g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString('cat.preference.error'), robj);