]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/holds.js
export csv from list to clipboard
[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_columns' : circ.util.std_map_row_to_columns(),
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_holds_export' : [
327                                                 ['command'],
328                                                 function() {
329                                                         try {
330                                                                 function flesh_callback() {
331                                                                         try {
332                                                                                 dump(obj.list.dump_csv() + '\n');
333                                                                                 copy_to_clipboard(obj.list.dump_csv());
334                                                                                 setTimeout(function(){obj.list.on_all_fleshed = null;},0);
335                                                                         } catch(E) {
336                                                                                 obj.error.standard_unexpected_error_alert('export 2',E);
337                                                                         }
338                                                                 }
339                                                                 obj.list.on_all_fleshed = flesh_callback;
340                                                                 obj.list.full_retrieve();
341                                                         } catch(E) {
342                                                                 obj.error.standard_unexpected_error_alert('export 1',E);
343                                                         }
344                                                 }
345                                         ],
346
347                                         'cmd_show_notifications' : [
348                                                 ['command'],
349                                                 function() {
350                                                         try {
351                                                                 JSAN.use('util.window'); var win = new util.window();
352                                                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
353                                                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
354                                                                         win.open(
355                                                                                 xulG.url_prefix(urls.XUL_HOLD_NOTICES) 
356                                                                                 + '?ahr_id=' + obj.retrieve_ids[i].id,
357                                                                                 'hold_notices_' + obj.retrieve_ids[i].id,
358                                                                                 'chrome,resizable'
359                                                                         );
360                                                                 }
361                                                         } catch(E) {
362                                                                 obj.error.standard_unexpected_error_alert('Error rendering/retrieving hold notifications.',E);
363                                                         }
364                                                 }
365                                         ],
366                                         'cmd_holds_edit_selection_depth' : [
367                                                 ['command'],
368                                                 function() {
369                                                         try {
370                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional'); 
371                                                                 var ws_type = obj.data.hash.aout[ obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].ou_type() ];
372                                                                 var list = util.functional.map_list(
373                                                                         util.functional.filter_list(    
374                                                                                 obj.data.list.aout,
375                                                                                 function(o) {
376                                                                                         if (o.depth() > ws_type.depth()) return false;
377                                                                                         if (o.depth() < ws_type.depth()) return true;
378                                                                                         return (o.id() == ws_type.id());
379                                                                                 }
380                                                                         ),
381                                                                         function(o) { 
382                                                                                 return [
383                                                                                         o.opac_label(),
384                                                                                         o.id(),
385                                                                                         false,
386                                                                                         ( o.depth() * 2),
387                                                                                 ]; 
388                                                                         }
389                                                                 );
390                                                                 ml = util.widgets.make_menulist( list, obj.data.list.au[0].ws_ou() );
391                                                                 ml.setAttribute('id','selection');
392                                                                 ml.setAttribute('name','fancy_data');
393                                                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
394                                                                 xml += '<description>Please choose a Hold Range:</description>';
395                                                                 xml += util.widgets.serialize_node(ml);
396                                                                 xml += '</vbox>';
397                                                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
398                                                                 bot_xml += '<spacer flex="1"/><button label="Done" accesskey="D" name="fancy_submit"/>';
399                                                                 bot_xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
400                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
401                                                                 obj.data.temp_mid = xml; obj.data.stash('temp_mid');
402                                                                 obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
403                                                                 window.open(
404                                                                         urls.XUL_FANCY_PROMPT
405                                                                         + '?xml_in_stash=temp_mid'
406                                                                         + '&bottom_xml_in_stash=temp_bot'
407                                                                         + '&title=' + window.escape('Choose a Pick Up Library'),
408                                                                         'fancy_prompt', 'chrome,resizable,modal'
409                                                                 );
410                                                                 obj.data.init({'via':'stash'});
411                                                                 if (obj.data.fancy_prompt_data == '') { return; }
412                                                                 var selection = obj.data.fancy_prompt_data.selection;
413                                                                 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() + '"?';
414                                                                 var r = obj.error.yns_alert(msg,'Modifying Holds','Yes','No',null,'Check here to confirm this message');
415                                                                 if (r == 0) {
416                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
417                                                                                 var hold = obj.holds_map[ obj.retrieve_ids[i].id ];
418                                                                                 hold.selection_depth( obj.data.hash.aout[selection].depth() ); hold.ischanged('1');
419                                                                                 var robj = obj.network.simple_request('FM_AHR_UPDATE',[ ses(), hold ]);
420                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
421                                                                         }
422                                                                         obj.retrieve();
423                                                                 }
424                                                         } catch(E) {
425                                                                 obj.error.standard_unexpected_error_alert('Holds not likely modified.',E);
426                                                         }
427                                                 }
428                                         ],
429
430                                         'cmd_holds_edit_pickup_lib' : [
431                                                 ['command'],
432                                                 function() {
433                                                         try {
434                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional'); 
435                                                                 var list = util.functional.map_list(
436                                                                         obj.data.list.aou,
437                                                                         function(o) { 
438                                                                                 var sname = o.shortname(); for (i = sname.length; i < 20; i++) sname += ' ';
439                                                                                 return [
440                                                                                         o.name() ? sname + ' ' + o.name() : o.shortname(),
441                                                                                         o.id(),
442                                                                                         ( obj.data.hash.aout[ o.ou_type() ].can_have_users() == 0),
443                                                                                         ( obj.data.hash.aout[ o.ou_type() ].depth() * 2),
444                                                                                 ]; 
445                                                                         }
446                                                                 );
447                                                                 ml = util.widgets.make_menulist( list, obj.data.list.au[0].ws_ou() );
448                                                                 ml.setAttribute('id','lib');
449                                                                 ml.setAttribute('name','fancy_data');
450                                                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
451                                                                 xml += '<description>Please choose a new Pickup Library:</description>';
452                                                                 xml += util.widgets.serialize_node(ml);
453                                                                 xml += '</vbox>';
454                                                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
455                                                                 bot_xml += '<spacer flex="1"/><button label="Done" accesskey="D" name="fancy_submit"/>';
456                                                                 bot_xml += '<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('Choose a Pick Up Library'),
465                                                                         'fancy_prompt', 'chrome,resizable,modal'
466                                                                 );
467                                                                 obj.data.init({'via':'stash'});
468                                                                 if (obj.data.fancy_prompt_data == '') { return; }
469                                                                 var pickup_lib = obj.data.fancy_prompt_data.lib;
470                                                                 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() + '?';
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.pickup_lib(  pickup_lib ); 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                                         'cmd_holds_edit_phone_notify' : [
487                                                 ['command'],
488                                                 function() {
489                                                         try {
490                                                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
491                                                                 xml += '<description>Please enter a new phone number for hold notification (leave the field empty to disable phone notification):</description>';
492                                                                 xml += '<textbox id="phone" name="fancy_data"/>';
493                                                                 xml += '</vbox>';
494                                                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
495                                                                 bot_xml += '<spacer flex="1"/><button label="Done" accesskey="D" name="fancy_submit"/>';
496                                                                 bot_xml += '<button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
497                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
498                                                                 obj.data.temp_mid = xml; obj.data.stash('temp_mid');
499                                                                 obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
500                                                                 window.open(
501                                                                         urls.XUL_FANCY_PROMPT
502                                                                         + '?xml_in_stash=temp_mid'
503                                                                         + '&bottom_xml_in_stash=temp_bot'
504                                                                         + '&title=' + window.escape('Choose a Hold Notification Phone Number')
505                                                                         + '&focus=phone',
506                                                                         'fancy_prompt', 'chrome,resizable,modal'
507                                                                 );
508                                                                 obj.data.init({'via':'stash'});
509                                                                 if (obj.data.fancy_prompt_data == '') { return; }
510                                                                 var phone = obj.data.fancy_prompt_data.phone;
511                                                                 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 + '"?';
512                                                                 var r = obj.error.yns_alert(msg,'Modifying Holds','Yes','No',null,'Check here to confirm this message');
513                                                                 if (r == 0) {
514                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
515                                                                                 var hold = obj.holds_map[ obj.retrieve_ids[i].id ];
516                                                                                 hold.phone_notify(  phone ); hold.ischanged('1');
517                                                                                 var robj = obj.network.simple_request('FM_AHR_UPDATE',[ ses(), hold ]);
518                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
519                                                                         }
520                                                                         obj.retrieve();
521                                                                 }
522                                                         } catch(E) {
523                                                                 obj.error.standard_unexpected_error_alert('Holds not likely modified.',E);
524                                                         }
525                                                 }
526                                         ],
527                                         'cmd_holds_edit_email_notify' : [
528                                                 ['command'],
529                                                 function() {
530                                                         try {
531                                                                 var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
532                                                                 xml += '<description>Send email notifications (when appropriate)?  The email address used is found in the hold recepient account.</description>';
533                                                                 xml += '<hbox><button value="email" label="Email" accesskey="E" name="fancy_submit"/>';
534                                                                 xml += '<button value="noemail" label="No Email" accesskey="N" name="fancy_submit"/></hbox>';
535                                                                 xml += '</vbox>';
536                                                                 var bot_xml = '<hbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" style="overflow: vertical">';
537                                                                 bot_xml += '<spacer flex="1"/><button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox>';
538                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
539                                                                 obj.data.temp_mid = xml; obj.data.stash('temp_mid');
540                                                                 obj.data.temp_bot = bot_xml; obj.data.stash('temp_bot');
541                                                                 window.open(
542                                                                         urls.XUL_FANCY_PROMPT
543                                                                         + '?xml_in_stash=temp_mid'
544                                                                         + '&bottom_xml_in_stash=temp_bot'
545                                                                         + '&title=' + window.escape('Set Email Notification for Holds'),
546                                                                         'fancy_prompt', 'chrome,resizable,modal'
547                                                                 );
548                                                                 obj.data.init({'via':'stash'});
549                                                                 if (obj.data.fancy_prompt_data == '') { return; }
550                                                                 var email = obj.data.fancy_prompt_data.fancy_submit == 'email' ? get_db_true() : get_db_false();
551                                                                 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(', ') + '?';
552                                                                 var r = obj.error.yns_alert(msg,'Modifying Holds','Yes','No',null,'Check here to confirm this message');
553                                                                 if (r == 0) {
554                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
555                                                                                 var hold = obj.holds_map[ obj.retrieve_ids[i].id ];
556                                                                                 hold.email_notify(  email ); hold.ischanged('1');
557                                                                                 var robj = obj.network.simple_request('FM_AHR_UPDATE',[ ses(), hold ]);
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 modified.',E);
564                                                         }
565                                                 }
566                                         ],
567
568
569                                         'cmd_holds_retarget' : [
570                                                 ['command'],
571                                                 function() {
572                                                         try {
573                                                                 JSAN.use('util.functional');
574                                                                 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(', ') + '?';
575                                                                 var r = obj.error.yns_alert(msg,'Resetting 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_RESET',[ 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 reset.',E);
585                                                         }
586
587                                                 }
588                                         ],
589
590                                         'cmd_holds_cancel' : [
591                                                 ['command'],
592                                                 function() {
593                                                         try {
594                                                                 JSAN.use('util.functional');
595                                                                 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(', ') + '?';
596                                                                 var r = obj.error.yns_alert(msg,'Cancelling Holds','Yes','No',null,'Check here to confirm this message');
597                                                                 if (r == 0) {
598                                                                         for (var i = 0; i < obj.retrieve_ids.length; i++) {
599                                                                                 var robj = obj.network.simple_request('FM_AHR_CANCEL',[ ses(), obj.retrieve_ids[i].id]);
600                                                                                 if (typeof robj.ilsevent != 'undefined') throw(robj);
601                                                                         }
602                                                                         obj.retrieve();
603                                                                 }
604                                                         } catch(E) {
605                                                                 obj.error.standard_unexpected_error_alert('Holds not likely cancelled.',E);
606                                                         }
607                                                 }
608                                         ],
609                                         'cmd_retrieve_patron' : [
610                                                 ['command'],
611                                                 function() {
612                                                         try {
613                                                                 var seen = {};
614                                                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
615                                                                         var patron_id = obj.retrieve_ids[i].usr;
616                                                                         if (seen[patron_id]) continue; seen[patron_id] = true;
617                                                                         xulG.new_tab(
618                                                                                 xulG.url_prefix(urls.XUL_PATRON_DISPLAY) + '?id=' + patron_id, 
619                                                                                 {}, 
620                                                                                 {}
621                                                                         );
622                                                                 }
623                                                         } catch(E) {
624                                                                 obj.error.standard_unexpected_error_alert('',E);
625                                                         }
626                                                 }
627                                         ],
628                                         'cmd_show_catalog' : [
629                                                 ['command'],
630                                                 function() {
631                                                         try {
632                                                                 for (var i = 0; i < obj.retrieve_ids.length; i++) {
633                                                                         var htarget = obj.retrieve_ids[i].target;
634                                                                         var htype = obj.retrieve_ids[i].type;
635                                                                         var opac_url;
636                                                                         switch(htype) {
637                                                                                 case 'M' :
638                                                                                         opac_url = xulG.url_prefix( urls.opac_rresult ) + '?m=' + htarget;
639                                                                                 break;
640                                                                                 case 'T' : 
641                                                                                         opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + htarget;
642                                                                                 break;
643                                                                                 case 'V' :
644                                                                                         var my_acn = obj.network.simple_request( 'FM_ACN_RETRIEVE', [ htarget ]);
645                                                                                         opac_url = xulG.url_prefix( urls.opac_rdetail) + '?r=' + my_acn.record();
646                                                                                 break;
647                                                                                 case 'C' :
648                                                                                         var my_acp = obj.network.simple_request( 'FM_ACP_RETRIEVE', [ htarget ]);
649                                                                                         var my_acn;
650                                                                                         if (typeof my_acp.call_number() == 'object') {
651                                                                                                 my_acn = my.acp.call_number();
652                                                                                         } else {
653                                                                                                 my_acn = obj.network.simple_request( 'FM_ACN_RETRIEVE', 
654                                                                                                         [ my_acp.call_number() ]);
655                                                                                         }
656                                                                                         opac_url = xulG.url_prefix( urls.opac_rdetail) + '?r=' + my_acn.record();
657                                                                                 break;
658                                                                                 default:
659                                                                                         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]);
660                                                                                         continue;
661                                                                                 break;
662                                                                         }
663                                                                         var content_params = { 
664                                                                                 'session' : ses(),
665                                                                                 'authtime' : ses('authtime'),
666                                                                                 'opac_url' : opac_url,
667                                                                         };
668                                                                         xulG.new_tab(
669                                                                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
670                                                                                 {'tab_name': htype == 'M' ? 'Catalog' : 'Retrieving title...'}, 
671                                                                                 content_params
672                                                                         );
673                                                                 }
674                                                         } catch(E) {
675                                                                 obj.error.standard_unexpected_error_alert('',E);
676                                                         }
677                                                 }
678                                         ],
679                                 }
680                         }
681                 );
682                 obj.controller.render();
683
684                 obj.retrieve();
685
686                 obj.controller.view.cmd_retrieve_patron.setAttribute('disabled','true');
687                 obj.controller.view.cmd_holds_edit_pickup_lib.setAttribute('disabled','true');
688                 obj.controller.view.cmd_holds_edit_phone_notify.setAttribute('disabled','true');
689                 obj.controller.view.cmd_holds_edit_email_notify.setAttribute('disabled','true');
690                 obj.controller.view.cmd_holds_edit_selection_depth.setAttribute('disabled','true');
691                 obj.controller.view.cmd_show_notifications.setAttribute('disabled','true');
692                 obj.controller.view.cmd_holds_retarget.setAttribute('disabled','true');
693                 obj.controller.view.cmd_holds_cancel.setAttribute('disabled','true');
694                 obj.controller.view.cmd_show_catalog.setAttribute('disabled','true');
695         },
696
697         'retrieve' : function(dont_show_me_the_list_change) {
698                 var obj = this;
699                 if (window.xulG && window.xulG.holds) {
700                         obj.holds = window.xulG.holds;
701                 } else {
702                         var method; var params = [ ses() ];
703                         if (obj.patron_id) {                 /*************************************************** PATRON ******************************/
704                                 method = 'FM_AHR_ID_LIST_RETRIEVE_VIA_AU'; 
705                                 params.push( obj.patron_id ); 
706                                 obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','true');
707                         } else if (obj.docid) {                 /*************************************************** RECORD ******************************/
708                                 method = 'FM_AHR_RETRIEVE_ALL_VIA_BRE'; 
709                                 params.push( obj.docid ); 
710                                 obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','false');
711                         } else if (obj.pull) {                 /*************************************************** PULL ******************************/
712                                 method = 'FM_AHR_ID_LIST_PULL_LIST'; 
713                                 params.push( 50 ); params.push( 0 );
714                         } else if (obj.shelf) {
715                                 method = 'FM_AHR_ID_LIST_ONSHELF_RETRIEVE';                  /*************************************************** HOLD SHELF ******************************/
716                                 params.push( obj.foreign_shelf || obj.data.list.au[0].ws_ou() ); 
717                                 obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','false');
718                                 obj.render_lib_menu();
719                         } else {
720                                 //method = 'FM_AHR_RETRIEVE_VIA_PICKUP_AOU'; 
721                                 method = 'FM_AHR_ID_LIST_PULL_LIST';                  /*************************************************** PULL ******************************/
722                                 params.push( 50 ); params.push( 0 );
723                                 obj.controller.view.cmd_retrieve_patron.setAttribute('hidden','false');
724                         }
725                         var robj = obj.network.simple_request( method, params );
726                         if (typeof robj.ilsevent != 'undefined') throw(robj);
727                         if (method == 'FM_AHR_RETRIEVE_ALL_VIA_BRE') {
728                                 obj.holds = [];
729                                 obj.holds = obj.holds.concat( robj.copy_holds );
730                                 obj.holds = obj.holds.concat( robj.volume_holds );
731                                 obj.holds = obj.holds.concat( robj.title_holds );
732                                 obj.holds = obj.holds.sort();
733                         } else {
734                                 obj.holds = robj;
735                         }
736                         //alert('method = ' + method + ' params = ' + js2JSON(params));
737                 }
738
739                 function list_append(hold_id) {
740                         obj.list.append(
741                                 {
742                                         'row' : {
743                                                 'my' : {
744                                                         'hold_id' : hold_id,
745                                                 }
746                                         }
747                                 }
748                         );
749                 }
750
751                 function gen_list_append(hold) {
752                         return function() {
753                                 if (typeof obj.controller.view.lib_menu == 'undefined') {
754                                         list_append(typeof hold == 'object' ? hold.id() : hold);
755                                 } else {
756                                         /*
757                                         var pickup_lib = hold.pickup_lib();
758                                         if (typeof pickup_lib == 'object') pickup_lib = pickup_lib.id();
759                                         if (pickup_lib == obj.controller.view.lib_menu.value) {
760                                         */
761                                                 list_append(typeof hold == 'object' ? hold.id() : hold);
762                                         /*
763                                         }
764                                         */
765                                 }
766                         };
767                 }
768
769                 obj.list.clear();
770
771                 //alert('obj.holds = ' + js2JSON(obj.holds));
772                 JSAN.use('util.exec'); var exec = new util.exec(2);
773                 var rows = [];
774                 for (var i in obj.holds) {
775                         rows.push( gen_list_append(obj.holds[i]) );
776                 }
777                 exec.chain( rows );
778         
779                 if (!dont_show_me_the_list_change) {
780                         if (window.xulG && typeof window.xulG.on_list_change == 'function') {
781                                 try { window.xulG.on_list_change(obj.holds); } catch(E) { this.error.sdump('D_ERROR',E); }
782                         }
783                 }
784         },
785
786         'render_lib_menu' : function() {
787                 try {
788                         var obj = this;
789                         JSAN.use('util.widgets'); JSAN.use('util.functional'); JSAN.use('util.fm_utils');
790                         var x = document.getElementById('menu_placeholder');
791                         if (x.firstChild) return;
792                         util.widgets.remove_children( x );
793         
794                         var ml = util.widgets.make_menulist( 
795                                 util.functional.map_list( 
796                                         obj.data.list.my_aou.concat(
797                                                 util.functional.filter_list(
798                                                         util.fm_utils.find_ou(
799                                                                 obj.data.tree.aou,
800                                                                 obj.data.hash.aou[ obj.data.list.au[0].ws_ou() ].parent_ou()
801                                                         ).children(),
802                                                         function(o) {
803                                                                 return o.id() != obj.data.list.au[0].ws_ou();
804                                                         }
805                                                 )
806                                         ),
807                                         function(o) { return [ 
808                                                 o.shortname(), 
809                                                 o.id(), 
810                                                 ( ! get_bool( obj.data.hash.aout[ o.ou_type() ].can_have_users() ) ),
811                                                 ( obj.data.hash.aout[ o.ou_type() ].depth() ),
812                                         ]; }
813                                 ).sort(
814                                         function( a, b ) {
815                                                 var A = obj.data.hash.aou[ a[1] ];
816                                                 var B = obj.data.hash.aou[ b[1] ];
817                                                 var X = obj.data.hash.aout[ A.ou_type() ];
818                                                 var Y = obj.data.hash.aout[ B.ou_type() ];
819                                                 if (X.depth() < Y.depth()) return -1;
820                                                 if (X.depth() > Y.depth()) return 1;
821                                                 if (A.shortname() < B.shortname()) return -1;
822                                                 if (A.shortname() > B.shortname()) return 1;
823                                                 return 0;
824                                         }
825                                 ),
826                                 obj.data.list.au[0].ws_ou()
827                         );
828                         x.appendChild( ml );
829                         ml.addEventListener(
830                                 'command',
831                                 function(ev) {
832                                         /*
833                                         obj.list.on_all_fleshed = function() {
834                                                 obj.list.clear();
835                                                 obj.foreign_shelf = ev.target.value;
836                                                 obj.retrieve();
837                                                 setTimeout( function() { obj.list.on_all_fleshed = null; }, 0);
838                                         };
839                                         obj.list.full_retrieve();
840                                         */
841                                         obj.list.clear();
842                                         obj.foreign_shelf = ev.target.value;
843                                         obj.retrieve();
844                                 },
845                                 false
846                         );
847                         obj.controller.view.lib_menu = ml;
848                 } catch(E) {
849                         this.error.standard_unexpected_error_alert('rendering lib menu',E);
850                 }
851         },
852 }
853
854 dump('exiting patron.holds.js\n');