edf589bc833ef79bd1ba8d096cba4a4a982ae8b9
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / patron / holds.js
1 dump('entering patron.holds.js\n');
2
3 function $(id) { return document.getElementById(id); }
4
5 if (typeof patron == 'undefined') patron = {};
6 patron.holds = function (params) {
7
8     JSAN.use('util.error'); this.error = new util.error();
9     JSAN.use('util.network'); this.network = new util.network();
10     JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
11 }
12
13 patron.holds.prototype = {
14
15     'hold_interface_type' : null,
16
17     'pull_from_shelf_interface' : {
18         '_default' : { 'limit' : 100, 'offset' : 0 },
19         'current' : { 'limit' : 100, 'offset' : 0 }
20     },
21
22     'filter_lib' : null,
23
24     'hold_subscription_map' : {},
25
26     'expired' : false,
27     'post_clear_shelf_hold_action_map' : {},
28
29     'retrieve_ids' : [],
30
31     'holds_map' : {},
32
33     'flatten_copy' : function(hold) {
34         try { if ( hold.current_copy() && typeof hold.current_copy() == 'object') hold.current_copy( hold.current_copy().id() ); } catch(E) { alert('FIXME: Error flattening hold before hold update: ' + E); }
35         return hold;
36     },
37
38     'init' : function( params ) {
39
40         var obj = this;
41
42         obj.patron_id = params['patron_id'];
43         obj.patron_barcode = params['patron_barcode'];
44         obj.docid = params['docid'];
45         obj.shelf = params['shelf'];
46         obj.tree_id = params['tree_id'];
47
48         var progressmeter = document.getElementById('progress');
49
50         JSAN.use('circ.util');
51         var columns = circ.util.hold_columns(
52             {
53                 'title' : { 'hidden' : false, 'flex' : '3' },
54                 'request_time' : { 'hidden' : false },
55                 'pickup_lib_shortname' : { 'hidden' : false },
56                 'hold_type' : { 'hidden' : false },
57                 'current_copy' : { 'hidden' : false },
58                 'capture_time' : { 'hidden' : false },
59                 'notify_time' : { 'hidden' : false },
60                 'notify_count' : { 'hidden' : false },
61                 'cancel_cause' : { 'hidden' : ! ( obj.data.hash.aous['circ.holds.canceled.display_count'] || obj.data.hash.aous['circ.holds.canceled.display_age'] ) },
62                 'cancel_note' : { 'hidden' :  ! ( obj.data.hash.aous['circ.holds.canceled.display_count'] || obj.data.hash.aous['circ.holds.canceled.display_age'] ) },
63                 'cancel_time' : { 'hidden' :  ! ( obj.data.hash.aous['circ.holds.canceled.display_count'] || obj.data.hash.aous['circ.holds.canceled.display_age'] ) },
64                 'post_clear_shelf_action' : { 'hidden' : obj.shelf ? false : true }
65             }
66         );
67
68         JSAN.use('util.list'); obj.list = new util.list( obj.tree_id || 'holds_list');
69         obj.list.init(
70             {
71                 'columns' : columns.concat(
72                     obj.list.fm_columns('acp', {
73                         '*' : { 'expanded_label' : true, 'hidden' : true },
74                         // example of unhiding some columns by default
75                         // 'acp_circ_modifier' : { 'hidden' : false }
76                     })
77                 ),
78                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
79                 'retrieve_row' : function(params) {
80                     var row = params.row;
81                     try {
82                         obj.network.simple_request('FM_AHR_BLOB_RETRIEVE.authoritative', [ ses(), row.my.hold_id ],
83                             function(blob_req) {
84                                 try {
85                                     var blob = blob_req.getResultObject();
86                                     if (typeof blob.ilsevent != 'undefined') throw(blob);
87                                     row.my.ahr = blob.hold;
88                                     row.my.status = blob.status;
89                                     row.my.ahr.status( blob.status );
90                                     row.my.acp = blob.copy;
91                                     row.my.acn = blob.volume;
92                                     row.my.mvr = blob.mvr;
93                                     row.my.part = blob.part;
94                                     row.my.issuance = blob.issuance;
95                                     if (blob.issuance) {
96                                         row.my.subscription = blob.issuance.subscription();
97                                         obj.hold_subscription_map[ row.my.hold_id ] = row.my.subscription;
98                                     }
99                                     row.my.patron_family_name = blob.patron_last;
100                                     row.my.patron_first_given_name = blob.patron_first;
101                                     row.my.patron_barcode = blob.patron_barcode;
102                                     row.my.patron_alias = blob.patron_alias;
103                                     row.my.total_holds = blob.total_holds;
104                                     row.my.queue_position = blob.queue_position;
105                                     row.my.potential_copies = blob.potential_copies;
106                                     row.my.estimated_wait = blob.estimated_wait;
107                                     row.my.ahrn_count = blob.hold.notes().length;
108
109                                     var copy_id = row.my.ahr.current_copy();
110                                     if (typeof copy_id == 'object') {
111                                         if (copy_id == null) {
112                                             if (typeof row.my.acp == 'object' && row.my.acp != null) copy_id = row.my.acp.id();
113                                         } else {
114                                             copy_id = copy_id.id();
115                                         }
116                                     } else {
117                                         copy_id = row.my.acp.id();
118                                     }
119
120                                     obj.holds_map[ row.my.ahr.id() ] = blob;
121                                     params.row_node.setAttribute('retrieve_id',
122                                         js2JSON({
123                                             'copy_id':copy_id,
124                                             'barcode':row.my.acp ? row.my.acp.barcode() : null,
125                                             'id':row.my.ahr.id(),
126                                             'type':row.my.ahr.hold_type(),
127                                             'target':row.my.ahr.target(),
128                                             'usr':row.my.ahr.usr()
129                                         })
130                                     );
131                                     if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
132
133                                 } catch(E) {
134                                     obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.holds.init.hold_num_error', [row.my.hold_id]), E);
135                                 }
136                             }
137                         );
138                     } catch(E) {
139                         obj.error.sdump('D_ERROR','retrieve_row: ' + E );
140                     }
141                     return row;
142                 },
143                 'on_select' : function(ev) {
144                     JSAN.use('util.functional');
145                     var sel = obj.list.retrieve_selection();
146                     obj.controller.view.sel_clip.setAttribute('disabled',sel.length < 1);
147                     obj.retrieve_ids = util.functional.map_list(
148                         sel,
149                         function(o) { return JSON2js( o.getAttribute('retrieve_id') ); }
150                     );
151                     if (obj.retrieve_ids.length > 0) {
152                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
153                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
154                         obj.controller.view.sel_copy_details.setAttribute('disabled','false');
155                         obj.controller.view.sel_patron.setAttribute('disabled','false');
156                         obj.controller.view.cmd_retrieve_patron.setAttribute('disabled','false');
157                         obj.controller.view.cmd_holds_edit_pickup_lib.setAttribute('disabled','false');
158                         obj.controller.view.cmd_holds_edit_desire_mint_condition.setAttribute('disabled','false');
159                         obj.controller.view.cmd_holds_edit_phone_notify.setAttribute('disabled','false');
160                         obj.controller.view.cmd_holds_edit_email_notify.setAttribute('disabled','false');
161                         obj.controller.view.cmd_holds_edit_selection_depth.setAttribute('disabled','false');
162                         obj.controller.view.cmd_holds_edit_expire_time.setAttribute('disabled','false');
163                         obj.controller.view.cmd_holds_edit_shelf_expire_time.setAttribute('disabled','false');
164                         obj.controller.view.cmd_holds_edit_thaw_date.setAttribute('disabled','false');
165                         obj.controller.view.cmd_holds_edit_request_date.setAttribute('disabled','false');
166                         obj.controller.view.cmd_holds_activate.setAttribute('disabled','false');
167                         obj.controller.view.cmd_holds_suspend.setAttribute('disabled','false');
168                         obj.controller.view.cmd_alt_view.setAttribute('rendering_rows','false');
169                         if (obj.controller.view.cmd_alt_view.getAttribute('ready')=='true') {
170                             obj.controller.view.cmd_alt_view.setAttribute('disabled','false');
171                         }
172                         obj.controller.view.cmd_holds_retarget.setAttribute('disabled','false');
173                         obj.controller.view.cmd_holds_cancel.setAttribute('disabled','false');
174                         obj.controller.view.cmd_holds_uncancel.setAttribute('disabled','false');
175                         obj.controller.view.cmd_show_catalog.setAttribute('disabled','false');
176                     } else {
177                         obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
178                         obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
179                         obj.controller.view.sel_copy_details.setAttribute('disabled','true');
180                         obj.controller.view.sel_patron.setAttribute('disabled','true');
181                         obj.controller.view.cmd_retrieve_patron.setAttribute('disabled','true');
182                         obj.controller.view.cmd_holds_edit_pickup_lib.setAttribute('disabled','true');
183                         obj.controller.view.cmd_holds_edit_desire_mint_condition.setAttribute('disabled','true');
184                         obj.controller.view.cmd_holds_edit_phone_notify.setAttribute('disabled','true');
185                         obj.controller.view.cmd_holds_edit_email_notify.setAttribute('disabled','true');
186                         obj.controller.view.cmd_holds_edit_selection_depth.setAttribute('disabled','true');
187                         obj.controller.view.cmd_holds_edit_expire_time.setAttribute('disabled','true');
188                         obj.controller.view.cmd_holds_edit_shelf_expire_time.setAttribute('disabled','true');
189                         obj.controller.view.cmd_holds_edit_thaw_date.setAttribute('disabled','true');
190                         obj.controller.view.cmd_holds_edit_request_date.setAttribute('disabled','true');
191                         obj.controller.view.cmd_holds_activate.setAttribute('disabled','true');
192                         obj.controller.view.cmd_holds_suspend.setAttribute('disabled','true');
193                         obj.controller.view.cmd_alt_view.setAttribute('disabled','true');
194                         obj.controller.view.cmd_alt_view.setAttribute('rendering_rows','true');
195                         obj.controller.view.cmd_holds_retarget.setAttribute('disabled','true');
196                         obj.controller.view.cmd_holds_cancel.setAttribute('disabled','true');
197                         obj.controller.view.cmd_holds_uncancel.setAttribute('disabled','true');
198                         obj.controller.view.cmd_show_catalog.setAttribute('disabled','true');
199                     }
200                 }
201             }
202         );
203
204         JSAN.use('util.controller'); obj.controller = new util.controller();
205         obj.controller.init(
206             {
207                 'control_map' : {
208                     'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
209                     'sel_clip' : [
210                         ['command'],
211                         function() { obj.list.clipboard(); }
212                     ],
213                     'cmd_broken' : [
214                         ['command'],
215                         function() { alert($("commonStrings").getString('common.unimplemented')); }
216                     ],
217                     'sel_patron' : [
218                         ['command'],
219                         function() {
220                             JSAN.use('circ.util');
221                             circ.util.show_last_few_circs(obj.retrieve_ids);
222                         }
223                     ],
224                     'alt_view_btn' : [
225                         ['render'],
226                         function(e) {
227                             e.setAttribute('label', document.getElementById("circStrings").getString('staff.circ.holds.alt_view.label'));
228                             e.setAttribute('accesskey', document.getElementById("circStrings").getString('staff.circ.holds.alt_view.accesskey'));
229                         }
230                     ],
231                     'cmd_alt_view' : [
232                         ['command'],
233                         function(ev) {
234                             try {
235                                 var n = obj.controller.view.alt_view_btn;
236                                 if (n.getAttribute('toggle') == '1') {
237                                     document.getElementById('deck').selectedIndex = 0;
238                                     n.setAttribute('toggle','0');
239                                     n.setAttribute('label', document.getElementById("circStrings").getString('staff.circ.holds.alt_view.label'));
240                                     n.setAttribute('accesskey', document.getElementById("circStrings").getString('staff.circ.holds.alt_view.accesskey'));
241                                 } else {
242                                     document.getElementById('deck').selectedIndex = 1;
243                                     n.setAttribute('toggle','1');
244                                     n.setAttribute('label', document.getElementById("circStrings").getString('staff.circ.holds.list_view.label'));
245                                     n.setAttribute('accesskey', document.getElementById("circStrings").getString('staff.circ.holds.list_view.accesskey'));
246                                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
247                                     if (obj.retrieve_ids.length == 0) return;
248                                     var f = obj.browser.get_content();
249                                     xulG.ahr_id = obj.retrieve_ids[0].id;
250                                     xulG.blob = obj.holds_map[ xulG.ahr_id ];
251                                     xulG.patron_rendered_elsewhere = (obj.hold_interface_type == 'patron');
252                                     xulG.bib_rendered_elsewhere = (obj.hold_interface_type == 'record');
253                                     f.xulG = xulG;
254                                     f.xulG.clear_and_retrieve = function() { obj.clear_and_retrieve(); };
255                                     f.fetch_and_render_all(true);
256                                 }
257                             } catch(E) {
258                                 alert('Error in holds.js, cmd_alt_view handler: ' + E);
259                             }
260                         },
261                     ],
262                     'cmd_cancelled_holds_view' : [
263                         ['command'],
264                         function(ev) {
265                             document.getElementById('show_cancelled_deck').selectedIndex = 1;
266                             /* For some reason attribute propogation on the <command> element isn't working with hidden */
267                             document.getElementById('holds_cancel_btn').setAttribute('hidden','true');
268                             document.getElementById('holds_uncancel_btn').setAttribute('hidden','false');
269                             document.getElementById('holds_cancel_btn2').setAttribute('hidden','true');
270                             document.getElementById('holds_uncancel_btn2').setAttribute('hidden','false');
271                             obj.clear_and_retrieve();
272                         }
273                     ],
274                     'cmd_uncancelled_holds_view' : [
275                         ['command'],
276                         function(ev) {
277                             document.getElementById('show_cancelled_deck').selectedIndex = 0;
278                             /* For some reason attribute propogation on the <command> element isn't working with hidden */
279                             document.getElementById('holds_cancel_btn').setAttribute('hidden','false');
280                             document.getElementById('holds_uncancel_btn').setAttribute('hidden','true');
281                             document.getElementById('holds_cancel_btn2').setAttribute('hidden','false');
282                             document.getElementById('holds_uncancel_btn2').setAttribute('hidden','true');
283                             obj.clear_and_retrieve();
284                         }
285                     ],
286                     'sel_mark_items_damaged' : [
287                         ['command'],
288                         function() {
289                             JSAN.use('cat.util'); JSAN.use('util.functional');
290                             cat.util.mark_item_damaged( util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
291                         }
292                     ],
293                     'sel_mark_items_missing' : [
294                         ['command'],
295                         function() {
296                             JSAN.use('cat.util'); JSAN.use('util.functional');
297                             cat.util.mark_item_missing( util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
298                         }
299                     ],
300                     'sel_copy_details' : [
301                         ['command'],
302                         function() {
303                             JSAN.use('circ.util');
304                             circ.util.item_details_new(
305                                 util.functional.map_list(
306                                     obj.retrieve_ids,
307                                     function(o) { return o.barcode; }
308                                 )
309                             );
310                         }
311                     ],
312                     'cmd_holds_print_full' : [
313                         ['command'],
314                         function() {
315                             var x_print_full_pull_list = document.getElementById('print_full_btn');
316                             try {
317                                 if (progressmeter) {
318                                     progressmeter.mode = 'undetermined';
319                                     progressmeter.hidden = false;
320                                     x_print_full_pull_list.disabled = true;
321                                 }
322                                 JSAN.use('util.print');
323                                 var print = new util.print('default');
324                                 var robj = fieldmapper.standardRequest(
325                                     [ api.HTML_HOLD_PULL_LIST.app, api.HTML_HOLD_PULL_LIST.method ],
326                                     {   async: false,
327                                         timeout: 180,
328                                         params: [ses()],
329                                     }
330                                 );
331                                 if (robj != null) {
332                                     if (typeof robj.ilsevent != 'undefined') { throw(robj); }
333                                     print.simple( robj.template_output().data() );
334                                 }
335                             } catch(E) {
336                                 obj.error.standard_unexpected_error_alert('cmd_holds_print_full',E);
337                             }
338                             if (progressmeter) {
339                                 progressmeter.mode = 'determined';
340                                 progressmeter.hidden = true;
341                                 x_print_full_pull_list.disabled = false;
342                             }
343                         }
344                     ],
345                     'cmd_holds_print_alt' : [
346                         ['command'],
347                         function() {
348                             try {
349                                 var content_params = {
350                                     "session": ses(),
351                                     "authtime": ses("authtime"),
352                                     "no_xulG": false,
353                                     "show_nav_buttons": true,
354                                     "show_print_button": true
355                                 };
356                                 ["url_prefix", "new_tab", "set_tab",
357                                     "close_tab", "new_patron_tab",
358                                     "set_patron_tab", "volume_item_creator",
359                                     "get_new_session",
360                                     "holdings_maintenance_tab", "set_tab_name",
361                                     "open_chrome_window", "url_prefix",
362                                     "network_meter", "page_meter",
363                                     "set_statusbar", "set_help_context"
364                                 ].forEach(function(k) {
365                                     content_params[k] = xulG[k];
366                                 });
367
368                                 var loc = urls.XUL_BROWSER + "?url=" + window.escape(
369                                     xulG.url_prefix("/opac/extras/circ/alt_holds_print.html").replace("http:","https:")
370                                 );
371                                 xulG.new_tab(
372                                     loc, {
373                                         "tab_name": "Printable Pull List", /* XXX i18n */
374                                         "browser": false
375                                     }, content_params
376                                 );
377                             } catch (E) {
378                                 g.error.sdump("D_ERROR", E);
379                             }
380                         }
381                     ],
382                     'cmd_holds_print' : [
383                         ['command'],
384                         function() {
385                             try {
386                                 JSAN.use('patron.util');
387                                 var params = {
388                                     'patron' : patron.util.retrieve_au_via_id(ses(),obj.patron_id),
389                                     'template' : 'holds'
390                                 };
391                                 obj.list.print(params);
392                             } catch(E) {
393                                 obj.error.standard_unexpected_error_alert('print 1',E);
394                             }
395                         }
396                     ],
397                     'cmd_csv_to_clipboard' : [ ['command'], function() { obj.list.dump_csv_to_clipboard(); } ],
398                     'cmd_csv_to_printer' : [ ['command'], function() { obj.list.dump_csv_to_printer(); } ],
399                     'cmd_csv_to_file' : [ ['command'], function() { obj.list.dump_csv_to_file( { 'defaultFileName' : 'holds.txt' } ); } ],
400
401                     'cmd_holds_edit_selection_depth' : [
402                         ['command'],
403                         function() {
404                             try {
405                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
406                                 var ws_type = obj.data.hash.aout[ obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].ou_type() ];
407                                 var list = util.functional.map_list(
408                                     util.functional.filter_list(
409                                         obj.data.list.aout,
410                                         function(o) {
411                                             if (o.depth() > ws_type.depth()) return false;
412                                             if (o.depth() < ws_type.depth()) return true;
413                                             return (o.id() == ws_type.id());
414                                         }
415                                     ),
416                                     function(o) {
417                                         return [
418                                             o.opac_label(),
419                                             o.id(),
420                                             false,
421                                             ( o.depth() * 2),
422                                         ];
423                                     }
424                                 );
425                                 ml = util.widgets.make_menulist( list, obj.data.list.au[0].ws_ou() );
426                                 ml.setAttribute('id','selection');
427                                 ml.setAttribute('name','fancy_data');
428                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
429                                 xml += '<description>' + $("patronStrings").getString('staff.patron.holds.holds_edit_selection_depth.choose_hold_range') + '</description>';
430                                 xml += util.widgets.serialize_node(ml);
431                                 xml += '</vbox>';
432                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
433                                 bot_xml += '<spacer flex="1"/><button label="'+ $("patronStrings").getString('staff.patron.holds.holds_edit_selection_depth.done.label') +'"';
434                                 bot_xml += 'accesskey="'+ $("patronStrings").getString('staff.patron.holds.holds_edit_selection_depth.done.accesskey') +'" name="fancy_submit"/>';
435                                 bot_xml += '<button label="'+ $("patronStrings").getString('staff.patron.holds.holds_edit_selection_depth.cancel.label') +'"';
436                                 bot_xml += 'accesskey="'+ $("patronStrings").getString('staff.patron.holds.holds_edit_selection_depth.cancel.accesskey') +'" name="fancy_cancel"/></hbox>';
437                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
438                                 //obj.data.temp_mid = xml; obj.data.stash('temp_mid');
439                                 //obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
440                                 JSAN.use('util.window'); var win = new util.window();
441                                 var fancy_prompt_data = win.open(
442                                     urls.XUL_FANCY_PROMPT,
443                                     //+ '?xml_in_stash=temp_mid'
444                                     //+ '&bottom_xml_in_stash=temp_bot'
445                                     //+ '&title=' + window.escape('Choose a Pick Up Library'),
446                                     'fancy_prompt', 'chrome,resizable,modal',
447                                     { 'xml' : xml, 'bottom_xml' : bot_xml, 'title' : $("patronStrings").getString('staff.patron.holds.holds_edit_selection_depth.choose_library') }
448                                 );
449                                 if (fancy_prompt_data.fancy_status == 'incomplete') { return; }
450                                 var selection = fancy_prompt_data.selection;
451
452                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
453                                 var msg = '';
454                                 if(obj.retrieve_ids.length > 1) {
455                                     msg = $("patronStrings").getformattedString('staff.patron.holds.holds_edit_selection_depth.modify_holds_message.plural', [hold_list.join(', '), obj.data.hash.aout[selection].opac_label()])
456                                 } else {
457                                     msg = $("patronStrings").getformattedString('staff.patron.holds.holds_edit_selection_depth.modify_holds_message.singular', [hold_list.join(', '), obj.data.hash.aout[selection].opac_label()])
458                                 }
459
460                                 var r = obj.error.yns_alert(msg,
461                                         $("patronStrings").getString('staff.patron.holds.holds_edit_selection_depth.modify_holds_title'),
462                                         $("commonStrings").getString('common.yes'),
463                                         $("commonStrings").getString('common.no'),
464                                         null,
465                                         $("commonStrings").getString('common.check_to_confirm')
466                                 );
467                                 if (r == 0) {
468                                     circ.util.batch_hold_update(hold_list, { 'selection_depth' : obj.data.hash.aout[selection].depth() }, { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } });
469                                 }
470                             } catch(E) {
471                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_not_modified'),E);
472                             }
473                         }
474                     ],
475
476                     'cmd_holds_edit_pickup_lib' : [
477                         ['command'],
478                         function() {
479                             try {
480                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
481
482                                 var list = util.functional.map_list(
483                                     obj.data.list.aou,
484                                     function(o) {
485                                         var sname = o.shortname(); for (i = sname.length; i < 20; i++) sname += ' ';
486                                         return [
487                                             o.name() ? sname + ' ' + o.name() : o.shortname(),
488                                             o.id(),
489                                             ( !isTrue(obj.data.hash.aout[ o.ou_type() ].can_have_users()) ),
490                                             ( obj.data.hash.aout[ o.ou_type() ].depth() * 2),
491                                         ];
492                                     }
493                                 );
494                                 ml = util.widgets.make_menulist( list, obj.data.list.au[0].ws_ou() );
495                                 ml.setAttribute('id','lib');
496                                 ml.setAttribute('name','fancy_data');
497                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
498                                 xml += '<description>'+$("patronStrings").getString('staff.patron.holds.holds_edit_pickup_lib.new_pickup_lib.description')+'</description>';
499                                 xml += util.widgets.serialize_node(ml);
500                                 xml += '</vbox>';
501                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
502                                 bot_xml += '<spacer flex="1"/><button label="'+ $("patronStrings").getString('staff.patron.holds.holds_edit_pickup_lib.done.label') +'"';
503                                 bot_xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_edit_pickup_lib.done.accesskey')+'" name="fancy_submit"/>';
504                                 bot_xml += '<button label="'+$("patronStrings").getString('staff.patron.holds.holds_edit_pickup_lib.cancel.label')+'"';
505                                 bot_xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_edit_pickup_lib.cancel.accesskey')+'" name="fancy_cancel"/></hbox>';
506                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
507                                 //obj.data.temp_mid = xml; obj.data.stash('temp_mid');
508                                 //obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
509                                 JSAN.use('util.window'); var win = new util.window();
510                                 var fancy_prompt_data = win.open(
511                                     urls.XUL_FANCY_PROMPT,
512                                     //+ '?xml_in_stash=temp_mid'
513                                     //+ '&bottom_xml_in_stash=temp_bot'
514                                     //+ '&title=' + window.escape('Choose a Pick Up Library'),
515                                     'fancy_prompt', 'chrome,resizable,modal',
516                                     { 'xml' : xml, 'bottom_xml' : bot_xml, 'title' : $("patronStrings").getString('staff.patron.holds.holds_edit_pickup_lib.choose_lib') }
517                                 );
518                                 if (fancy_prompt_data.fancy_status == 'incomplete') { return; }
519                                 var pickup_lib = fancy_prompt_data.lib;
520
521                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
522                                 var msg = '';
523                                 if(obj.retrieve_ids.length > 1) {
524                                     msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_edit_pickup_lib.change_pickup_lib_message.plural',[hold_list.join(', '), obj.data.hash.aou[pickup_lib].shortname()]);
525                                 } else {
526                                     msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_edit_pickup_lib.change_pickup_lib_message.singular',[hold_list.join(', '), obj.data.hash.aou[pickup_lib].shortname()]);
527                                 }
528                                 var r = obj.error.yns_alert(msg,
529                                         $("patronStrings").getString('staff.patron.holds.holds_edit_pickup_lib.change_pickup_lib_title'),
530                                         $("commonStrings").getString('common.yes'),
531                                         $("commonStrings").getString('common.no'),
532                                         null,
533                                         $("commonStrings").getString('common.check_to_confirm')
534                                 );
535                                 if (r == 0) {
536                                     circ.util.batch_hold_update(hold_list, { 'pickup_lib' : pickup_lib }, { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } });
537                                 }
538                             } catch(E) {
539                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_not_modified'),E);
540                             }
541                         }
542                     ],
543                     'cmd_holds_edit_phone_notify' : [
544                         ['command'],
545                         function() {
546                             try {
547                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
548                                 xml += '<description>'+$("patronStrings").getString('staff.patron.holds.holds_edit_phone_notify.new_phone_number')+'</description>';
549                                 xml += '<textbox id="phone" name="fancy_data" context="clipboard"/>';
550                                 xml += '</vbox>';
551                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
552                                 bot_xml += '<spacer flex="1"/><button label="'+$("patronStrings").getString('staff.patron.holds.holds_edit_phone_notify.btn_done.label')+'"';
553                                 bot_xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_edit_phone_notify.btn_done.accesskey')+'" name="fancy_submit"/>';
554                                 bot_xml += '<button label="'+$("patronStrings").getString('staff.patron.holds.holds_edit_phone_notify.btn_cancel.label')+'"';
555                                 bot_xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_edit_phone_notify.btn_cancel.accesskey')+'" name="fancy_cancel"/></hbox>';
556                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
557                                 //obj.data.temp_mid = xml; obj.data.stash('temp_mid');
558                                 //obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
559                                 JSAN.use('util.window'); var win = new util.window();
560                                 var fancy_prompt_data = win.open(
561                                     urls.XUL_FANCY_PROMPT,
562                                     //+ '?xml_in_stash=temp_mid'
563                                     //+ '&bottom_xml_in_stash=temp_bot'
564                                     //+ '&title=' + window.escape('Choose a Hold Notification Phone Number')
565                                     //+ '&focus=phone',
566                                     'fancy_prompt', 'chrome,resizable,modal',
567                                     { 'xml' : xml, 'bottom_xml' : bot_xml, 'title' : $("patronStrings").getString('staff.patron.holds.holds_edit_phone_notify.choose_phone_number'), 'focus' : 'phone' }
568                                 );
569                                 if (fancy_prompt_data.fancy_status == 'incomplete') { return; }
570                                 var phone = fancy_prompt_data.phone;
571
572                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
573                                 var msg = '';
574                                 if(obj.retrieve_ids.length > 1) {
575                                     msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_edit_phone_notify.confirm_phone_number_change.plural',[hold_list.join(', '), phone]);
576                                 } else {
577                                     msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_edit_phone_notify.confirm_phone_number_change.singular',[hold_list.join(', '), phone]);
578                                 }
579                                 var r = obj.error.yns_alert(msg,
580                                         $("patronStrings").getString('staff.patron.holds.holds_edit_phone_notify.modifying_holds_title'),
581                                         $("commonStrings").getString('common.yes'),
582                                         $("commonStrings").getString('common.no'),
583                                         null,
584                                         $("commonStrings").getString('common.check_to_confirm')
585                                 );
586                                 if (r == 0) {
587                                     circ.util.batch_hold_update(hold_list, { 'phone_notify' : phone }, { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } });
588                                 }
589                             } catch(E) {
590                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_not_modified'),E);
591                             }
592                         }
593                     ],
594                     'cmd_holds_edit_email_notify' : [
595                         ['command'],
596                         function() {
597                             try {
598                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
599                                 xml += '<description>'+$("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.description')+'</description>';
600                                 xml += '<hbox><button value="email" label="'+$("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.btn_email.label')+'"';
601                                 xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.btn_email.accesskey')+'" name="fancy_submit"/>';
602                                 xml += '<button value="noemail" label="'+$("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.btn_no_email.label')+'"';
603                                 xml += '  accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.btn_no_email.accesskey')+'" name="fancy_submit"/></hbox>';
604                                 xml += '</vbox>';
605                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
606                                 bot_xml += '<spacer flex="1"/><button label="'+$("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.btn_cancel.label')+'"';
607                                 bot_xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.btn_cancel.accesskey')+'" name="fancy_cancel"/></hbox>';
608                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
609                                 //obj.data.temp_mid = xml; obj.data.stash('temp_mid');
610                                 //obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
611                                 JSAN.use('util.window'); var win = new util.window();
612                                 var fancy_prompt_data = win.open(
613                                     urls.XUL_FANCY_PROMPT,
614                                     //+ '?xml_in_stash=temp_mid'
615                                     //+ '&bottom_xml_in_stash=temp_bot'
616                                     //+ '&title=' + window.escape('Set Email Notification for Holds'),
617                                     'fancy_prompt', 'chrome,resizable,modal',
618                                     { 'xml' : xml, 'bottom_xml' : bot_xml, 'title' : $("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.set_notifs') }
619                                 );
620                                 if (fancy_prompt_data.fancy_status == 'incomplete') { return; }
621                                 var email = fancy_prompt_data.fancy_submit == 'email' ? get_db_true() : get_db_false();
622
623                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
624                                 var msg = '';
625                                 if(get_bool(email)) {
626                                     if(obj.retrieve_ids.length > 1) {
627                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_edit_email_notify.enable_email.plural', [hold_list.join(', ')]);
628                                     } else {
629                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_edit_email_notify.enable_email.singular', [hold_list.join(', ')]);
630                                     }
631                                 } else {
632                                     if(obj.retrieve_ids.length > 1) {
633                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_edit_email_notify.disable_email.plural', [hold_list.join(', ')]);
634                                     } else {
635                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_edit_email_notify.disable_email.singular', [hold_list.join(', ')]);
636                                     }
637                                 }
638
639                                 var r = obj.error.yns_alert(msg,
640                                         $("patronStrings").getString('staff.patron.holds.holds_edit_email_notify.mod_holds_title'),
641                                         $("commonStrings").getString('common.yes'),
642                                         $("commonStrings").getString('common.no'),
643                                         null,
644                                         $("commonStrings").getString('common.check_to_confirm')
645                                 );
646                                 if (r == 0) {
647                                     circ.util.batch_hold_update(hold_list, { 'email_notify' : email }, { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } });
648                                 }
649                             } catch(E) {
650                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_not_modified'),E);
651                             }
652                         }
653                     ],
654                     'cmd_holds_cut_in_line' : [
655                         ['command'],
656                         function() {
657                             try {
658                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
659                                 xml += '<description>'+$("patronStrings").getString('staff.patron.holds.holds_cut_in_line.description')+'</description>';
660                                 xml += '<hbox><button value="cut" label="'+$("patronStrings").getString('staff.patron.holds.holds_cut_in_line.btn_cut.label')+'"';
661                                 xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_cut_in_line.btn_cut.accesskey')+'" name="fancy_submit"/>';
662                                 xml += '<button value="nocut" label="'+$("patronStrings").getString('staff.patron.holds.holds_cut_in_line.btn_no_cut.label')+'"';
663                                 xml += '  accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_cut_in_line.btn_no_cut.accesskey')+'" name="fancy_submit"/></hbox>';
664                                 xml += '</vbox>';
665                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
666                                 bot_xml += '<spacer flex="1"/><button label="'+$("patronStrings").getString('staff.patron.holds.holds_cut_in_line.btn_cancel.label')+'"';
667                                 bot_xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_cut_in_line.btn_cancel.accesskey')+'" name="fancy_cancel"/></hbox>';
668                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
669                                 JSAN.use('util.window'); var win = new util.window();
670                                 var fancy_prompt_data = win.open(
671                                     urls.XUL_FANCY_PROMPT,
672                                     'fancy_prompt', 'chrome,resizable,modal',
673                                     { 'xml' : xml, 'bottom_xml' : bot_xml, 'title' : $("patronStrings").getString('staff.patron.holds.holds_cut_in_line.set_notifs') }
674                                 );
675                                 if (fancy_prompt_data.fancy_status == 'incomplete') { return; }
676                                 var cut = fancy_prompt_data.fancy_submit == 'cut' ? get_db_true() : get_db_false();
677
678                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
679                                 var msg = '';
680                                 if(get_bool(cut)) {
681                                     if(obj.retrieve_ids.length > 1) {
682                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_cut_in_line.enable_cut.plural', [hold_list.join(', ')]);
683                                     } else {
684                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_cut_in_line.enable_cut.singular', [hold_list.join(', ')]);
685                                     }
686                                 } else {
687                                     if(obj.retrieve_ids.length > 1) {
688                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_cut_in_line.disable_cut.plural', [hold_list.join(', ')]);
689                                     } else {
690                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_cut_in_line.disable_cut.singular', [hold_list.join(', ')]);
691                                     }
692                                 }
693
694                                 var r = obj.error.yns_alert(msg,
695                                         $("patronStrings").getString('staff.patron.holds.holds_cut_in_line.mod_holds_title'),
696                                         $("commonStrings").getString('common.yes'),
697                                         $("commonStrings").getString('common.no'),
698                                         null,
699                                         $("commonStrings").getString('common.check_to_confirm')
700                                 );
701                                 if (r == 0) {
702                                     circ.util.batch_hold_update(hold_list, { 'cut_in_line' : cut }, { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } });
703                                 }
704                             } catch(E) {
705                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_not_modified'),E);
706                             }
707                         }
708                     ],
709                     'cmd_holds_edit_desire_mint_condition' : [
710                         ['command'],
711                         function() {
712                             try {
713                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
714                                 xml += '<description>'+$("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.description')+'</description>';
715                                 xml += '<hbox><button value="good" label="'+$("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.btn_good.label')+'"';
716                                 xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.btn_good.accesskey')+'" name="fancy_submit"/>';
717                                 xml += '<button value="nogood" label="'+$("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.btn_mediocre.label')+'"';
718                                 xml += '  accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.btn_mediocre.accesskey')+'" name="fancy_submit"/></hbox>';
719                                 xml += '</vbox>';
720                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
721                                 bot_xml += '<spacer flex="1"/><button label="'+$("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.btn_cancel.label')+'"';
722                                 bot_xml += ' accesskey="'+$("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.btn_cancel.accesskey')+'" name="fancy_cancel"/></hbox>';
723                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
724                                 JSAN.use('util.window'); var win = new util.window();
725                                 var fancy_prompt_data = win.open(
726                                     urls.XUL_FANCY_PROMPT,
727                                     'fancy_prompt', 'chrome,resizable,modal',
728                                     { 'xml' : xml, 'bottom_xml' : bot_xml, 'title' : $("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.set_notifs') }
729                                 );
730                                 if (fancy_prompt_data.fancy_status == 'incomplete') { return; }
731                                 var good = fancy_prompt_data.fancy_submit == 'good' ? get_db_true() : get_db_false();
732
733                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
734                                 var msg = '';
735                                 if(get_bool(good)) {
736                                     if(obj.retrieve_ids.length > 1) {
737                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_desire_mint_condition.enable_good.plural', [hold_list.join(', ')]);
738                                     } else {
739                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_desire_mint_condition.enable_good.singular', [hold_list.join(', ')]);
740                                     }
741                                 } else {
742                                     if(obj.retrieve_ids.length > 1) {
743                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_desire_mint_condition.disable_good.plural', [hold_list.join(', ')]);
744                                     } else {
745                                         msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_desire_mint_condition.disable_good.singular', [hold_list.join(', ')]);
746                                     }
747                                 }
748
749                                 var r = obj.error.yns_alert(msg,
750                                         $("patronStrings").getString('staff.patron.holds.holds_desire_mint_condition.mod_holds_title'),
751                                         $("commonStrings").getString('common.yes'),
752                                         $("commonStrings").getString('common.no'),
753                                         null,
754                                         $("commonStrings").getString('common.check_to_confirm')
755                                 );
756                                 if (r == 0) {
757                                     circ.util.batch_hold_update(hold_list, { 'mint_condition' : good }, { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } });
758                                 }
759                             } catch(E) {
760                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_not_modified'),E);
761                             }
762                         }
763                     ],
764
765
766                     'cmd_holds_suspend' : [
767                         ['command'],
768                         function() {
769                             try {
770                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
771                                 var r = obj.error.yns_alert(
772                                     obj.retrieve_ids.length > 1 ?
773                                     document.getElementById('circStrings').getFormattedString('staff.circ.holds.suspend.prompt.plural',[hold_list.join(', ')]) :
774                                     document.getElementById('circStrings').getFormattedString('staff.circ.holds.suspend.prompt',[hold_list.join(', ')]),
775                                     document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds'),
776                                     document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds.yes'),
777                                     document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds.no'),
778                                     null,
779                                     document.getElementById('commonStrings').getString('common.confirm')
780                                 );
781                                 if (r == 0) {
782                                     var already_suspended = []; var filtered_hold_list = [];
783                                     for (var i = 0; i < obj.retrieve_ids.length; i++) {
784                                         var hold = obj.holds_map[ obj.retrieve_ids[i].id ].hold;
785                                         if ( get_bool( hold.frozen() ) ) {
786                                             already_suspended.push( hold.id() );
787                                             continue;
788                                         }
789                                         filtered_hold_list.push( hold.id() );
790                                     }
791                                     circ.util.batch_hold_update(filtered_hold_list, { 'frozen' : 't', 'thaw_date' : null }, { 'progressmeter' : progressmeter, 'oncomplete' :  function() { 
792                                         if (already_suspended.length == 1) {
793                                             alert( document.getElementById('circStrings').getFormattedString('staff.circ.holds.already_suspended',[already_suspended[0]]) );
794                                         } else if (already_suspended.length > 1) {
795                                             alert( document.getElementById('circStrings').getFormattedString('staff.circ.holds.already_suspended.plural',[already_suspended.join(', ')]) );
796                                         }
797                                         obj.clear_and_retrieve(true); 
798                                     } });
799                                 }
800                             } catch(E) {
801                                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.holds.unexpected_error.not_likely_suspended'),E);
802                             }
803                         }
804                     ],
805                     'cmd_holds_activate' : [
806                         ['command'],
807                         function() {
808                             try {
809                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
810                                 var r = obj.error.yns_alert(
811                                     obj.retrieve_ids.length > 1 ?
812                                     document.getElementById('circStrings').getFormattedString('staff.circ.holds.activate.prompt.plural',[hold_list.join(', ')]) :
813                                     document.getElementById('circStrings').getFormattedString('staff.circ.holds.activate.prompt',[hold_list.join(', ')]),
814                                     document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds'),
815                                     document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds.yes'),
816                                     document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds.no'),
817                                     null,
818                                     document.getElementById('commonStrings').getString('common.confirm')
819                                 );
820                                 if (r == 0) {
821                                     var already_activated = []; var filtered_hold_list = [];
822                                     for (var i = 0; i < obj.retrieve_ids.length; i++) {
823                                         var hold = obj.holds_map[ obj.retrieve_ids[i].id ].hold;
824                                         if ( ! get_bool( hold.frozen() ) ) {
825                                             already_activated.push( hold.id() );
826                                             continue;
827                                         }
828                                         filtered_hold_list.push( hold.id() );
829                                     }
830                                     circ.util.batch_hold_update(filtered_hold_list, { 'frozen' : 'f', 'thaw_date' : null }, { 'progressmeter' : progressmeter, 'oncomplete' :  function() { 
831                                         if (already_activated.length == 1) {
832                                             alert( document.getElementById('circStrings').getFormattedString('staff.circ.holds.already_activated',[already_activated[0]]) );
833                                         } else if (already_activated.length > 1) {
834                                             alert( document.getElementById('circStrings').getFormattedString('staff.circ.holds.already_activated.plural',[already_activated.join(', ')]) );
835                                         }
836                                         obj.clear_and_retrieve(true); 
837                                     } });
838                                 }
839                             } catch(E) {
840                                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.holds.unexpected_error.not_likely_activated'),E);
841                             }
842                         }
843                     ],
844                     'cmd_holds_edit_thaw_date' : [
845                         ['command'],
846                         function() {
847                             try {
848                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
849                                 var msg_singular = document.getElementById('circStrings').getFormattedString('staff.circ.holds.activation_date.prompt',[hold_list.join(', ')]);
850                                 var msg_plural = document.getElementById('circStrings').getFormattedString('staff.circ.holds.activation_date.prompt.plural',[hold_list.join(', ')]);
851                                 var msg = obj.retrieve_ids.length > 1 ? msg_plural : msg_singular;
852                                 var title = document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds');
853                                 var desc = document.getElementById('circStrings').getString('staff.circ.holds.activation_date.dialog.description');
854
855                                 JSAN.use('util.window'); var win = new util.window();
856                                 var my_xulG = win.open( 
857                                     urls.XUL_TIMESTAMP_DIALOG, 'edit_thaw_date', 'chrome,resizable,modal', 
858                                     { 
859                                         'title' : title, 
860                                         'description' : desc, 
861                                         'msg' : msg, 
862                                         'allow_unset' : true,
863                                         'disallow_future_dates' : false,
864                                         'disallow_past_dates' : true,
865                                         'disallow_today' : true,
866                                         'default_time' : '00:00:00',
867                                         'time_readonly' : false
868                                     }
869                                 );
870                                 if (my_xulG.complete) {
871                                     circ.util.batch_hold_update(
872                                         hold_list, 
873                                         { 'frozen' : 't', 'thaw_date' : my_xulG.timestamp }, 
874                                         { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } }
875                                     );
876                                 }
877                             } catch(E) {
878                                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.holds.unexpected_error.not_likely_modified'),E);
879                             }
880                         }
881                     ],
882                     'cmd_holds_edit_expire_time' : [
883                         ['command'],
884                         function() {
885                             try {
886                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
887                                 var msg_singular = document.getElementById('circStrings').getFormattedString('staff.circ.holds.expire_time.prompt',[hold_list.join(', ')]);
888                                 var msg_plural = document.getElementById('circStrings').getFormattedString('staff.circ.holds.expire_time.prompt.plural',[hold_list.join(', ')]);
889                                 var msg = obj.retrieve_ids.length > 1 ? msg_plural : msg_singular;
890                                 var value = 'YYYY-MM-DD';
891                                 var title = document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds');
892                                 var desc = document.getElementById('circStrings').getString('staff.circ.holds.expire_time.dialog.description');
893
894                                 JSAN.use('util.window'); var win = new util.window();
895                                 var my_xulG = win.open( 
896                                     urls.XUL_TIMESTAMP_DIALOG, 'edit_expire_time', 'chrome,resizable,modal', 
897                                     { 
898                                         'title' : title, 
899                                         'description' : desc, 
900                                         'msg' : msg, 
901                                         'allow_unset' : true,
902                                         'disallow_future_dates' : false,
903                                         'disallow_past_dates' : true,
904                                         'disallow_today' : true,
905                                         'default_time' : '00:00:00',
906                                         'time_readonly' : false
907                                     }
908                                 );
909                                 if (my_xulG.complete) {
910                                     circ.util.batch_hold_update(
911                                         hold_list, 
912                                         { 'expire_time' : my_xulG.timestamp }, 
913                                         { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } }
914                                     );
915                                 }
916                             } catch(E) {
917                                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.holds.unexpected_error.not_likely_modified'),E);
918                             }
919                         }
920                     ],
921                     'cmd_holds_edit_shelf_expire_time' : [
922                         ['command'],
923                         function() {
924                             try {
925                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
926                                 var msg_singular = document.getElementById('circStrings').getFormattedString('staff.circ.holds.shelf_expire_time.prompt',[hold_list.join(', ')]);
927                                 var msg_plural = document.getElementById('circStrings').getFormattedString('staff.circ.holds.shelf_expire_time.prompt.plural',[hold_list.join(', ')]);
928                                 var msg = obj.retrieve_ids.length > 1 ? msg_plural : msg_singular;
929                                 var title = document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds');
930                                 var desc = document.getElementById('circStrings').getString('staff.circ.holds.shelf_expire_time.dialog.description');
931
932                                 JSAN.use('util.window'); var win = new util.window();
933                                 var my_xulG = win.open( 
934                                     urls.XUL_TIMESTAMP_DIALOG, 'edit_shelf_expire_time', 'chrome,resizable,modal', 
935                                     { 
936                                         'title' : title, 
937                                         'description' : desc, 
938                                         'msg' : msg, 
939                                         'allow_unset' : false,
940                                         'disallow_future_dates' : false,
941                                         'disallow_past_dates' : false,
942                                         'disallow_today' : false
943                                     }
944                                 );
945                                 if (my_xulG.complete) {
946                                     circ.util.batch_hold_update(
947                                         hold_list, 
948                                         { 'shelf_expire_time' : my_xulG.timestamp }, 
949                                         { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } }
950                                     );
951                                 }
952                             } catch(E) {
953                                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.holds.unexpected_error.not_likely_modified'),E);
954                             }
955                         }
956                     ],
957                     'cmd_holds_edit_request_date' : [
958                         ['command'],
959                         function() {
960                             try {
961                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
962                                 var msg_singular = document.getElementById('circStrings').getFormattedString('staff.circ.holds.request_date.prompt',[hold_list.join(', ')]);
963                                 var msg_plural = document.getElementById('circStrings').getFormattedString('staff.circ.holds.request_date.prompt.plural',[hold_list.join(', ')]);
964                                 var msg = obj.retrieve_ids.length > 1 ? msg_plural : msg_singular;
965                                 var title = document.getElementById('circStrings').getString('staff.circ.holds.modifying_holds');
966                                 var desc = document.getElementById('circStrings').getString('staff.circ.holds.request_date.dialog.description');
967
968                                 JSAN.use('util.window'); var win = new util.window();
969                                 var my_xulG = win.open( 
970                                     urls.XUL_TIMESTAMP_DIALOG, 'edit_request_date', 'chrome,resizable,modal', 
971                                     { 
972                                         'title' : title, 
973                                         'description' : desc, 
974                                         'msg' : msg, 
975                                         'allow_unset' : false,
976                                         'disallow_future_dates' : true,
977                                         'disallow_past_dates' : false,
978                                         'disallow_today' : false
979                                     }
980                                 );
981                                 if (my_xulG.complete) {
982                                     circ.util.batch_hold_update(
983                                         hold_list, 
984                                         { 'request_time' : my_xulG.timestamp }, 
985                                         { 'progressmeter' : progressmeter, 'oncomplete' :  function() { obj.clear_and_retrieve(true); } }
986                                     );
987                                 }
988                             } catch(E) {
989                                 obj.error.standard_unexpected_error_alert(document.getElementById('circStrings').getString('staff.circ.holds.unexpected_error.not_likely_modified'),E);
990                             }
991                         }
992                     ],
993                     'cmd_holds_retarget' : [
994                         ['command'],
995                         function() {
996                             try {
997                                 JSAN.use('util.functional');
998
999                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
1000                                 var msg = '';
1001                                 if(obj.retrieve_ids.length > 1) {
1002                                     msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_retarget.reset_hold_message.plural',[hold_list.join(', ')]);
1003                                 } else {
1004                                     msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_retarget.reset_hold_message.singular',[hold_list.join(', ')]);
1005                                 }
1006                                 var r = obj.error.yns_alert(msg,
1007                                         $("patronStrings").getString('staff.patron.holds.holds_retarget.reset_hold_title'),
1008                                         $("commonStrings").getString('common.yes'),
1009                                         $("commonStrings").getString('common.no'),
1010                                         null,
1011                                         $("commonStrings").getString('common.check_to_confirm')
1012                                 );
1013                                 if (r == 0) {
1014                                     for (var i = 0; i < obj.retrieve_ids.length; i++) {
1015                                         var robj = obj.network.simple_request('FM_AHR_RESET',[ ses(), obj.retrieve_ids[i].id]);
1016                                         if (typeof robj.ilsevent != 'undefined') throw(robj);
1017                                     }
1018                                     obj.clear_and_retrieve();
1019                                 }
1020                             } catch(E) {
1021                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_retarget.holds_not_reset'),E);
1022                             }
1023
1024                         }
1025                     ],
1026
1027                     'cmd_holds_cancel' : [
1028                         ['command'],
1029                         function() {
1030                             try {
1031                                 JSAN.use('util.functional');
1032
1033                                 var hold_list = util.functional.map_list(obj.retrieve_ids, function(o){return o.id;});
1034                                 var msg = '';
1035                                 if(obj.retrieve_ids.length > 1 ) {
1036                                     msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_cancel.cancel_hold_message.plural', [hold_list.join(', ')]);
1037                                 } else {
1038                                     msg = $("patronStrings").getFormattedString('staff.patron.holds.holds_cancel.cancel_hold_message.singular', [hold_list.join(', ')]);
1039                                 }
1040
1041                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1042                                 JSAN.use('util.window');
1043                                 var win = new util.window();
1044                                 var my_xulG = win.open(
1045                                     urls.XUL_HOLD_CANCEL,
1046                                     'hold_cancel',
1047                                     'chrome,resizable,modal',
1048                                     {}
1049                                 );
1050                                 /*var r = obj.error.yns_alert(msg,
1051                                         $("patronStrings").getString('staff.patron.holds.holds_cancel.cancel_hold_title'),
1052                                         $("commonStrings").getString('common.yes'),
1053                                         $("commonStrings").getString('common.no'),
1054                                         null,
1055                                         $("commonStrings").getString('common.check_to_confirm')
1056                                 );*/
1057
1058                                 if (my_xulG.proceed) { 
1059                                     var transits = [];
1060                                     for (var i = 0; i < obj.retrieve_ids.length; i++) {
1061                                         var transit = obj.holds_map[ obj.retrieve_ids[i].id ].hold.transit();
1062                                         if (transit && ! transit.dest_recv_time() ) {
1063                                             transits.push( obj.retrieve_ids[i].barcode );
1064                                         }
1065                                         var robj = obj.network.simple_request('FM_AHR_CANCEL',[ ses(), obj.retrieve_ids[i].id, my_xulG.cancel_reason, my_xulG.note]);
1066                                         if (typeof robj.ilsevent != 'undefined') throw(robj);
1067                                     }
1068                                     if (transits.length > 0) {
1069                                         var msg2 = $("patronStrings").getFormattedString('staff.patron.holds.holds_cancel.cancel_for_barcodes', [transits.join(', ')]);
1070                                         var r2 = obj.error.yns_alert(msg2,
1071                                             $("patronStrings").getString('staff.patron.holds.holds_cancel.cancel_for_barcodes.title'),
1072                                             $("commonStrings").getString('common.yes'),
1073                                             $("commonStrings").getString('common.no'),
1074                                             null,
1075                                             $("commonStrings").getString('common.check_to_confirm'));
1076                                         if (r2 == 0) {
1077                                             try {
1078                                                 for (var i = 0; i < transits.length; i++) {
1079                                                     var robj = obj.network.simple_request('FM_ATC_VOID',[ ses(), { 'barcode' : transits[i] } ]);
1080                                                     if (typeof robj.ilsevent != 'undefined') {
1081                                                         switch(Number(robj.ilsevent)) {
1082                                                             case 1225 /* TRANSIT_ABORT_NOT_ALLOWED */ :
1083                                                                 alert(robj.desc);
1084                                                             break;
1085                                                             case 5000 /* PERM_FAILURE */ :
1086                                                             break;
1087                                                             default:
1088                                                                 throw(robj);
1089                                                             break;
1090                                                         }
1091                                                     }
1092                                                 }
1093                                             } catch(E) {
1094                                                obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_cancel.hold_transits_not_cancelled'),E);
1095                                             }
1096                                         }
1097                                     }
1098                                     obj.clear_and_retrieve();
1099                                 }
1100                             } catch(E) {
1101                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_cancel.hold_not_cancelled'),E);
1102                             }
1103                         }
1104                     ],
1105                     'cmd_holds_uncancel' : [
1106                         ['command'],
1107                         function() {
1108                             try {
1109                                 JSAN.use('util.functional');
1110                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
1111                                     var robj = obj.network.simple_request('FM_AHR_UNCANCEL',[ ses(), obj.retrieve_ids[i].id]);
1112                                     if (typeof robj.ilsevent != 'undefined') throw(robj);
1113                                 }
1114                                 obj.clear_and_retrieve();
1115                             } catch(E) {
1116                                 obj.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.holds.holds_uncancel.hold_not_uncancelled'),E);
1117                             }
1118                         }
1119                     ],
1120
1121                     'cmd_retrieve_patron' : [
1122                         ['command'],
1123                         function() {
1124                             try {
1125                                 var seen = {};
1126                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
1127                                     var patron_id = obj.retrieve_ids[i].usr;
1128                                     if (seen[patron_id]) continue; seen[patron_id] = true;
1129                                     xulG.new_patron_tab(
1130                                         {},
1131                                         { 'id' : patron_id }
1132                                     );
1133                                 }
1134                             } catch(E) {
1135                                 obj.error.standard_unexpected_error_alert('',E);
1136                             }
1137                         }
1138                     ],
1139                     'cmd_show_catalog' : [
1140                         ['command'],
1141                         function() {
1142                             try {
1143                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
1144                                     var htarget = obj.retrieve_ids[i].target;
1145                                     var htype = obj.retrieve_ids[i].type;
1146                                     var opac_url;
1147                                     switch(htype) {
1148                                         case 'M' :
1149                                             opac_url = xulG.url_prefix( urls.opac_rresult ) + '?m=' + htarget;
1150                                         break;
1151                                         case 'T' :
1152                                         case 'P' :
1153                                             opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + htarget;
1154                                         break;
1155                                         case 'I' :
1156                                             opac_url = xulG.url_prefix( urls.opac_rdetail )
1157                                             + '?r=' + obj.hold_subscription_map[ obj.retrieve_ids[i].id ].record_entry();
1158                                         break;
1159                                         case 'V' :
1160                                             var my_acn = obj.network.simple_request( 'FM_ACN_RETRIEVE.authoritative', [ htarget ]);
1161                                             opac_url = xulG.url_prefix( urls.opac_rdetail) + '?r=' + my_acn.record();
1162                                         break;
1163                                         case 'C' :
1164                                             var my_acp = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ htarget ]);
1165                                             var my_acn;
1166                                             if (typeof my_acp.call_number() == 'object') {
1167                                                 my_acn = my.acp.call_number();
1168                                             } else {
1169                                                 my_acn = obj.network.simple_request( 'FM_ACN_RETRIEVE.authoritative',
1170                                                     [ my_acp.call_number() ]);
1171                                             }
1172                                             opac_url = xulG.url_prefix( urls.opac_rdetail) + '?r=' + my_acn.record();
1173                                         break;
1174                                         default:
1175                                             obj.error.standard_unexpected_error_alert($("patronStrings").getFormattedString('staff.patron.holds.show_catalog.unknown_htype', [htype]), obj.retrieve_ids[i]);
1176                                             continue;
1177                                         break;
1178                                     }
1179                                     var content_params = {
1180                                         'session' : ses(),
1181                                         'authtime' : ses('authtime'),
1182                                         'opac_url' : opac_url
1183                                     };
1184                                     xulG.new_tab(
1185                                         xulG.url_prefix(urls.XUL_OPAC_WRAPPER),
1186                                         {'tab_name': htype == 'M' ? 'Catalog' : $("patronStrings").getString('staff.patron.holds.show_catalog.retrieving_title') },
1187                                         content_params
1188                                     );
1189                                 }
1190                             } catch(E) {
1191                                 obj.error.standard_unexpected_error_alert('',E);
1192                             }
1193                         }
1194                     ],
1195                     'cmd_holds_title_transfer' : [
1196                         ['command'],
1197                         function() {
1198                             try {
1199                                 var targets = [];
1200                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
1201                                     var htarget = obj.retrieve_ids[i].target;
1202                                     var htype = obj.retrieve_ids[i].type;
1203                                     switch(htype) {
1204                                         case 'M' :
1205                                             continue; // not supported
1206                                         break;
1207                                         case 'T' :
1208                                             targets.push( htarget );
1209                                         break;
1210                                         case 'V' :
1211                                             continue; // not supported
1212                                         break;
1213                                         case 'C' :
1214                                             continue; // not supported
1215                                         break;
1216                                         default:
1217                                             continue; // not supported
1218                                         break;
1219                                     }
1220                                 }
1221                                 JSAN.use('cat.util');
1222                                 cat.util.transfer_title_holds(targets);
1223                                 obj.clear_and_retrieve();
1224                             } catch(E) {
1225                                 obj.error.standard_unexpected_error_alert('',E);
1226                             }
1227                         }
1228                     ],
1229
1230                     'fetch_more' : [
1231                         ['command'],
1232                         function() {
1233                             obj.pull_from_shelf_interface.current.offset += obj.pull_from_shelf_interface.current.limit;
1234                             obj.retrieve(true);
1235                         }
1236                     ],
1237                     'lib_filter_checkbox' : [
1238                         ['command'],
1239                         function(ev) {
1240                             var x_lib_type_menu = document.getElementById('lib_type_menu');
1241                             if (x_lib_type_menu) x_lib_type_menu.disabled = ! ev.target.checked;
1242                             if (obj.controller.view.lib_menu) obj.controller.view.lib_menu.disabled = ! ev.target.checked;
1243                             obj.clear_and_retrieve();
1244                             ev.target.setAttribute('checked',ev.target.checked);
1245                         }
1246                     ],
1247                     'cmd_view_expired_onshelf_holds' : [
1248                         ['command'],
1249                         function(ev) {
1250                             var x = document.getElementById('expired_checkbox'); // can't trust ev.explicitOriginalTarget, sometimes gives a "button"
1251                             obj.expired = x.checked;
1252                             obj.controller.view.cmd_clear_expired_onshelf_holds.setAttribute('disabled', !obj.expired);
1253                             obj.clear_and_retrieve();
1254                         }
1255                     ],
1256                     'cmd_clear_expired_onshelf_holds' : [
1257                         ['command'],
1258                         function(ev) {
1259                             try {
1260                                 // I could put this with the "retrieval" methods, but since it has side effects, seems cleaner to invoke it here
1261                                 var robj = obj.network.simple_request( 'CLEAR_HOLD_SHELF', [ ses(), obj.filter_lib || obj.data.list.au[0].ws_ou() ] );
1262                                 if (robj == null) { robj = []; }
1263                                 if (typeof robj.ilsevent != 'undefined') { throw(robj); }
1264                                 if (typeof robj.length == 'undefined') { robj = [ robj ]; }
1265
1266                                 // Disable anything such as filters that can have us accidentally lose these non-repeatable results
1267                                 var x_lib_filter_checkbox = document.getElementById('lib_filter_checkbox');
1268                                 if (x_lib_filter_checkbox) { x_lib_filter_checkbox.checked = false; }
1269                                 var x_lib_type_menu = document.getElementById('lib_type_menu');
1270                                 if (x_lib_type_menu) { x_lib_type_menu.disabled = true; }
1271                                 var x_lib_menu_placeholder = document.getElementById('lib_menu_placeholder');
1272                                 if (x_lib_menu_placeholder) { x_lib_menu_placeholder.firstChild.disabled = true; }
1273                                 obj.controller.view.cmd_view_expired_onshelf_holds.setAttribute('disabled', 'true');
1274                                 obj.controller.view.cmd_clear_expired_onshelf_holds.setAttribute('disabled', 'true');
1275
1276                                 // id's in xulG.holds will prevent the normal retrieval method from firing
1277                                 JSAN.use('util.functional');
1278                                 xulG.holds = util.functional.map_list(
1279                                     robj.sort(function(a,b) {
1280                                         if (a.action > b.action) { return 1; }
1281                                         if (a.action < b.action) { return -1; }
1282                                         return 0;
1283                                     }),
1284                                     function (element, idx) {
1285                                         obj.post_clear_shelf_hold_action_map[ element.hold_id ] = element.action; // necessary side-effect
1286                                         return element.hold_id;
1287                                     }
1288                                 );
1289                                 obj.clear_and_retrieve();
1290                             } catch(E) {
1291                                 if (E.ilsevent == 5000 /* PERM_FAILURE */ ) { return; /* handled by network.js */ }
1292                                 obj.error.standard_unexpected_error_alert('Error in holds.js, cmd_clear_expired_onshelf_holds', E);
1293                             }
1294                         }
1295                     ],
1296
1297                     'cmd_search_opac' : [
1298                         ['command'],
1299                         function(ev) {
1300                             try {
1301                                 var content_params = {
1302                                     'show_nav_buttons' : false,
1303                                     'show_print_button' : true,
1304                                     'passthru_content_params' : {
1305                                         'authtoken' : ses(),
1306                                         'authtime' : ses('authtime'),
1307                                         'window_open' : function(a,b,c) {
1308                                             try {
1309                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
1310                                                 return window.open(a,b,c);
1311                                             } catch(E) {
1312                                                 obj.error.standard_unexpected_error_alert('window_open',E);
1313                                             }
1314                                         },
1315                                         'opac_hold_placed' : function(hold) {
1316                                             try {
1317                                                 obj.list.append(
1318                                                     {
1319                                                         'row' : {
1320                                                             'my' : {
1321                                                                 'hold_id' : typeof hold == 'object' ? hold.id() : hold
1322                                                             }
1323                                                         }
1324                                                     }
1325                                                 );
1326                                                 if (window.xulG && typeof window.xulG.on_list_change == 'function') {
1327                                                     window.xulG.on_list_change(); 
1328                                                 }
1329                                             } catch(E) {
1330                                                 obj.error.standard_unexpected_error_alert('holds.js, opac_hold_placed(): ',E);
1331                                             }
1332                                         },
1333                                         'patron_barcode' : obj.patron_barcode
1334                                     },
1335                                     'url_prefix' : xulG.url_prefix,
1336                                     'url' : xulG.url_prefix( urls.browser )
1337                                 };
1338                                 xulG.display_window.g.patron.right_deck.set_iframe( urls.XUL_REMOTE_BROWSER + '?patron_hold=1', {}, content_params);
1339                             } catch(E) {
1340                                 obj.error.sdump('D_ERROR','cmd_search_opac: ' + E);
1341                             }
1342
1343                         }
1344                     ]
1345                 }
1346             }
1347         );
1348
1349         obj.determine_hold_interface_type();
1350         var x_fetch_more = document.getElementById('fetch_more');
1351         var x_lib_type_menu = document.getElementById('lib_type_menu');
1352         var x_lib_menu_placeholder = document.getElementById('lib_menu_placeholder');
1353         var x_lib_filter_checkbox = document.getElementById('lib_filter_checkbox');
1354         var x_show_cancelled_deck = document.getElementById('show_cancelled_deck');
1355         var x_clear_shelf_widgets = document.getElementById('clear_shelf_widgets');
1356         var x_expired_checkbox = document.getElementById('expired_checkbox');
1357         var x_print_full_pull_list = document.getElementById('print_full_btn');
1358         var x_print_full_pull_list_alt = document.getElementById('print_alt_btn');
1359         switch(obj.hold_interface_type) {
1360             case 'shelf':
1361                 obj.render_lib_menus({'pickup_lib':true});
1362                 if (x_lib_filter_checkbox) x_lib_filter_checkbox.checked = true;
1363                 if (x_lib_type_menu) x_lib_type_menu.hidden = false;
1364                 if (x_lib_menu_placeholder) x_lib_menu_placeholder.hidden = false;
1365                 if (x_clear_shelf_widgets) x_clear_shelf_widgets.hidden = false;
1366                 if (x_print_full_pull_list_alt) x_print_full_pull_list_alt.hidden = true;
1367             break;
1368             case 'pull' :
1369                 if (x_fetch_more) x_fetch_more.hidden = false;
1370                 if (x_print_full_pull_list) x_print_full_pull_list.hidden = false;
1371                 if (x_print_full_pull_list_alt) x_print_full_pull_list_alt.hidden = false;
1372                 if (x_lib_type_menu) x_lib_type_menu.hidden = true;
1373                 if (x_lib_menu_placeholder) x_lib_menu_placeholder.hidden = true;
1374             break;
1375             case 'record' :
1376                 obj.render_lib_menus({'pickup_lib':true,'request_lib':true});
1377                 if (x_lib_filter_checkbox) x_lib_filter_checkbox.hidden = false;
1378                 if (x_lib_type_menu) x_lib_type_menu.hidden = false;
1379                 if (x_print_full_pull_list_alt) x_print_full_pull_list_alt.hidden = true;
1380                 if (x_lib_menu_placeholder) x_lib_menu_placeholder.hidden = false;
1381             break;
1382             default:
1383                 if (obj.controller.view.cmd_search_opac) obj.controller.view.cmd_search_opac.setAttribute('hidden', false);
1384                 if (x_fetch_more) x_fetch_more.hidden = true;
1385                 if (x_lib_type_menu) x_lib_type_menu.hidden = true;
1386                 if (x_lib_menu_placeholder) x_lib_menu_placeholder.hidden = true;
1387                 if (x_show_cancelled_deck) x_show_cancelled_deck.hidden = false;
1388                 if (x_print_full_pull_list_alt) x_print_full_pull_list_alt.hidden = true;
1389             break;
1390         }
1391         setTimeout( // We do this because render_lib_menus above creates and appends a DOM node, but until this thread exits, it doesn't really happen
1392             function() {
1393                 if (x_lib_filter_checkbox) if (!x_lib_filter_checkbox.checked) {
1394                     if (x_lib_type_menu) x_lib_type_menu.disabled = true;
1395                     if (obj.controller.view.lib_menu) obj.controller.view.lib_menu.disabled = true;
1396                 }
1397                 obj.controller.render();
1398                 obj.retrieve(true);
1399
1400                 obj.controller.view.cmd_retrieve_patron.setAttribute('disabled','true');
1401                 obj.controller.view.cmd_holds_edit_pickup_lib.setAttribute('disabled','true');
1402                 obj.controller.view.cmd_holds_edit_phone_notify.setAttribute('disabled','true');
1403                 obj.controller.view.cmd_holds_edit_email_notify.setAttribute('disabled','true');
1404                 obj.controller.view.cmd_holds_edit_thaw_date.setAttribute('disabled','true');
1405                 obj.controller.view.cmd_holds_activate.setAttribute('disabled','true');
1406                 obj.controller.view.cmd_holds_suspend.setAttribute('disabled','true');
1407                 obj.controller.view.cmd_holds_edit_selection_depth.setAttribute('disabled','true');
1408                 obj.controller.view.cmd_alt_view.setAttribute('disabled','true');
1409                 obj.controller.view.cmd_holds_retarget.setAttribute('disabled','true');
1410                 obj.controller.view.cmd_holds_cancel.setAttribute('disabled','true');
1411                 obj.controller.view.cmd_holds_uncancel.setAttribute('disabled','true');
1412                 obj.controller.view.cmd_show_catalog.setAttribute('disabled','true');
1413             }, 0
1414         );
1415
1416         $('cmd_alt_view').setAttribute('disabled','true');
1417         xulG.when_done = function() {
1418             $('cmd_alt_view').setAttribute('ready','true');
1419             if ($('cmd_alt_view').getAttribute('rendering_rows') != 'true') {
1420                 $('cmd_alt_view').setAttribute('disabled','false');
1421             }
1422             dump('hold details UI ready\n');
1423         }
1424         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1425         JSAN.use('util.browser');
1426         obj.browser = new util.browser();
1427         obj.browser.init(
1428             {
1429                 'url' : urls.XUL_HOLD_DETAILS,
1430                 'push_xulG' : true,
1431                 'alt_print' : false,
1432                 'browser_id' : 'hold_detail_frame',
1433                 'passthru_content_params' : xulG
1434             }
1435         );
1436
1437     },
1438
1439     'determine_hold_interface_type' : function() {
1440         var obj = this;
1441         if (obj.patron_id) { /*************************************************** PATRON ******************************/
1442             obj.hold_interface_type = 'patron';
1443         } else if (obj.docid) { /*************************************************** RECORD ******************************/
1444             obj.hold_interface_type = 'record';
1445         } else if (obj.pull) { /*************************************************** PULL ******************************/
1446             obj.hold_interface_type = 'pull';
1447         } else if (obj.shelf) { /*************************************************** HOLD SHELF ******************************/
1448             obj.hold_interface_type = 'shelf';
1449         } else { /*************************************************** PULL ******************************/
1450             obj.hold_interface_type = 'pull';
1451         }
1452     },
1453
1454     'clear_and_retrieve' : function() {
1455         try {
1456             this.list.clear();
1457             this.pull_from_shelf_interface.current.offset = this.pull_from_shelf_interface._default.offset;
1458             this.retrieve();
1459             if (window.xulG && typeof window.xulG.on_list_change == 'function') {
1460                 window.xulG.on_list_change(); 
1461             }
1462         } catch(E) {
1463             this.error.standard_unexpected_error_alert('holds.js, clear_and_retrieve(): ',E);
1464         }
1465     },
1466
1467     'retrieve' : function() {
1468         var obj = this; var holds = [];
1469         if (window.xulG && window.xulG.holds) {
1470             holds = window.xulG.holds;
1471         } else {
1472             var method; var params = [ ses() ];
1473             switch(obj.hold_interface_type) {
1474                 case 'patron' :
1475                     if (document.getElementById('show_cancelled_deck').selectedIndex == 0) {
1476                         method = 'FM_AHR_ID_LIST_RETRIEVE_VIA_AU.authoritative';
1477                     } else {
1478                         method = 'FM_AHR_CANCELLED_ID_LIST_RETRIEVE_VIA_AU.authoritative';
1479                     }
1480                     params.push( obj.patron_id );
1481                     obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','true');
1482                 break;
1483                 case 'record' :
1484                     method = 'FM_AHR_RETRIEVE_ALL_VIA_BRE';
1485                     params.push( obj.docid );
1486                     var x_lib_filter = document.getElementById('lib_filter_checkbox');
1487                     var x_lib_type_menu = document.getElementById('lib_type_menu');
1488                     if (x_lib_filter) {
1489                         if (x_lib_filter.checked) {
1490                             if (x_lib_type_menu && obj.controller.view.lib_menu) {
1491                                 var x = {};
1492                                 x[ x_lib_type_menu.value ] = obj.controller.view.lib_menu.value;
1493                                 params.push( x );
1494                             }
1495                         }
1496                     }
1497                     obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','false');
1498                 break;
1499                 case 'shelf' :
1500                     if (obj.expired) {
1501                         method = 'FM_AHR_ID_LIST_EXPIRED_ONSHELF_RETRIEVE';
1502                     } else {
1503                         method = 'FM_AHR_ID_LIST_ONSHELF_RETRIEVE';
1504                     }
1505                     params.push( obj.filter_lib || obj.data.list.au[0].ws_ou() );
1506                     obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','false');
1507                 break;
1508                 case 'pull' :
1509                 default:
1510                     method = 'FM_AHR_ID_LIST_PULL_LIST';
1511                     params.push( obj.pull_from_shelf_interface.current.limit ); params.push( obj.pull_from_shelf_interface.current.offset );
1512                     var x = document.getElementById('hold_count');
1513                     if (x) {
1514                         obj.network.simple_request('FM_AHR_PULL_LIST_COUNT',[ses()],function(req) {
1515                             var count = req.getResultObject();
1516                             if (typeof count.ilsevent == 'undefined' && count != null) {
1517                                 x.setAttribute('value', document.getElementById('patronStrings').getFormattedString(
1518                                     'staff.patron.holds.total_count',
1519                                     [ count ]
1520                                 ));
1521                                 x.hidden = false;
1522                             }
1523                         });
1524                     }
1525                 break;
1526             }
1527             var robj = obj.network.simple_request( method, params );
1528             if (robj != null && typeof robj.ilsevent != 'undefined') throw(robj);
1529             if (method == 'FM_AHR_RETRIEVE_ALL_VIA_BRE') {
1530                 holds = [];
1531                 if (robj != null) {
1532                     holds = holds.concat( robj.copy_holds );
1533                     holds = holds.concat( robj.volume_holds );
1534                     holds = holds.concat( robj.title_holds );
1535                     holds = holds.concat( robj.part_holds );
1536                     holds = holds.concat( robj.issuance_holds );
1537                     holds = holds.concat( robj.metarecord_holds );
1538                     holds = holds.sort();
1539                 }
1540             } else {
1541                 if (robj == null ) {
1542                     holds = [];
1543                 } else {
1544                     if (typeof robj.length == 'undefined') {
1545                         holds = [ robj ];
1546                     } else {
1547                         holds = robj;
1548                     }
1549                 }
1550             }
1551             holds.reverse();
1552             //alert('method = ' + method + ' params = ' + js2JSON(params));
1553         }
1554
1555         var x_fetch_more = document.getElementById('fetch_more');
1556         if (holds.length == 0) {
1557             if (x_fetch_more) x_fetch_more.disabled = true;
1558         } else {
1559             if (x_fetch_more) x_fetch_more.disabled = false;
1560             obj.render(holds);
1561         }
1562
1563     },
1564
1565     'render' : function(holds) {
1566         try {
1567             var obj = this;
1568
1569             function list_append(hold_id) {
1570                 obj.list.append(
1571                     {
1572                         'row' : {
1573                             'my' : {
1574                                 'hold_id' : hold_id,
1575                                 'post_clear_shelf_action' : obj.post_clear_shelf_hold_action_map[ hold_id ]
1576                             }
1577                         },
1578                         'to_bottom' : true
1579                     }
1580                 );
1581             }
1582
1583             function gen_list_append(hold) {
1584                 return function() {
1585                     if (typeof obj.controller.view.lib_menu == 'undefined') {
1586                         list_append(typeof hold == 'object' ? hold.id() : hold);
1587                     } else {
1588                         list_append(typeof hold == 'object' ? hold.id() : hold);
1589                     }
1590                 };
1591             }
1592
1593             //obj.list.clear();
1594
1595             JSAN.use('util.exec'); var exec = new util.exec(2);
1596             var rows = [];
1597             for (var i in holds) {
1598                 rows.push( gen_list_append(holds[i]) );
1599             }
1600             exec.chain( rows );
1601
1602         } catch(E) {
1603             this.error.standard_unexpected_error_alert('holds.js, render():',E);
1604         }
1605     },
1606
1607     'render_lib_menus' : function(types) {
1608         try {
1609             var obj = this;
1610             JSAN.use('util.widgets'); JSAN.use('util.functional'); JSAN.use('util.fm_utils');
1611
1612             var x = document.getElementById('lib_type_menu');
1613             if (types) {
1614                 var nodes = x.firstChild.childNodes;
1615                 for (var i = 0; i < nodes.length; i++) nodes[i].hidden = true;
1616                 for (var i in types) document.getElementById(i).hidden = false;
1617             }
1618             x.setAttribute('oncommand','g.holds.clear_and_retrieve()');
1619
1620             x = document.getElementById('lib_menu_placeholder');
1621             util.widgets.remove_children( x );
1622
1623             JSAN.use('util.file');
1624             var file = new util.file('offline_ou_list');
1625             if (file._file.exists()) {
1626                 var list_data = file.get_object(); file.close();
1627                 var ml = util.widgets.make_menulist( list_data[0], obj.data.list.au[0].ws_ou() );
1628                 ml.setAttribute('id','lib_menu');
1629                 x.appendChild( ml );
1630                 ml.addEventListener(
1631                     'command',
1632                     function(ev) {
1633                         obj.filter_lib = ev.target.value;
1634                         obj.clear_and_retrieve();
1635                     },
1636                     false
1637                 );
1638                 obj.controller.view.lib_menu = ml;
1639             } else {
1640                 throw($("patronStrings").getString('staff.patron.holds.lib_menus.missing_library_list'));
1641             }
1642
1643         } catch(E) {
1644             this.error.standard_unexpected_error_alert('rendering lib menu',E);
1645         }
1646     }
1647 }
1648
1649 dump('exiting patron.holds.js\n');