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