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