]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/holds.js
new uber holds detail. Does this make it faster?
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / patron / holds.js
1 dump('entering patron.holds.js\n');
2
3 if (typeof patron == 'undefined') patron = {};
4 patron.holds = function (params) {
5
6         JSAN.use('util.error'); this.error = new util.error();
7         JSAN.use('util.network'); this.network = new util.network();
8         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
9 }
10
11 patron.holds.prototype = {
12
13         'foreign_shelf' : null,
14
15         'retrieve_ids' : [],
16
17         'holds_map' : {},
18
19         'init' : function( params ) {
20
21                 var obj = this;
22
23                 obj.patron_id = params['patron_id'];
24                 obj.docid = params['docid'];
25                 obj.shelf = params['shelf'];
26
27                 JSAN.use('circ.util');
28                 var columns = circ.util.hold_columns( 
29                         { 
30                                 'title' : { 'hidden' : false, 'flex' : '3' },
31                                 'request_time' : { 'hidden' : false },
32                                 'pickup_lib_shortname' : { 'hidden' : false },
33                                 'hold_type' : { 'hidden' : false },
34                                 'current_copy' : { 'hidden' : false },
35                                 'capture_time' : { 'hidden' : false },
36                                 'notify_time' : { 'hidden' : false },
37                                 'notify_count' : { 'hidden' : false },
38                         } 
39                 );
40
41                 JSAN.use('util.list'); obj.list = new util.list('holds_list');
42                 obj.list.init(
43                         {
44                                 'columns' : columns,
45                                 'map_row_to_column' : circ.util.std_map_row_to_column(),
46                                 'retrieve_row' : function(params) {
47                                         var row = params.row;
48                                         try {
49                                                 obj.network.simple_request('FM_AHR_BLOB_RETRIEVE', [ ses(), row.my.hold_id ],
50                                                         function(blob_req) {
51                                                                 try {
52                                                                         var blob = blob_req.getResultObject();
53                                                                         if (typeof blob.ilsevent != 'undefined') throw(blob);
54                                                                         row.my.ahr = blob.hold;
55                                                                         row.my.status = blob.status;
56                                                                         row.my.acp = blob.copy;
57                                                                         row.my.acn = blob.volume;
58                                                                         row.my.mvr = blob.mvr;
59                                                                         row.my.patron_family_name = blob.patron_last;
60                                                                         row.my.patron_first_given_name = blob.patron_first;
61                                                                         row.my.patron_barcode = blob.patron_barcode;
62
63                                                                         obj.holds_map[ row.my.ahr.id() ] = row.my.ahr;
64                                                                         params.row_node.setAttribute('retrieve_id', 
65                                                                                 js2JSON({
66                                                                                         'copy_id':row.my.ahr.current_copy(),
67                                                                                         'id':row.my.ahr.id(),
68                                                                                         'type':row.my.ahr.hold_type(),
69                                                                                         'target':row.my.ahr.target(),
70                                                                                         'usr':row.my.ahr.usr(),
71                                                                                 })
72                                                                         );
73                                                                         if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
74
75                                                                 } catch(E) {
76                                                                         obj.error.standard_unexpected_error_alert('Error retrieving details for hold #' + row.my.hold_id, E);
77                                                                 }
78                                                         }
79                                                 );
80                                                 /*
81                                                 obj.network.simple_request('FM_AHR_RETRIEVE', [ ses(), row.my.hold_id ],
82                                                         function(ahr_req) {
83                                                                 try {
84                                                                         var ahr_robj = ahr_req.getResultObject();
85                                                                         if (typeof ahr_robj.ilsevent != 'undefined') throw(ahr_robj);
86                                                                         row.my.ahr = ahr_robj[0];
87                                                                         obj.holds_map[ row.my.ahr.id() ] = row.my.ahr;
88                                                                         params.row_node.setAttribute('retrieve_id', 
89                                                                                 js2JSON({
90                                                                                         'copy_id':row.my.ahr.current_copy(),
91                                                                                         'id':row.my.ahr.id(),
92                                                                                         'type':row.my.ahr.hold_type(),
93                                                                                         'target':row.my.ahr.target(),
94                                                                                         'usr':row.my.ahr.usr(),
95                                                                                 })
96                                                                         );
97
98                                                                         obj.network.simple_request('FM_AHR_STATUS',[ ses(), row.my.ahr.id() ],
99                                                                                 function(status_req) {
100                                                                                         try {
101                                                                                                 var status_robj = status_req.getResultObject();
102                                                                                                 row.my.status = status_robj;
103                                                                                                 switch(row.my.ahr.hold_type()) {
104                                                                                                         case 'M' :
105                                                                                                                 obj.network.request(
106                                                                                                                         api.MODS_SLIM_METARECORD_RETRIEVE.app,
107                                                                                                                         api.MODS_SLIM_METARECORD_RETRIEVE.method,
108                                                                                                                         [ row.my.ahr.target() ],
109                                                                                                                         function(mvr_req) {
110                                                                                                                                 row.my.mvr = mvr_req.getResultObject();
111                                                                                                                                 if ( row.my.ahr.current_copy() && ! row.my.acp) {
112                                                                                                                                         obj.network.simple_request( 'FM_ACP_RETRIEVE', [ row.my.ahr.current_copy() ],
113                                                                                                                                                 function(acp_req) {
114                                                                                                                                                         row.my.acp = acp_req.getResultObject();
115                                                                                                                                                         if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
116                                                                                                                                                 }
117                                                                                                                                         );
118                                                                                                                                 } else {
119                                                                                                                                         if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
120                                                                                                                                 }
121                                                                                                                         }
122                                                                                                                 );
123                                                                                                         break;
124                                                                                                         case 'T' :
125                                                                                                                 obj.network.request(
126                                                                                                                         api.MODS_SLIM_RECORD_RETRIEVE.app,
127                                                                                                                         api.MODS_SLIM_RECORD_RETRIEVE.method,
128                                                                                                                         [ row.my.ahr.target() ],
129                                                                                                                         function(mvr_req) {
130                                                                                                                                 row.my.mvr = mvr_req.getResultObject();
131                                                                                                                                 if ( row.my.ahr.current_copy() && ! row.my.acp) {
132                                                                                                                                         obj.network.simple_request( 'FM_ACP_RETRIEVE', [ row.my.ahr.current_copy() ],
133                                                                                                                                                 function(acp_req) {
134                                                                                                                                                         row.my.acp = acp_req.getResultObject();
135                                                                                                                                                         if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
136                                                                                                                                                 }
137                                                                                                                                         );
138                                                                                                                                 } else {
139                                                                                                                                         if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
140                                                                                                                                 }
141         
142                                                                                                                         }
143                                                                                                                 );
144                                                                                                         break;
145                                                                                                         case 'V' :
146                                                                                                                 row.my.acn = obj.network.simple_request( 'FM_ACN_RETRIEVE', [ row.my.ahr.target() ],
147                                                                                                                         function(acn_req) {
148                                                                                                                                 row.my.acn = acn_req.getResultObject();
149                                                                                                                                 obj.network.request(
150                                                                                                                                         api.MODS_SLIM_RECORD_RETRIEVE.app,
151                                                                                                                                         api.MODS_SLIM_RECORD_RETRIEVE.method,
152                                                                                                                                         [ row.my.acn.record() ],
153                                                                                                                                         function(mvr_req) {
154                                                                                                                                                 try { row.my.mvr = mvr_req.getResultObject(); } catch(E) {}
155                                                                                                                                                 if ( row.my.ahr.current_copy() && ! row.my.acp) {
156                                                                                                                                                         obj.network.simple_request( 'FM_ACP_RETRIEVE', [ row.my.ahr.current_copy() ],
157                                                                                                                                                                 function(acp_req) {
158                                                                                                                                                                         row.my.acp = acp_req.getResultObject();
159                                                                                                                                                                         if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
160                                                                                                                                                                 }
161                                                                                                                                                         );
162                                                                                                                                                 } else {
163                                                                                                                                                         if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
164                                                                                                                                                 }
165                                                                                                                                         }
166                                                                                                                                 );
167                                                                                                                         }
168                                                                                                                 );
169                                                                                                         break;
170                                                                                                         case 'C' :
171                                                                                                                 obj.network.simple_request( 'FM_ACP_RETRIEVE', [ row.my.ahr.target() ],
172                                                                                                                         function(acp_req) {
173                                                                                                                                 row.my.acp = acp_req.getResultObject();
174                                                                                                                                 obj.network.simple_request( 'FM_ACN_RETRIEVE', [ typeof row.my.acp.call_number() == 'object' ? row.my.acp.call_number().id() : row.my.acp.call_number() ],
175                                                                                                                                         function(acn_req) {
176                                                                                                                                                 row.my.acn = acn_req.getResultObject();
177                                                                                                                                                 obj.network.request(
178                                                                                                                                                         api.MODS_SLIM_RECORD_RETRIEVE.app,
179                                                                                                                                                         api.MODS_SLIM_RECORD_RETRIEVE.method,
180                                                                                                                                                         [ row.my.acn.record() ],
181                                                                                                                                                         function(mvr_req) {
182                                                                                                                                                                 try { row.my.mvr = mvr_req.getResultObject(); } catch(E) {}
183                                                                                                                                                                 if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
184                                                                                                                                                         }
185                                                                                                                                                 );
186                                                                                                                                         }
187                                                                                                                                 );
188                                                                                                                         }
189                                                                                                                 );
190                                                                                                         break;
191                                                                                                 }
192                                                                                         } catch(E) {
193                                                                                                 obj.error.standard_unexpected_error_alert('Error retrieving status for hold #' + row.my.hold_id, E);
194                                                                                         }
195                                                                                 }
196                                                                         );
197                                                                 } catch(E) {
198                                                                         obj.error.standard_unexpected_error_alert('Error retrieving hold #' + row.my.hold_id, E);
199                                                                 }
200                                                         }
201                                                 );
202                                                 */
203                                         } catch(E) {
204                                                 obj.error.sdump('D_ERROR','retrieve_row: ' + E );
205                                         }
206                                         return row;
207                                 },
208                                 'on_select' : function(ev) {
209                                         JSAN.use('util.functional');
210                                         var sel = obj.list.retrieve_selection();
211                                         obj.controller.view.sel_clip.setAttribute('disabled',sel.length < 1);
212                                         obj.retrieve_ids = util.functional.map_list(
213                                                 sel,
214                                                 function(o) { return JSON2js( o.getAttribute('retrieve_id') ); }
215                                         );
216                                         if (obj.retrieve_ids.length > 0) {
217                                                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','false');
218                                                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','false');
219                                                 obj.controller.view.sel_copy_details.setAttribute('disabled','false');
220                                                 obj.controller.view.sel_patron.setAttribute('disabled','false');
221                                                 obj.controller.view.cmd_retrieve_patron.setAttribute('disabled','false');
222                                                 obj.controller.view.cmd_holds_edit_pickup_lib.setAttribute('disabled','false');
223                                                 obj.controller.view.cmd_holds_edit_phone_notify.setAttribute('disabled','false');
224                                                 obj.controller.view.cmd_holds_edit_email_notify.setAttribute('disabled','false');
225                                                 obj.controller.view.cmd_holds_edit_selection_depth.setAttribute('disabled','false');
226                                                 obj.controller.view.cmd_show_notifications.setAttribute('disabled','false');
227                                                 obj.controller.view.cmd_holds_retarget.setAttribute('disabled','false');
228                                                 obj.controller.view.cmd_holds_cancel.setAttribute('disabled','false');
229                                                 obj.controller.view.cmd_show_catalog.setAttribute('disabled','false');
230                                         } else {
231                                                 obj.controller.view.sel_mark_items_damaged.setAttribute('disabled','true');
232                                                 obj.controller.view.sel_mark_items_missing.setAttribute('disabled','true');
233                                                 obj.controller.view.sel_copy_details.setAttribute('disabled','true');
234                                                 obj.controller.view.sel_patron.setAttribute('disabled','true');
235                                                 obj.controller.view.cmd_retrieve_patron.setAttribute('disabled','true');
236                                                 obj.controller.view.cmd_holds_edit_pickup_lib.setAttribute('disabled','true');
237                                                 obj.controller.view.cmd_holds_edit_phone_notify.setAttribute('disabled','true');
238                                                 obj.controller.view.cmd_holds_edit_email_notify.setAttribute('disabled','true');
239                                                 obj.controller.view.cmd_holds_edit_selection_depth.setAttribute('disabled','true');
240                                                 obj.controller.view.cmd_show_notifications.setAttribute('disabled','true');
241                                                 obj.controller.view.cmd_holds_retarget.setAttribute('disabled','true');
242                                                 obj.controller.view.cmd_holds_cancel.setAttribute('disabled','true');
243                                                 obj.controller.view.cmd_show_catalog.setAttribute('disabled','true');
244                                         }
245                                 },
246
247                         }
248                 );
249                 
250                 JSAN.use('util.controller'); obj.controller = new util.controller();
251                 obj.controller.init(
252                         {
253                                 'control_map' : {
254                                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
255                                         'sel_clip' : [
256                                                 ['command'],
257                                                 function() { obj.list.clipboard(); }
258                                         ],
259                                         'cmd_broken' : [
260                                                 ['command'],
261                                                 function() { alert('Not Yet Implemented'); }
262                                         ],
263                                         'sel_patron' : [
264                                                 ['command'],
265                                                 function() {
266                                                         JSAN.use('circ.util');
267                                                         circ.util.show_last_few_circs(obj.retrieve_ids);
268                                                 }
269                                         ],
270                                         'sel_mark_items_damaged' : [
271                                                 ['command'],
272                                                 function() {
273                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
274                                                         cat.util.mark_item_damaged( util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
275                                                 }
276                                         ],
277                                         'sel_mark_items_missing' : [
278                                                 ['command'],
279                                                 function() {
280                                                         JSAN.use('cat.util'); JSAN.use('util.functional');
281                                                         cat.util.mark_item_missing( util.functional.map_list( obj.retrieve_ids, function(o) { return o.copy_id; } ) );
282                                                 }
283                                         ],
284                                         'sel_copy_details' : [
285                                                 ['command'],
286                                                 function() {
287                                                         JSAN.use('circ.util');
288                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
289                                                                 if (obj.retrieve_ids[i].copy_id) circ.util.show_copy_details( obj.retrieve_ids[i].copy_id );
290                                                         }
291                                                 }
292                                         ],
293                                         'cmd_holds_print' : [
294                                                 ['command'],
295                                                 function() {
296                                                         try {
297                                                                 dump(js2JSON(obj.list.dump_with_keys()) + '\n');
298                                                                 function flesh_callback() {
299                                                                         try {
300                                                                                 JSAN.use('patron.util');
301                                                                                 var params = { 
302                                                                                         'patron' : patron.util.retrieve_au_via_id(ses(),obj.patron_id), 
303                                                                                         'lib' : obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ],
304                                                                                         'staff' : obj.data.list.au[0],
305                                                                                         'header' : obj.data.print_list_templates.holds.header,
306                                                                                         'line_item' : obj.data.print_list_templates.holds.line_item,
307                                                                                         'footer' : obj.data.print_list_templates.holds.footer,
308                                                                                         'type' : obj.data.print_list_templates.holds.type,
309                                                                                         'list' : obj.list.dump_with_keys(),
310                                                                                 };
311                                                                                 JSAN.use('util.print'); var print = new util.print();
312                                                                                 print.tree_list( params );
313                                                                                 setTimeout(function(){obj.list.on_all_fleshed = null;},0);
314                                                                         } catch(E) {
315                                                                                 obj.error.standard_unexpected_error_alert('print 2',E);
316                                                                         }
317                                                                 }
318                                                                 obj.list.on_all_fleshed = flesh_callback;
319                                                                 obj.list.full_retrieve();
320                                                         } catch(E) {
321                                                                 obj.error.standard_unexpected_error_alert('print 1',E);
322                                                         }
323                                                 }
324                                         ],
325                                         'cmd_show_notifications' : [
326                                                 ['command'],
327                                                 function() {
328                                                         try {
329                                                                 JSAN.use('util.window'); var win = new util.window();
330                                                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
331                                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
332                                                                         win.open(
333                                                                                 xulG.url_prefix(urls.XUL_HOLD_NOTICES) 
334                                                                                 + '?ahr_id=' + obj.retrieve_ids[i].id,
335                                                                                 'hold_notices_' + obj.retrieve_ids[i].id,
336                                                                                 'chrome,resizable'
337                                                                         );
338                                                                 }
339                                                         } catch(E) {
340                                                                 obj.error.standard_unexpected_error_alert('Error rendering/retrieving hold notifications.',E);
341                                                         }
342                                                 }
343                                         ],
344                                         'cmd_holds_edit_selection_depth' : [
345                                                 ['command'],
346                                                 function() {
347                                                         try {
348                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional'); 
349                                                                 var ws_type = obj.data.hash.aout[ obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].ou_type() ];
350                                                                 var list = util.functional.map_list(
351                                                                         util.functional.filter_list(    
352                                                                                 obj.data.list.aout,
353                                                                                 function(o) {
354                                                                                         if (o.depth() > ws_type.depth()) return false;
355                                                                                         if (o.depth() < ws_type.depth()) return true;
356                                                                                         return (o.id() == ws_type.id());
357                                                                                 }
358                                                                         ),
359                                                                         function(o) { 
360                                                                                 return [
361                                                                                         o.opac_label(),
362                                                                                         o.id(),
363                                                                                         false,
364                                                                                         ( o.depth() * 2),
365                                                                                 ]; 
366                                                                         }
367                                                                 );
368                                                                 ml = util.widgets.make_menulist( list, obj.data.list.au[0].ws_ou() );
369                                                                 ml.setAttribute('id','selection');
370                                                                 ml.setAttribute('name','fancy_data');
371                                                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
372                                                                 xml += '<description>Please choose a Hold Range:</description>';
373                                                                 xml += util.widgets.serialize_node(ml);
374                                                                 xml += '</vbox>';
375                                                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
376                                                                 bot_xml += '<spacer flex="1"/><button label="Done" accesskey="D" name="fancy_submit"/>';
377                                                                 bot_xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
378                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
379                                                                 obj.data.temp_mid = xml; obj.data.stash('temp_mid');
380                                                                 obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
381                                                                 window.open(
382                                                                         urls.XUL_FANCY_PROMPT
383                                                                         + '?xml_in_stash=temp_mid'
384                                                                         + '&bottom_xml_in_stash=temp_bot'
385                                                                         + '&title=' + window.escape('Choose a Pick Up Library'),
386                                                                         'fancy_prompt', 'chrome,resizable,modal'
387                                                                 );
388                                                                 obj.data.init({'via':'stash'});
389                                                                 if (obj.data.fancy_prompt_data == '') { return; }
390                                                                 var selection = obj.data.fancy_prompt_data.selection;
391                                                                 var msg = 'Are you sure you would like to change the Hold Range for hold' + ( obj.retrieve_ids.length > 1 ? 's ' : ' ') + util.functional.map_list( obj.retrieve_ids, function(o){return o.id;}).join(', ') + ' to "' + obj.data.hash.aout[selection].opac_label() + '"?';
392                                                                 var r = obj.error.yns_alert(msg,'Modifying Holds','Yes','No',null,'Check here to confirm this message');
393                                                                 if (r == 0) {
394                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
395                                                                                 var hold = obj.holds_map[ obj.retrieve_ids[i].id ];
396                                                                                 hold.selection_depth( obj.data.hash.aout[selection].depth() ); hold.ischanged('1');
397                                                                                 var robj = obj.network.simple_request('FM_AHR_UPDATE',[ ses(), hold ]);
398                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
399                                                                         }
400                                                                         obj.retrieve();
401                                                                 }
402                                                         } catch(E) {
403                                                                 obj.error.standard_unexpected_error_alert('Holds not likely modified.',E);
404                                                         }
405                                                 }
406                                         ],
407
408                                         'cmd_holds_edit_pickup_lib' : [
409                                                 ['command'],
410                                                 function() {
411                                                         try {
412                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional'); 
413                                                                 var list = util.functional.map_list(
414                                                                         obj.data.list.aou,
415                                                                         function(o) { 
416                                                                                 var sname = o.shortname(); for (i = sname.length; i < 20; i++) sname += ' ';
417                                                                                 return [
418                                                                                         o.name() ? sname + ' ' + o.name() : o.shortname(),
419                                                                                         o.id(),
420                                                                                         ( obj.data.hash.aout[ o.ou_type() ].can_have_users() == 0),
421                                                                                         ( obj.data.hash.aout[ o.ou_type() ].depth() * 2),
422                                                                                 ]; 
423                                                                         }
424                                                                 );
425                                                                 ml = util.widgets.make_menulist( list, obj.data.list.au[0].ws_ou() );
426                                                                 ml.setAttribute('id','lib');
427                                                                 ml.setAttribute('name','fancy_data');
428                                                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
429                                                                 xml += '<description>Please choose a new Pickup Library:</description>';
430                                                                 xml += util.widgets.serialize_node(ml);
431                                                                 xml += '</vbox>';
432                                                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
433                                                                 bot_xml += '<spacer flex="1"/><button label="Done" accesskey="D" name="fancy_submit"/>';
434                                                                 bot_xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
435                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
436                                                                 obj.data.temp_mid = xml; obj.data.stash('temp_mid');
437                                                                 obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
438                                                                 window.open(
439                                                                         urls.XUL_FANCY_PROMPT
440                                                                         + '?xml_in_stash=temp_mid'
441                                                                         + '&bottom_xml_in_stash=temp_bot'
442                                                                         + '&title=' + window.escape('Choose a Pick Up Library'),
443                                                                         'fancy_prompt', 'chrome,resizable,modal'
444                                                                 );
445                                                                 obj.data.init({'via':'stash'});
446                                                                 if (obj.data.fancy_prompt_data == '') { return; }
447                                                                 var pickup_lib = obj.data.fancy_prompt_data.lib;
448                                                                 var msg = 'Are you sure you would like to change the Pick Up Lib for hold' + ( obj.retrieve_ids.length > 1 ? 's ' : ' ') + util.functional.map_list( obj.retrieve_ids, function(o){return o.id;}).join(', ') + ' to ' + obj.data.hash.aou[pickup_lib].shortname() + '?';
449                                                                 var r = obj.error.yns_alert(msg,'Modifying Holds','Yes','No',null,'Check here to confirm this message');
450                                                                 if (r == 0) {
451                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
452                                                                                 var hold = obj.holds_map[ obj.retrieve_ids[i].id ];
453                                                                                 hold.pickup_lib(  pickup_lib ); hold.ischanged('1');
454                                                                                 var robj = obj.network.simple_request('FM_AHR_UPDATE',[ ses(), hold ]);
455                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
456                                                                         }
457                                                                         obj.retrieve();
458                                                                 }
459                                                         } catch(E) {
460                                                                 obj.error.standard_unexpected_error_alert('Holds not likely modified.',E);
461                                                         }
462                                                 }
463                                         ],
464                                         'cmd_holds_edit_phone_notify' : [
465                                                 ['command'],
466                                                 function() {
467                                                         try {
468                                                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
469                                                                 xml += '<description>Please enter a new phone number for hold notification (leave the field empty to disable phone notification):</description>';
470                                                                 xml += '<textbox id="phone" name="fancy_data"/>';
471                                                                 xml += '</vbox>';
472                                                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
473                                                                 bot_xml += '<spacer flex="1"/><button label="Done" accesskey="D" name="fancy_submit"/>';
474                                                                 bot_xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
475                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
476                                                                 obj.data.temp_mid = xml; obj.data.stash('temp_mid');
477                                                                 obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
478                                                                 window.open(
479                                                                         urls.XUL_FANCY_PROMPT
480                                                                         + '?xml_in_stash=temp_mid'
481                                                                         + '&bottom_xml_in_stash=temp_bot'
482                                                                         + '&title=' + window.escape('Choose a Hold Notification Phone Number')
483                                                                         + '&focus=phone',
484                                                                         'fancy_prompt', 'chrome,resizable,modal'
485                                                                 );
486                                                                 obj.data.init({'via':'stash'});
487                                                                 if (obj.data.fancy_prompt_data == '') { return; }
488                                                                 var phone = obj.data.fancy_prompt_data.phone;
489                                                                 var msg = 'Are you sure you would like to change the Notification Phone Number for hold' + ( obj.retrieve_ids.length > 1 ? 's ' : ' ') + util.functional.map_list( obj.retrieve_ids, function(o){return o.id;}).join(', ') + ' to "' + phone + '"?';
490                                                                 var r = obj.error.yns_alert(msg,'Modifying Holds','Yes','No',null,'Check here to confirm this message');
491                                                                 if (r == 0) {
492                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
493                                                                                 var hold = obj.holds_map[ obj.retrieve_ids[i].id ];
494                                                                                 hold.phone_notify(  phone ); hold.ischanged('1');
495                                                                                 var robj = obj.network.simple_request('FM_AHR_UPDATE',[ ses(), hold ]);
496                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
497                                                                         }
498                                                                         obj.retrieve();
499                                                                 }
500                                                         } catch(E) {
501                                                                 obj.error.standard_unexpected_error_alert('Holds not likely modified.',E);
502                                                         }
503                                                 }
504                                         ],
505                                         'cmd_holds_edit_email_notify' : [
506                                                 ['command'],
507                                                 function() {
508                                                         try {
509                                                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
510                                                                 xml += '<description>Send email notifications (when appropriate)?  The email address used is found in the hold recepient account.</description>';
511                                                                 xml += '<hbox><button value="email" label="Email" accesskey="E" name="fancy_submit"/>';
512                                                                 xml += '<button value="noemail" label="No Email" accesskey="N" name="fancy_submit"/></hbox>';
513                                                                 xml += '</vbox>';
514                                                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
515                                                                 bot_xml += '<spacer flex="1"/><button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
516                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
517                                                                 obj.data.temp_mid = xml; obj.data.stash('temp_mid');
518                                                                 obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
519                                                                 window.open(
520                                                                         urls.XUL_FANCY_PROMPT
521                                                                         + '?xml_in_stash=temp_mid'
522                                                                         + '&bottom_xml_in_stash=temp_bot'
523                                                                         + '&title=' + window.escape('Set Email Notification for Holds'),
524                                                                         'fancy_prompt', 'chrome,resizable,modal'
525                                                                 );
526                                                                 obj.data.init({'via':'stash'});
527                                                                 if (obj.data.fancy_prompt_data == '') { return; }
528                                                                 var email = obj.data.fancy_prompt_data.fancy_submit == 'email' ? get_db_true() : get_db_false();
529                                                                 var msg = 'Are you sure you would like ' + ( get_bool( email ) ? 'enable' : 'disable' ) + ' email notification for hold' + ( obj.retrieve_ids.length > 1 ? 's ' : ' ') + util.functional.map_list( obj.retrieve_ids, function(o){return o.id;}).join(', ') + '?';
530                                                                 var r = obj.error.yns_alert(msg,'Modifying Holds','Yes','No',null,'Check here to confirm this message');
531                                                                 if (r == 0) {
532                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
533                                                                                 var hold = obj.holds_map[ obj.retrieve_ids[i].id ];
534                                                                                 hold.email_notify(  email ); hold.ischanged('1');
535                                                                                 var robj = obj.network.simple_request('FM_AHR_UPDATE',[ ses(), hold ]);
536                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
537                                                                         }
538                                                                         obj.retrieve();
539                                                                 }
540                                                         } catch(E) {
541                                                                 obj.error.standard_unexpected_error_alert('Holds not likely modified.',E);
542                                                         }
543                                                 }
544                                         ],
545
546
547                                         'cmd_holds_retarget' : [
548                                                 ['command'],
549                                                 function() {
550                                                         try {
551                                                                 JSAN.use('util.functional');
552                                                                 var msg = 'Are you sure you would like to reset hold' + ( obj.retrieve_ids.length > 1 ? 's ' : ' ') + util.functional.map_list( obj.retrieve_ids, function(o){return o.id;}).join(', ') + '?';
553                                                                 var r = obj.error.yns_alert(msg,'Resetting Holds','Yes','No',null,'Check here to confirm this message');
554                                                                 if (r == 0) {
555                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
556                                                                                 var robj = obj.network.simple_request('FM_AHR_RESET',[ ses(), obj.retrieve_ids[i].id]);
557                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
558                                                                         }
559                                                                         obj.retrieve();
560                                                                 }
561                                                         } catch(E) {
562                                                                 obj.error.standard_unexpected_error_alert('Holds not likely reset.',E);
563                                                         }
564
565                                                 }
566                                         ],
567
568                                         'cmd_holds_cancel' : [
569                                                 ['command'],
570                                                 function() {
571                                                         try {
572                                                                 JSAN.use('util.functional');
573                                                                 var msg = 'Are you sure you would like to cancel hold' + ( obj.retrieve_ids.length > 1 ? 's ' : ' ') + util.functional.map_list( obj.retrieve_ids, function(o){return o.id;}).join(', ') + '?';
574                                                                 var r = obj.error.yns_alert(msg,'Cancelling Holds','Yes','No',null,'Check here to confirm this message');
575                                                                 if (r == 0) {
576                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
577                                                                                 var robj = obj.network.simple_request('FM_AHR_CANCEL',[ ses(), obj.retrieve_ids[i].id]);
578                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
579                                                                         }
580                                                                         obj.retrieve();
581                                                                 }
582                                                         } catch(E) {
583                                                                 obj.error.standard_unexpected_error_alert('Holds not likely cancelled.',E);
584                                                         }
585                                                 }
586                                         ],
587                                         'cmd_retrieve_patron' : [
588                                                 ['command'],
589                                                 function() {
590                                                         try {
591                                                                 var seen = {};
592                                                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
593                                                                         var patron_id = obj.retrieve_ids[i].usr;
594                                                                         if (seen[patron_id]) continue; seen[patron_id] = true;
595                                                                         xulG.new_tab(
596                                                                                 xulG.url_prefix(urls.XUL_PATRON_DISPLAY) + '?id=' + patron_id, 
597                                                                                 {}, 
598                                                                                 {}
599                                                                         );
600                                                                 }
601                                                         } catch(E) {
602                                                                 obj.error.standard_unexpected_error_alert('',E);
603                                                         }
604                                                 }
605                                         ],
606                                         'cmd_show_catalog' : [
607                                                 ['command'],
608                                                 function() {
609                                                         try {
610                                                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
611                                                                         var htarget = obj.retrieve_ids[i].target;
612                                                                         var htype = obj.retrieve_ids[i].type;
613                                                                         var opac_url;
614                                                                         switch(htype) {
615                                                                                 case 'M' :
616                                                                                         opac_url = xulG.url_prefix( urls.opac_rresult ) + '?m=' + htarget;
617                                                                                 break;
618                                                                                 case 'T' : 
619                                                                                         opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + htarget;
620                                                                                 break;
621                                                                                 case 'V' :
622                                                                                         var my_acn = obj.network.simple_request( 'FM_ACN_RETRIEVE', [ htarget ]);
623                                                                                         opac_url = xulG.url_prefix( urls.opac_rdetail) + '?r=' + my_acn.record();
624                                                                                 break;
625                                                                                 case 'C' :
626                                                                                         var my_acp = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ htarget ]);
627                                                                                         var my_acn;
628                                                                                         if (typeof my_acp.call_number() == 'object') {
629                                                                                                 my_acn = my.acp.call_number();
630                                                                                         } else {
631                                                                                                 my_acn = obj.network.simple_request( 'FM_ACN_RETRIEVE', 
632                                                                                                         [ my_acp.call_number() ]);
633                                                                                         }
634                                                                                         opac_url = xulG.url_prefix( urls.opac_rdetail) + '?r=' + my_acn.record();
635                                                                                 break;
636                                                                                 default:
637                                                                                         obj.error.standard_unexpected_error_alert("I don't understand the hold type of " + htype + ", so I can't jump to the appropriate record in the catalog.", obj.retrieve_ids[i]);
638                                                                                         continue;
639                                                                                 break;
640                                                                         }
641                                                                         var content_params = { 
642                                                                                 'session' : ses(),
643                                                                                 'authtime' : ses('authtime'),
644                                                                                 'opac_url' : opac_url,
645                                                                         };
646                                                                         xulG.new_tab(
647                                                                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
648                                                                                 {'tab_name': htype == 'M' ? 'Catalog' : 'Retrieving title...'}, 
649                                                                                 content_params
650                                                                         );
651                                                                 }
652                                                         } catch(E) {
653                                                                 obj.error.standard_unexpected_error_alert('',E);
654                                                         }
655                                                 }
656                                         ],
657                                 }
658                         }
659                 );
660                 obj.controller.render();
661
662                 obj.retrieve();
663
664                 obj.controller.view.cmd_retrieve_patron.setAttribute('disabled','true');
665                 obj.controller.view.cmd_holds_edit_pickup_lib.setAttribute('disabled','true');
666                 obj.controller.view.cmd_holds_edit_phone_notify.setAttribute('disabled','true');
667                 obj.controller.view.cmd_holds_edit_email_notify.setAttribute('disabled','true');
668                 obj.controller.view.cmd_holds_edit_selection_depth.setAttribute('disabled','true');
669                 obj.controller.view.cmd_show_notifications.setAttribute('disabled','true');
670                 obj.controller.view.cmd_holds_retarget.setAttribute('disabled','true');
671                 obj.controller.view.cmd_holds_cancel.setAttribute('disabled','true');
672                 obj.controller.view.cmd_show_catalog.setAttribute('disabled','true');
673         },
674
675         'retrieve' : function(dont_show_me_the_list_change) {
676                 var obj = this;
677                 if (window.xulG && window.xulG.holds) {
678                         obj.holds = window.xulG.holds;
679                 } else {
680                         var method; var params = [ ses() ];
681                         if (obj.patron_id) {                 /*************************************************** PATRON ******************************/
682                                 method = 'FM_AHR_ID_LIST_RETRIEVE_VIA_AU'; 
683                                 params.push( obj.patron_id ); 
684                                 obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','true');
685                         } else if (obj.docid) {                 /*************************************************** RECORD ******************************/
686                                 method = 'FM_AHR_RETRIEVE_ALL_VIA_BRE'; 
687                                 params.push( obj.docid ); 
688                                 obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','false');
689                         } else if (obj.pull) {                 /*************************************************** PULL ******************************/
690                                 method = 'FM_AHR_ID_LIST_PULL_LIST'; 
691                                 params.push( 50 ); params.push( 0 );
692                         } else if (obj.shelf) {
693                                 method = 'FM_AHR_ID_LIST_ONSHELF_RETRIEVE';                  /*************************************************** HOLD SHELF ******************************/
694                                 params.push( obj.foreign_shelf || obj.data.list.au[0].ws_ou() ); 
695                                 obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','false');
696                                 obj.render_lib_menu();
697                         } else {
698                                 //method = 'FM_AHR_RETRIEVE_VIA_PICKUP_AOU'; 
699                                 method = 'FM_AHR_ID_LIST_PULL_LIST';                  /*************************************************** PULL ******************************/
700                                 params.push( 50 ); params.push( 0 );
701                                 obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','false');
702                         }
703                         var robj = obj.network.simple_request( method, params );
704                         if (typeof robj.ilsevent != 'undefined') throw(robj);
705                         if (method == 'FM_AHR_RETRIEVE_ALL_VIA_BRE') {
706                                 obj.holds = [];
707                                 obj.holds = obj.holds.concat( robj.copy_holds );
708                                 obj.holds = obj.holds.concat( robj.volume_holds );
709                                 obj.holds = obj.holds.concat( robj.title_holds );
710                                 obj.holds = obj.holds.sort();
711                         } else {
712                                 obj.holds = robj;
713                         }
714                         //alert('method = ' + method + ' params = ' + js2JSON(params));
715                 }
716
717                 function list_append(hold_id) {
718                         obj.list.append(
719                                 {
720                                         'row' : {
721                                                 'my' : {
722                                                         'hold_id' : hold_id,
723                                                 }
724                                         }
725                                 }
726                         );
727                 }
728
729                 function gen_list_append(hold) {
730                         return function() {
731                                 if (typeof obj.controller.view.lib_menu == 'undefined') {
732                                         list_append(typeof hold == 'object' ? hold.id() : hold);
733                                 } else {
734                                         /*
735                                         var pickup_lib = hold.pickup_lib();
736                                         if (typeof pickup_lib == 'object') pickup_lib = pickup_lib.id();
737                                         if (pickup_lib == obj.controller.view.lib_menu.value) {
738                                         */
739                                                 list_append(typeof hold == 'object' ? hold.id() : hold);
740                                         /*
741                                         }
742                                         */
743                                 }
744                         };
745                 }
746
747                 obj.list.clear();
748
749                 //alert('obj.holds = ' + js2JSON(obj.holds));
750                 JSAN.use('util.exec'); var exec = new util.exec(2);
751                 var rows = [];
752                 for (var i in obj.holds) {
753                         rows.push( gen_list_append(obj.holds[i]) );
754                 }
755                 exec.chain( rows );
756         
757                 if (!dont_show_me_the_list_change) {
758                         if (window.xulG && typeof window.xulG.on_list_change == 'function') {
759                                 try { window.xulG.on_list_change(obj.holds); } catch(E) { this.error.sdump('D_ERROR',E); }
760                         }
761                 }
762         },
763
764         'render_lib_menu' : function() {
765                 try {
766                         var obj = this;
767                         JSAN.use('util.widgets'); JSAN.use('util.functional'); JSAN.use('util.fm_utils');
768                         var x = document.getElementById('menu_placeholder');
769                         if (x.firstChild) return;
770                         util.widgets.remove_children( x );
771         
772                         var ml = util.widgets.make_menulist( 
773                                 util.functional.map_list( 
774                                         obj.data.list.my_aou.concat(
775                                                 util.functional.filter_list(
776                                                         util.fm_utils.find_ou(
777                                                                 obj.data.tree.aou,
778                                                                 obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou()
779                                                         ).children(),
780                                                         function(o) {
781                                                                 return o.id() != obj.data.list.au[0].ws_ou();
782                                                         }
783                                                 )
784                                         ),
785                                         function(o) { return [ 
786                                                 o.shortname(), 
787                                                 o.id(), 
788                                                 ( ! get_bool( obj.data.hash.aout[ o.ou_type() ].can_have_users() ) ),
789                                                 ( obj.data.hash.aout[ o.ou_type() ].depth() ),
790                                         ]; }
791                                 ).sort(
792                                         function( a, b ) {
793                                                 var A = obj.data.hash.aou[ a[1] ];
794                                                 var B = obj.data.hash.aou[ b[1] ];
795                                                 var X = obj.data.hash.aout[ A.ou_type() ];
796                                                 var Y = obj.data.hash.aout[ B.ou_type() ];
797                                                 if (X.depth() < Y.depth()) return -1;
798                                                 if (X.depth() > Y.depth()) return 1;
799                                                 if (A.shortname() < B.shortname()) return -1;
800                                                 if (A.shortname() > B.shortname()) return 1;
801                                                 return 0;
802                                         }
803                                 ),
804                                 obj.data.list.au[0].ws_ou()
805                         );
806                         x.appendChild( ml );
807                         ml.addEventListener(
808                                 'command',
809                                 function(ev) {
810                                         /*
811                                         obj.list.on_all_fleshed = function() {
812                                                 obj.list.clear();
813                                                 obj.foreign_shelf = ev.target.value;
814                                                 obj.retrieve();
815                                                 setTimeout( function() { obj.list.on_all_fleshed = null; }, 0);
816                                         };
817                                         obj.list.full_retrieve();
818                                         */
819                                         obj.list.clear();
820                                         obj.foreign_shelf = ev.target.value;
821                                         obj.retrieve();
822                                 },
823                                 false
824                         );
825                         obj.controller.view.lib_menu = ml;
826                 } catch(E) {
827                         this.error.standard_unexpected_error_alert('rendering lib menu',E);
828                 }
829         },
830 }
831
832 dump('exiting patron.holds.js\n');