]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/cat/opac.js
Serials: an alternative batch receiving interface, to support certain
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / cat / opac.js
1 var docid; var marc_html; var top_pane; var bottom_pane; var opac_frame; var opac_url;
2
3 var marc_view_reset = true;
4 var marc_edit_reset = true;
5 var copy_browser_reset = true;
6 var hold_browser_reset = true;
7 var serctrl_view_reset = true;
8
9 function $(id) { return document.getElementById(id); }
10
11 function my_init() {
12     try {
13         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
14         if (typeof JSAN == 'undefined') { throw(document.getElementById('offlineStrings').getString('common.jsan.missing')); }
15         JSAN.errorLevel = "die"; // none, warn, or die
16         JSAN.addRepository('..');
17         JSAN.use('util.error'); g.error = new util.error();
18         g.error.sdump('D_TRACE','my_init() for cat/opac.xul');
19
20         JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
21         XML_HTTP_SERVER = g.data.server_unadorned;
22
23         // Pull in local customizations
24         var r = new XMLHttpRequest();
25         r.open("GET", xulG.url_prefix('/xul/server/skin/custom.js'), false);
26         r.send(null);
27         if (r.status == 200) {
28             dump('Evaluating /xul/server/skin/custom.js\n');
29             eval( r.responseText );
30         }
31
32         window.help_context_set_locally = true;
33
34         JSAN.use('util.network'); g.network = new util.network();
35
36         g.cgi = new CGI();
37         try { authtime = g.cgi.param('authtime') || xulG.authtime; } catch(E) { g.error.sdump('D_ERROR',E); }
38         try { docid = g.cgi.param('docid') || xulG.docid; } catch(E) { g.error.sdump('D_ERROR',E); }
39         try { opac_url = g.cgi.param('opac_url') || xulG.opac_url; } catch(E) { g.error.sdump('D_ERROR',E); }
40         try { g.view_override = g.cgi.param('default_view') || xulG.default_view; } catch(E) { g.error.sdump('D_ERROR',E); }
41
42         JSAN.use('util.deck');
43         top_pane = new util.deck('top_pane');
44         bottom_pane = new util.deck('bottom_pane');
45
46         set_opac();
47
48     } catch(E) {
49         var err_msg = document.getElementById("offlineStrings").getFormattedString("common.exception", ["cat/opac.xul", E]);
50         try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
51         alert(err_msg);
52     }
53 }
54
55 function default_focus() {
56     opac_wrapper_set_help_context(); 
57 }
58
59 function opac_wrapper_set_help_context() {
60     try {
61         dump('Entering opac.js, opac_wrapper_set_help_context\n');
62         var cw = bottom_pane.get_contentWindow(); 
63         if (cw && typeof cw['location'] != 'undefined') {
64             if (typeof cw.help_context_set_locally == 'undefined') {
65                 var help_params = {
66                     'protocol' : cw.location.protocol,
67                     'hostname' : cw.location.hostname,
68                     'port' : cw.location.port,
69                     'pathname' : cw.location.pathname,
70                     'src' : ''
71                 };
72                 xulG.set_help_context(help_params);
73             } else {
74                 dump('\tcw.help_context_set_locally = ' + cw.help_context_set_locally + '\n');
75                 if (typeof cw.default_focus == 'function') {
76                     cw.default_focus();
77                 }
78             }
79         } else {
80             dump('opac.js: problem in opac_wrapper_set_help_context(): bottom_pane = ' + bottom_pane + ' cw = ' + cw + '\n');
81             dump('\tcw.location = ' + cw.location + '\n');
82         }
83     } catch(E) {
84         // We can expect some errors here if this called before the DOM is ready.  Easiest to just trap and ignore
85         dump('Error in opac.js, opac_wrapper_set_help_context(): ' + E + '\n');
86     }
87 }
88
89 function set_brief_view() {
90     var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid); 
91     dump('spawning ' + url + '\n');
92     top_pane.set_iframe( 
93         url,
94         {}, 
95         { 
96             'set_tab_name' : function(n) { 
97                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
98                     try { window.xulG.set_tab_name(document.getElementById('offlineStrings').getFormattedString("cat.bib_record", [n])); } catch(E) { alert(E); }
99                 } else {
100                     dump('no set_tab_name\n');
101                 }
102             }
103         }  
104     );
105 }
106
107 function set_marc_view() {
108     g.view = 'marc_view';
109     if (marc_view_reset) {
110         bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
111         marc_view_reset = false;
112     } else {
113         bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_MARC_VIEW ) + '?docid=' + window.escape(docid),{},xulG);
114     }
115     opac_wrapper_set_help_context(); 
116     bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
117 }
118
119 function set_marc_edit() {
120     g.view = 'marc_edit';
121     var a =    xulG.url_prefix( urls.XUL_MARC_EDIT );
122     var b =    {};
123     var c =    {
124             'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid },
125             'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
126                 try {
127                     var cat = { util: {} }; /* FIXME: kludge since we can't load remote JSAN libraries into chrome */
128                     cat.util.spawn_copy_editor = function(params) {
129                         try {
130                             if (!params.copy_ids && !params.copies) return;
131                             if (params.copy_ids && params.copy_ids.length == 0) return;
132                             if (params.copies && params.copies.length == 0) return;
133                             if (params.copy_ids) params.copy_ids = js2JSON(params.copy_ids); // legacy
134                             if (!params.caller_handles_update) params.handle_update = 1; // legacy
135
136                             var obj = {};
137                             JSAN.use('util.network'); obj.network = new util.network();
138                             JSAN.use('util.error'); obj.error = new util.error();
139                         
140                             var title = '';
141                             if (params.copy_ids && params.copy_ids.length > 1 && params.edit == 1)
142                                 title = $("offlineStrings").getString('staff.cat.util.copy_editor.batch_edit');
143                             else if(params.copies && params.copies.length > 1 && params.edit == 1)
144                                 title = $("offlineStrings").getString('staff.cat.util.copy_editor.batch_view');
145                             else if(params.copy_ids && params.copy_ids.length == 1)
146                                 title = $("offlineStrings").getString('staff.cat.util.copy_editor.edit');
147                             else
148                                 title = $("offlineStrings").getString('staff.cat.util.copy_editor.view');
149
150                             JSAN.use('util.window'); var win = new util.window();
151                             var my_xulG = win.open(
152                                 (urls.XUL_COPY_EDITOR),
153                                 title,
154                                 'chrome,modal,resizable',
155                                 params
156                             );
157                             if (!my_xulG.copies && params.edit) {
158                             } else {
159                                 return my_xulG.copies;
160                             }
161                             return [];
162                         } catch(E) {
163                             JSAN.use('util.error'); var error = new util.error();
164                             error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.spawn_copy_editor',E);
165                         }
166                     }
167                     cat.util.fast_item_add = function(doc_id,cn_label,cp_barcode) {
168                         var error;
169                         try {
170
171                             JSAN.use('util.error'); error = new util.error();
172                             JSAN.use('util.network'); var network = new util.network();
173
174                             var acn_id = network.simple_request(
175                                 'FM_ACN_FIND_OR_CREATE',
176                                 [ ses(), cn_label, doc_id, ses('ws_ou') ]
177                             );
178
179                             if (typeof acn_id.ilsevent != 'undefined') {
180                                 error.standard_unexpected_error_alert('Error in chrome/content/cat/opac.js, cat.util.fast_item_add', acn_id);
181                                 return;
182                             }
183
184                             var copy_obj = new acp();
185                             copy_obj.id( -1 );
186                             copy_obj.isnew('1');
187                             copy_obj.barcode( cp_barcode );
188                             copy_obj.call_number( acn_id );
189                             copy_obj.circ_lib( ses('ws_ou') );
190                             /* FIXME -- use constants */
191                             copy_obj.deposit(0);
192                             copy_obj.price(0);
193                             copy_obj.deposit_amount(0);
194                             copy_obj.fine_level(2);
195                             copy_obj.loan_duration(2);
196                             copy_obj.location(1);
197                             copy_obj.status(0);
198                             copy_obj.circulate(get_db_true());
199                             copy_obj.holdable(get_db_true());
200                             copy_obj.opac_visible(get_db_true());
201                             copy_obj.ref(get_db_false());
202
203                             JSAN.use('util.window'); var win = new util.window();
204                             return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
205
206                         } catch(E) {
207                             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);
208                         }
209                     }
210                     return cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
211                 } catch(E) {
212                     alert('Error in chrome/content/cat/opac.js, set_marc_edit, fast_item_add: ' + E);
213                 }
214             },
215             'save' : {
216                 'label' : document.getElementById('offlineStrings').getString('cat.save_record'),
217                 'func' : function (new_marcxml) {
218                     try {
219                         var r = g.network.simple_request('MARC_XML_RECORD_UPDATE', [ ses(), docid, new_marcxml ]);
220                         marc_view_reset = true;
221                         copy_browser_reset = true;
222                         hold_browser_reset = true;
223                         if (typeof r.ilsevent != 'undefined') {
224                             throw(r);
225                         } else {
226                             return {
227                                 'id' : r.id(),
228                                 'oncomplete' : function() {}
229                             };
230                         }
231                     } catch(E) {
232                             g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString("cat.save.failure"), E);
233                     }
234                 }
235             }
236         };
237     if (marc_edit_reset) {
238         bottom_pane.reset_iframe( a,b,c );
239         marc_edit_reset = false;
240     } else {
241         bottom_pane.set_iframe( a,b,c );
242     }
243     opac_wrapper_set_help_context(); 
244     bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
245 }
246
247 function set_copy_browser() {
248     g.view = 'copy_browser';
249     if (copy_browser_reset) {
250         bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
251         copy_browser_reset =false;
252     } else {
253         bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_COPY_VOLUME_BROWSE ) + '?docid=' + window.escape(docid),{},xulG);
254     }
255     opac_wrapper_set_help_context(); 
256     bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
257 }
258
259 function set_hold_browser() {
260     g.view = 'hold_browser';
261     if (hold_browser_reset) {
262         bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
263         hold_browser_reset = false;
264     } else {
265         bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_HOLDS_BROWSER ) + '?docid=' + window.escape(docid),{},xulG);
266     }
267     opac_wrapper_set_help_context(); 
268     bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
269 }
270
271
272 function open_acq_orders() {
273     try {
274         var content_params = {
275             "session": ses(),
276             "authtime": ses("authtime"),
277             "no_xulG": false,
278             "show_print_button": false
279         };
280
281         ["url_prefix", "new_tab", "set_tab", "close_tab", "new_patron_tab",
282             "set_patron_tab", "volume_item_creator", "get_new_session",
283             "holdings_maintenance_tab", "set_tab_name", "open_chrome_window",
284             "url_prefix", "network_meter", "page_meter", "set_statusbar",
285             "set_help_context"
286         ].forEach(function(k) { content_params[k] = xulG[k]; });
287
288         var loc = urls.XUL_BROWSER + "?url=" + window.escape(
289             xulG.url_prefix("/eg/acq/lineitem/related/") +
290             docid + "?target=bib"
291         );
292         xulG.new_tab(
293             loc, {
294                 "tab_name": $("offlineStrings").getString(
295                     "staff.cat.opac.related_items"
296                 ),
297                 "browser": false
298             }, content_params
299         );
300     } catch (E) {
301         g.error.sdump("D_ERROR", E);
302     }
303 }
304
305 function set_opac() {
306     g.view = 'opac';
307     try {
308         var content_params = { 
309             'show_nav_buttons' : true,
310             'show_print_button' : true,
311             'passthru_content_params' : { 
312                 'authtoken' : ses(), 
313                 'authtime' : ses('authtime'),
314                 'window_open' : function(a,b,c) {
315                     try {
316                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
317                         return window.open(a,b,c);
318                     } catch(E) {
319                         g.error.standard_unexpected_error_alert('window_open',E);
320                     }
321                 }
322             },
323             'on_url_load' : function(f) {
324                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
325                 var win;
326                 try {
327                     if (typeof f.contentWindow.wrappedJSObject.attachEvt != 'undefined') {
328                         win = f.contentWindow.wrappedJSObject;
329                     } else {
330                         win = f.contentWindow;
331                     }
332                 } catch(E) {
333                     win = f.contentWindow;
334                 }
335                 win.attachEvt("rdetail", "recordRetrieved",
336                     function(id){
337                         try {
338                             if (docid == id) return;
339                             docid = id;
340                             refresh_display(id);
341                         } catch(E) {
342                             g.error.standard_unexpected_error_alert('rdetail -> recordRetrieved',E);
343                         }
344                     }
345                 );
346                 
347                 g.f_record_start = null; g.f_record_prev = null; g.f_record_next = null; g.f_record_end = null;
348                 $('record_start').disabled = true; $('record_next').disabled = true;
349                 $('record_prev').disabled = true; $('record_end').disabled = true;
350                 $('record_pos').setAttribute('value','');
351
352                 win.attachEvt("rdetail", "nextPrevDrawn",
353                     function(rIndex,rCount){
354                         $('record_pos').setAttribute('value', document.getElementById('offlineStrings').getFormattedString('cat.record.counter', [(1+rIndex), rCount ? rCount : 1]));
355                         if (win.rdetailNext) {
356                             g.f_record_next = function() { 
357                                 g.view_override = g.view; 
358                                 win.rdetailNext(); 
359                             }
360                             $('record_next').disabled = false;
361                         }
362                         if (win.rdetailPrev) {
363                             g.f_record_prev = function() { 
364                                 g.view_override = g.view; 
365                                 win.rdetailPrev(); 
366                             }
367                             $('record_prev').disabled = false;
368                         }
369                         if (win.rdetailStart) {
370                             g.f_record_start = function() { 
371                                 g.view_override = g.view; 
372                                 win.rdetailStart(); 
373                             }
374                             $('record_start').disabled = false;
375                         }
376                         if (win.rdetailEnd) {
377                             g.f_record_end = function() { 
378                                 g.view_override = g.view; 
379                                 win.rdetailEnd(); 
380                             }
381                             $('record_end').disabled = false;
382                         }
383                     }
384                 );
385
386                 $('mfhd_add').setAttribute('oncommand','create_mfhd()');
387                 var mfhd_edit_menu = $('mfhd_edit');
388                 var mfhd_delete_menu = $('mfhd_delete');
389
390                 // clear menus on subsequent loads
391                 if (mfhd_edit_menu.firstChild) {
392                     mfhd_edit_menu.removeChild(mfhd_edit_menu.firstChild);
393                     mfhd_delete_menu.removeChild(mfhd_delete_menu.firstChild);
394                 }
395
396                 mfhd_edit_menu.disabled = true;
397                 mfhd_delete_menu.disabled = true;
398
399                 win.attachEvt("rdetail", "MFHDDrawn",
400                     function() {
401                         if (win.mfhdDetails && win.mfhdDetails.length > 0) {
402                             g.mfhd = {};
403                             g.mfhd.details = win.mfhdDetails;
404                             mfhd_edit_menu.disabled = false;
405                             mfhd_delete_menu.disabled = false;
406                             for (var i = 0; i < win.mfhdDetails.length; i++) {
407                                 var mfhd_details = win.mfhdDetails[i];
408                                 var num = mfhd_details.entryNum;
409                                 num++;
410                                 var label = mfhd_details.label + ' (' + num + ')';
411                                 var item = mfhd_edit_menu.appendItem(label);
412                                 item.setAttribute('oncommand','open_mfhd_editor('+mfhd_details.id+')');
413                                 item = mfhd_delete_menu.appendItem(label);
414                                 item.setAttribute('oncommand','delete_mfhd('+mfhd_details.id+')');
415                             }
416                         }
417                     }
418                 );
419             },
420             'url_prefix' : xulG.url_prefix,
421         };
422         content_params.new_tab = xulG.new_tab;
423         content_params.set_tab = xulG.set_tab;
424         content_params.close_tab = xulG.close_tab;
425         content_params.new_patron_tab = xulG.new_patron_tab;
426         content_params.set_patron_tab = xulG.set_patron_tab;
427         content_params.volume_item_creator = xulG.volume_item_creator;
428         content_params.get_new_session = xulG.get_new_session;
429         content_params.holdings_maintenance_tab = xulG.holdings_maintenance_tab;
430         content_params.set_tab_name = xulG.set_tab_name;
431         content_params.open_chrome_window = xulG.open_chrome_window;
432         content_params.url_prefix = xulG.url_prefix;
433         content_params.network_meter = xulG.network_meter;
434         content_params.page_meter = xulG.page_meter;
435         content_params.set_statusbar = xulG.set_statusbar;
436         content_params.set_help_context = xulG.set_help_context;
437
438         if (opac_url) { content_params.url = opac_url; } else { content_params.url = xulG.url_prefix( urls.browser ); }
439         browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_BROWSER) + '?name=Catalog', {}, content_params);
440         /* // Remember to use the REMOTE_BROWSER if we ever try to move this to remote xul again
441         browser_frame = bottom_pane.set_iframe( xulG.url_prefix(urls.XUL_REMOTE_BROWSER) + '?name=Catalog', {}, content_params);
442         */
443     } catch(E) {
444         g.error.sdump('D_ERROR','set_opac: ' + E);
445     }
446     opac_wrapper_set_help_context(); 
447     bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
448 }
449
450 function set_serctrl_view() {
451     g.view = 'serctrl_view';
452     if (serctrl_view_reset) {
453         bottom_pane.reset_iframe( xulG.url_prefix( urls.XUL_SERIAL_SERCTRL_MAIN ) + '?docid=' + window.escape(docid), {}, xulG);
454         serctrl_view_reset =false;
455     } else {
456         bottom_pane.set_iframe( xulG.url_prefix( urls.XUL_SERIAL_SERCTRL_MAIN ) + '?docid=' + window.escape(docid), {}, xulG);
457     }
458 }
459
460 function create_mfhd() {
461     try {
462         g.data.create_mfhd_aou = '';
463         JSAN.use('util.window'); var win = new util.window();
464         win.open(
465             xulG.url_prefix(urls.XUL_SERIAL_SELECT_AOU),
466             'sel_bucket_win' + win.window_name_increment(),
467             'chrome,resizable,modal,centerscreen'
468         );
469         if (!g.data.create_mfhd_aou) {
470             return;
471         }
472         var r = g.network.simple_request(
473                 'MFHD_XML_RECORD_CREATE',
474                 [ ses(), 1, g.data.create_mfhd_aou, docid ]
475             );
476         if (typeof r.ilsevent != 'undefined') {
477             throw(r);
478         }
479         alert("MFHD record created."); //TODO: better success message
480         //TODO: refresh opac display
481     } catch(E) {
482         g.error.standard_unexpected_error_alert("Create MFHD failed", E); //TODO: better error handling
483     }
484 }
485
486 function delete_mfhd(sre_id) {
487     if (g.error.yns_alert(
488         document.getElementById('offlineStrings').getFormattedString('serial.delete_record.confirm', [sre_id]),
489         document.getElementById('offlineStrings').getString('cat.opac.delete_record'),
490         document.getElementById('offlineStrings').getString('cat.opac.delete'),
491         document.getElementById('offlineStrings').getString('cat.opac.cancel'),
492         null,
493         document.getElementById('offlineStrings').getString('cat.opac.record_deleted.confirm')) == 0) {
494         var robj = g.network.request(
495                 'open-ils.permacrud',
496                 'open-ils.permacrud.delete.sre',
497                 [ses(),sre_id]);
498         if (typeof robj.ilsevent != 'undefined') {
499             alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error',  [docid, robj.textcode, robj.desc]) + '\n');
500         } else {
501             alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
502             //TODO: refresh opac display
503         }
504     }
505 }
506
507 function open_mfhd_editor(sre_id) {
508     try {
509         var r = g.network.simple_request(
510                 'FM_SRE_RETRIEVE',
511                 [ ses(), sre_id ]
512               );
513         if (typeof r.ilsevent != 'undefined') {
514             throw(r);
515         }
516         open_marc_editor(r, 'MFHD');
517     } catch(E) {
518         g.error.standard_unexpected_error_alert("Create MFHD failed", E); //TODO: better error handling
519     }
520 }
521
522 function open_marc_editor(rec, label) {
523     win = window.open( xulG.url_prefix('/xul/server/cat/marcedit.xul') );
524
525     win.xulG = {
526         record : {marc : rec.marc()},
527         save : {
528             label: 'Save ' + label,
529             func: function(xmlString) {  // TODO: switch to pcrud, or define an sre update method in Serial.pm?
530                 var method = 'open-ils.permacrud.update.' + rec.classname;
531                 rec.marc(xmlString);
532                 g.network.request(
533                     'open-ils.permacrud', method,
534                     [ses(), rec]
535                 );
536             }
537         }
538     };
539 }
540
541 function serials_mgmt_new_tab() {
542     try {
543         /* XXX should the following be put into a function somewhere? the gist
544          * of this setting up of content_params seems to be duplicated all
545          * over the place.
546          */
547         var content_params = {"session": ses(), "authtime": ses("authtime")};
548         ["url_prefix", "new_tab", "set_tab", "close_tab", "new_patron_tab",
549             "set_patron_tab", "volume_item_creator", "get_new_session",
550             "holdings_maintenance_tab", "set_tab_name", "open_chrome_window",
551             "url_prefix", "network_meter", "page_meter", "set_statusbar",
552             "set_help_context"
553         ].forEach(function(k) { content_params[k] = xulG[k]; });
554
555         xulG.new_tab(
556             xulG.url_prefix(urls.XUL_SERIAL_RECORD_ENTRY), {}, content_params
557         );
558     } catch (E) {
559         g.error.sdump('D_ERROR', E);
560     }
561 }
562
563 function bib_in_new_tab() {
564     try {
565         var url = browser_frame.contentWindow.g.browser.controller.view.browser_browser.contentWindow.wrappedJSObject.location.href;
566         var content_params = { 'session' : ses(), 'authtime' : ses('authtime'), 'opac_url' : url };
567         content_params.url_prefix = xulG.url_prefix;
568         content_params.new_tab = xulG.new_tab;
569         content_params.set_tab = xulG.set_tab;
570         content_params.close_tab = xulG.close_tab;
571         content_params.new_patron_tab = xulG.new_patron_tab;
572         content_params.set_patron_tab = xulG.set_patron_tab;
573         content_params.volume_item_creator = xulG.volume_item_creator;
574         content_params.get_new_session = xulG.get_new_session;
575         content_params.holdings_maintenance_tab = xulG.holdings_maintenance_tab;
576         content_params.set_tab_name = xulG.set_tab_name;
577         content_params.open_chrome_window = xulG.open_chrome_window;
578         content_params.url_prefix = xulG.url_prefix;
579         content_params.network_meter = xulG.network_meter;
580         content_params.page_meter = xulG.page_meter;
581         content_params.set_statusbar = xulG.set_statusbar;
582         content_params.set_help_context = xulG.set_help_context;
583
584         xulG.new_tab(xulG.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
585     } catch(E) {
586         g.error.sdump('D_ERROR',E);
587     }
588 }
589
590 function batch_receive_in_new_tab() {
591     try {
592         var content_params = {"session": ses(), "authtime": ses("authtime")};
593
594         ["url_prefix", "new_tab", "set_tab", "close_tab", "new_patron_tab",
595             "set_patron_tab", "volume_item_creator", "get_new_session",
596             "holdings_maintenance_tab", "set_tab_name", "open_chrome_window",
597             "url_prefix", "network_meter", "page_meter", "set_statusbar",
598             "set_help_context"
599         ].forEach(function(k) { content_params[k] = xulG[k]; });
600
601         xulG.new_tab(
602             xulG.url_prefix(urls.XUL_SERIAL_BATCH_RECEIVE) +
603                 "?docid=" + window.escape(docid), {
604                 "tab_name": $("offlineStrings").getString(
605                     "menu.cmd_serial_batch_receive.tab"
606                 )
607             }, content_params
608         );
609     } catch (E) {
610         g.error.sdump("D_ERROR", E);
611     }
612 }
613
614 function remove_me() {
615     var url = xulG.url_prefix( urls.XUL_BIB_BRIEF ) + '?docid=' + window.escape(docid);
616     dump('removing ' + url + '\n');
617     try { top_pane.remove_iframe( url ); } catch(E) { dump(E + '\n'); }
618     $('nav').setAttribute('hidden','true');
619 }
620
621 function add_to_bucket() {
622     JSAN.use('util.window'); var win = new util.window();
623     win.open(
624         xulG.url_prefix(urls.XUL_RECORD_BUCKETS_QUICK),
625         'sel_bucket_win' + win.window_name_increment(),
626         'chrome,resizable,modal,centerscreen',
627         {
628             record_ids: [ docid ]
629         }
630     );
631 }
632
633 function mark_for_overlay() {
634     g.data.marked_record = docid;
635     g.data.stash('marked_record');
636     var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
637     if (typeof robj.ilsevent == 'undefined') {
638         g.data.marked_record_mvr = robj;
639     } else {
640         g.data.marked_record_mvr = null;
641         g.error.standard_unexpected_error_alert('in mark_for_overlay',robj);
642     }
643     g.data.stash('marked_record_mvr');
644     if (g.data.marked_record_mvr) {
645         alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.tcn.alert',[ g.data.marked_record_mvr.tcn() ]));
646         xulG.set_statusbar(1, $("offlineStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.tcn.label',[g.data.marked_record_mvr.tcn()]) );
647     } else {
648         alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_marked_for_overlay.record_id.alert',[ g.data.marked_record  ]));
649         xulG.set_statusbar(1, $("offlineStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.record_id.label',[g.data.marked_record]) );
650     }
651 }
652
653 function mark_for_hold_transfer() {
654     g.data.marked_record_for_hold_transfer = docid;
655     g.data.stash('marked_record_for_hold_transfer');
656     var robj = g.network.simple_request('MODS_SLIM_RECORD_RETRIEVE.authoritative',[docid]);
657     if (typeof robj.ilsevent == 'undefined') {
658         g.data.marked_record_for_hold_transfer_mvr = robj;
659     } else {
660         g.data.marked_record_for_hold_transfer_mvr = null;
661         g.error.standard_unexpected_error_alert('in mark_for_hold_transfer',robj);
662     }
663     g.data.stash('marked_record_for_hold_transfer_mvr');
664     if (g.data.marked_record_mvr) {
665         var m = $("offlineStrings").getFormattedString('staff.cat.opac.marked_record_for_hold_transfer_indicator.tcn.label',[g.data.marked_record_for_hold_transfer_mvr.tcn()]);
666         alert(m); xulG.set_statusbar(1, m );
667     } else {
668         var m = $("offlineStrings").getFormattedString('staff.cat.opac.marked_record_for_hold_transfer_indicator.record_id.label',[g.data.marked_record_for_hold_transfer]);
669         alert(m); xulG.set_statusbar(1, m );
670     }
671 }
672
673 function transfer_title_holds() {
674     g.data.stash_retrieve();
675     var target = g.data.marked_record_for_hold_transfer;
676     if (!target) {
677         var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.destination_needed.label');
678         alert(m);
679         return;
680     }
681     var robj = g.network.simple_request('TRANSFER_TITLE_HOLDS',[ ses(), target, [ docid ] ]);
682     if (robj == 1) {
683         var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.success.label');
684         alert(m);
685     } else {
686         var m = $("offlineStrings").getString('staff.cat.opac.title_for_hold_transfer.failure.label');
687         alert(m);
688     }
689     hold_browser_reset = true;
690     if (g.view == 'hold_browser') { set_hold_browser(); };
691 }
692
693 function delete_record() {
694     if (g.error.yns_alert(
695         document.getElementById('offlineStrings').getFormattedString('cat.opac.delete_record.confirm', [docid]),
696         document.getElementById('offlineStrings').getString('cat.opac.delete_record'),
697         document.getElementById('offlineStrings').getString('cat.opac.delete'),
698         document.getElementById('offlineStrings').getString('cat.opac.cancel'),
699         null,
700         document.getElementById('offlineStrings').getString('cat.opac.record_deleted.confirm')) == 0) {
701         var robj = g.network.simple_request('FM_BRE_DELETE',[ses(),docid]);
702         if (typeof robj.ilsevent != 'undefined') {
703             alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error',  [docid, robj.textcode, robj.desc]) + '\n');
704         } else {
705             alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
706             refresh_display(docid);
707         }
708     }
709 }
710
711 function undelete_record() {
712     if (g.error.yns_alert(
713         document.getElementById('offlineStrings').getFormattedString('cat.opac.undelete_record.confirm', [docid]),
714         document.getElementById('offlineStrings').getString('cat.opac.undelete_record'),
715         document.getElementById('offlineStrings').getString('cat.opac.undelete'),
716         document.getElementById('offlineStrings').getString('cat.opac.cancel'),
717         null,
718         document.getElementById('offlineStrings').getString('cat.opac.record_undeleted.confirm')) == 0) {
719
720         var robj = g.network.simple_request('FM_BRE_UNDELETE',[ses(),docid]);
721         if (typeof robj.ilsevent != 'undefined') {
722             alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_undeleted.error',  [docid, robj.textcode, robj.desc]) + '\n');
723         } else {
724             alert(document.getElementById('offlineStrings').getString('cat.opac.record_undeleted'));
725             refresh_display(docid);
726         }
727     }
728 }
729
730 function refresh_display(id) {
731     try { 
732         marc_view_reset = true;
733         marc_edit_reset = true;
734         copy_browser_reset = true;
735         hold_browser_reset = true;
736         while(top_pane.node.lastChild) top_pane.node.removeChild( top_pane.node.lastChild );
737         var children = bottom_pane.node.childNodes;
738         for (var i = 0; i < children.length; i++) {
739             if (children[i] != browser_frame) bottom_pane.node.removeChild(children[i]);
740         }
741
742         set_brief_view();
743         $('nav').setAttribute('hidden','false');
744         var settings = g.network.simple_request(
745             'FM_AUS_RETRIEVE',
746             [ ses(), g.data.list.au[0].id() ]
747         );
748         var view = settings['staff_client.catalog.record_view.default'];
749         if (g.view_override) {
750             view = g.view_override;
751             g.view_override = null;
752         }
753         switch(view) {
754             case 'marc_view' : set_marc_view(); break;
755             case 'marc_edit' : set_marc_edit(); break;
756             case 'copy_browser' : set_copy_browser(); break;
757             case 'hold_browser' : set_hold_browser(); break;
758             case 'serctrl_view' : set_serctrl_view(); break;
759             case 'opac' :
760             default: set_opac(); break;
761         }
762         opac_wrapper_set_help_context(); 
763     } catch(E) {
764         g.error.standard_unexpected_error_alert('in refresh_display',E);
765     }
766 }
767
768 function set_default() {
769     var robj = g.network.simple_request(
770         'FM_AUS_UPDATE',
771         [ ses(), g.data.list.au[0].id(), { 'staff_client.catalog.record_view.default' : g.view } ]
772     )
773     if (typeof robj.ilsevent != 'undefined') {
774         if (robj.ilsevent != 0) g.error.standard_unexpected_error_alert(document.getElementById('offlineStrings').getString('cat.preference.error'), robj);
775     }
776 }
777
778 function add_volumes() {
779     try {
780         var edit = 0;
781         try {
782             edit = g.network.request(
783                 api.PERM_MULTI_ORG_CHECK.app,
784                 api.PERM_MULTI_ORG_CHECK.method,
785                 [ 
786                     ses(), 
787                     ses('staff_id'), 
788                     [ ses('ws_ou') ],
789                     [ 'CREATE_VOLUME', 'CREATE_COPY' ]
790                 ]
791             ).length == 0 ? 1 : 0;
792         } catch(E) {
793             g.error.sdump('D_ERROR','batch permission check: ' + E);
794         }
795
796         if (edit==0) {
797             alert(document.getElementById('offlineStrings').getString('staff.circ.copy_status.add_volumes.perm_failure'));
798             return; // no read-only view for this interface
799         }
800
801         var title = document.getElementById('offlineStrings').getFormattedString('staff.circ.copy_status.add_volumes.title', [docid]);
802
803         JSAN.use('util.window'); var win = new util.window();
804         var w = win.open(
805             window.xulG.url_prefix(urls.XUL_VOLUME_COPY_CREATOR),
806             title,
807             'chrome,resizable',
808             { 'doc_id' : docid, 'ou_ids' : [ ses('ws_ou') ] }
809         );
810     } catch(E) {
811         alert('Error in chrome/content/cat/opac.js, add_volumes(): ' + E);
812     }
813 }