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