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