]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/record_buckets.js
reserving the string "default" is lame, mozilla
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / record_buckets.js
1 dump('entering cat.record_buckets.js\n');
2
3 if (typeof cat == 'undefined') cat = {};
4 cat.record_buckets = 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('util.date');
9         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
10         this.first_pause = true;
11 };
12
13 cat.record_buckets.pick_file = function (defaultFileName) {
14         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
15
16         var nsIFilePicker = Components.interfaces.nsIFilePicker;
17         var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance( nsIFilePicker );
18
19         fp.init( window, "Save File As", nsIFilePicker.modeSave );
20         if (defaultFileName)
21                 fp.defaultString = defaultFileName;
22
23         fp.appendFilters( nsIFilePicker.filterAll );
24
25         var result = fp.show(); 
26         if ( (result == nsIFilePicker.returnOK || result == nsIFilePicker.returnReplace) && fp.file ) {
27                 return fp.file;
28         } else {
29                 return null;
30         }
31 };
32
33 cat.record_buckets.export_records = function(output_type) {
34         try {
35                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
36                 obj.list2.select_all();
37                 obj.data.stash_retrieve();
38                 JSAN.use('util.functional');
39
40                 var record_ids = util.functional.map_list(
41                         obj.list2.dump_retrieve_ids(),
42                         function (o) { return JSON2js(o).docid }
43                 );
44
45                 var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
46                         .createInstance(Components.interfaces.nsIWebBrowserPersist);
47
48                 var proto_uri = 'http://' + window.location.hostname + '/exporter';
49
50                 dump('Record Export URI is ' + proto_uri + '?id=' + record_ids.join('&id=') + '\n');
51
52                 var uri = Components.classes["@mozilla.org/network/io-service;1"]
53                         .getService(Components.interfaces.nsIIOService)
54                         .newURI( proto_uri + '?id=' + record_ids.join('&id='), null, null );
55
56                 var file = pick_file('bucket.' + output_type);
57                                                                 
58                 if (file) {
59                         persist.saveURI(uri,null,null,null,null,file);
60                 } else {
61                         alert("File not downloaded.");
62                 }
63
64         } catch(E) {
65                 obj.error.standard_unexpected_error_alert('Records could not be exported.',E);
66         }
67 };
68
69
70 cat.record_buckets.prototype = {
71         'selection_list1' : [],
72         'selection_list2' : [],
73         'bucket_id_name_map' : {},
74
75         'render_pending_records' : function() {
76                 if (this.first_pause) {
77                         this.first_pause = false;
78                 } else {
79                         alert("Action completed.");
80                 }
81                 var obj = this;
82                 obj.list1.clear();
83                 for (var i = 0; i < obj.record_ids.length; i++) {
84                         var item = obj.flesh_item_for_list( obj.record_ids[i] );
85                         if (item) obj.list1.append( item );
86                 }
87         },
88
89         'init' : function( params ) {
90
91                 var obj = this;
92
93                 obj.record_ids = params['record_ids'] || [];
94
95                 JSAN.use('circ.util');
96                 var columns = circ.util.columns( 
97                         { 
98                                 'title' : { 'hidden' : false },
99                                 'author' : { 'hidden' : false },
100                                 'edition' : { 'hidden' : false },
101                                 'publisher' : { 'hidden' : false },
102                                 'pubdate' : { 'hidden' : false },
103                                 'isbn' : { 'hidden' : false },
104                                 'tcn' : { 'hidden' : false },
105                         } 
106                 );
107
108                 JSAN.use('util.list'); 
109
110                 obj.list1 = new util.list('pending_records_list');
111                 obj.list1.init(
112                         {
113                                 'columns' : columns,
114                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
115                                 'on_select' : function(ev) {
116                                         try {
117                                                 JSAN.use('util.functional');
118                                                 var sel = obj.list1.retrieve_selection();
119                                                 document.getElementById('clip_button1').disabled = sel.length < 1;
120                                                 obj.selection_list1 = util.functional.map_list(
121                                                         sel,
122                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
123                                                 );
124                                                 obj.error.sdump('D_TRACE','circ/record_buckets: selection list 1 = ' + js2JSON(obj.selection_list1) );
125                                                 if (obj.selection_list1.length == 0) {
126                                                         obj.controller.view.record_buckets_sel_add.disabled = true;
127                                                 } else {
128                                                         obj.controller.view.record_buckets_sel_add.disabled = false;
129                                                 }
130                                         } catch(E) {
131                                                 alert('FIXME: ' + E);
132                                         }
133                                 },
134
135                         }
136                 );
137
138                 obj.render_pending_records();
139         
140                 obj.list2 = new util.list('records_in_bucket_list');
141                 obj.list2.init(
142                         {
143                                 'columns' : columns,
144                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
145                                 'on_select' : function(ev) {
146                                         try {
147                                                 JSAN.use('util.functional');
148                                                 var sel = obj.list2.retrieve_selection();
149                                                 document.getElementById('clip_button2').disabled = sel.length < 1;
150                                                 obj.selection_list2 = util.functional.map_list(
151                                                         sel,
152                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
153                                                 );
154                                                 obj.error.sdump('D_TRACE','circ/record_buckets: selection list 2 = ' + js2JSON(obj.selection_list2) );
155                                                 if (obj.selection_list2.length == 0) {
156                                                         obj.controller.view.record_buckets_delete_item.disabled = true;
157                                                         obj.controller.view.record_buckets_delete_item.setAttribute('disabled','true');
158                                                         obj.controller.view.record_buckets_export.disabled = true;
159                                                         obj.controller.view.record_buckets_export.setAttribute('disabled','true');
160                                                 } else {
161                                                         obj.controller.view.record_buckets_delete_item.disabled = false;
162                                                         obj.controller.view.record_buckets_delete_item.setAttribute('disabled','false');
163                                                         obj.controller.view.record_buckets_export.disabled = false;
164                                                         obj.controller.view.record_buckets_export.setAttribute('disabled','false');
165                                                 }
166                                         } catch(E) {
167                                                 alert('FIXME: ' + E);
168                                         }
169                                 },
170                         }
171                 );
172                 
173                 JSAN.use('util.controller'); obj.controller = new util.controller();
174                 obj.controller.init(
175                         {
176                                 'control_map' : {
177                                         'save_columns2' : [
178                                                 ['command'],
179                                                 function() { obj.list2.save_columns(); }
180                                         ],
181                                         'save_columns1' : [
182                                                 ['command'],
183                                                 function() { obj.list1.save_columns(); }
184                                         ],
185                                         'sel_clip2' : [
186                                                 ['command'],
187                                                 function() { obj.list2.clipboard(); }
188                                         ],
189                                         'sel_clip1' : [
190                                                 ['command'],
191                                                 function() { obj.list1.clipboard(); }
192                                         ],
193                                         'record_buckets_menulist_placeholder' : [
194                                                 ['render'],
195                                                 function(e) {
196                                                         return function() {
197                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
198                                                                 var buckets = obj.network.simple_request(
199                                                                         'BUCKET_RETRIEVE_VIA_USER',
200                                                                         [ ses(), obj.data.list.au[0].id() ]
201                                                                 );
202                                                                 if (typeof buckets.ilsevent != 'undefined') {
203                                                                         obj.error.standard_unexpected_error_alert('Could not retrieve your buckets.',buckets);
204                                                                         return;
205                                                                 }
206                                                                 var items = [ ['Choose a bucket...',''], ['Retrieve shared bucket...',-1] ].concat(
207                                                                         util.functional.map_list(
208                                                                                 util.functional.filter_list(
209                                                                                         buckets.biblio,
210                                                                                         function(o) {
211                                                                                                 return o.btype() == 'staff_client';
212                                                                                         }
213                                                                                 ),
214                                                                                 function(o) {
215                                                                                         obj.bucket_id_name_map[ o.id() ] = o.name();
216                                                                                         return [ o.name(), o.id() ];
217                                                                                 }
218                                                                         ).sort( 
219                                                         function( a, b ) {
220                                                             if (a[0] < b[0]) return -1;
221                                                             if (a[0] > b[0]) return 1;
222                                                             return 0;
223                                                         }
224                                                                         )
225                                                                 );
226                                                                 obj.error.sdump('D_TRACE','items = ' + js2JSON(items));
227                                                                 util.widgets.remove_children( e );
228                                                                 var ml = util.widgets.make_menulist(
229                                                                         items
230                                                                 );
231                                                                 e.appendChild( ml );
232                                                                 ml.setAttribute('id','bucket_menulist');
233                                                                 ml.setAttribute('accesskey','');
234
235                                                                 function change_bucket(ev) {
236                                                                         var bucket_id = ev.target.value;
237                                                                         if (bucket_id < 0 ) {
238                                                                                 bucket_id = window.prompt('Enter bucket number:');
239                                                                                 ev.target.value = bucket_id;
240                                                                                 ev.target.setAttribute('value',bucket_id);
241                                                                         }
242                                                                         if (!bucket_id) return;
243                                                                         var bucket = obj.network.simple_request(
244                                                                                 'BUCKET_FLESH',
245                                                                                 [ ses(), 'biblio', bucket_id ]
246                                                                         );
247                                                                         if (typeof bucket.ilsevent != 'undefined') {
248                                                                                 if (bucket.ilsevent == 1506 /* CONTAINER_NOT_FOUND */) {
249                                                                                         alert('Could not find a bucket with ID = ' + bucket_id);
250                                                                                 } else {
251                                                                                         obj.error.standard_unexpected_error_alert('Error retrieving bucket.  Did you use a valid bucket id?',bucket);
252                                                                                 }
253                                                                                 return;
254                                                                         }
255                                                                         try {
256                                                                                 var x = document.getElementById('info_box');
257                                                                                 x.setAttribute('hidden','false');
258                                                                                 x = document.getElementById('bucket_number');
259                                                                                 x.setAttribute('value',bucket.id());
260                                                                                 x = document.getElementById('bucket_name');
261                                                                                 x.setAttribute('value',bucket.name());
262                                                                                 x = document.getElementById('bucket_owner');
263                                                                                 var s = bucket.owner(); JSAN.use('patron.util');
264                                                                                 if (s && typeof s != "object") s = patron.util.retrieve_fleshed_au_via_id(ses(),s); 
265                                                                                 x.setAttribute('value',s.card().barcode() + " @ " + obj.data.hash.aou[ s.home_ou() ].shortname());
266                                                                         } catch(E) {
267                                                                                 alert(E);
268                                                                         }
269                                                                         var items = bucket.items() || [];
270                                                                         obj.list2.clear();
271                                                                         for (var i = 0; i < items.length; i++) {
272                                                                                 var item = obj.flesh_item_for_list( 
273                                                                                         items[i].target_biblio_record_entry(),
274                                                                                         items[i].id()
275                                                                                 );
276                                                                                 if (item) obj.list2.append( item );
277                                                                         }
278                                                                 }
279
280                                                                 ml.addEventListener( 'change_bucket', change_bucket , false);
281                                                                 ml.addEventListener( 'command', function() {
282                                                                         JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
283                                                                 }, false);
284                                                                 obj.controller.view.bucket_menulist = ml;
285                                                                 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
286                                                                 document.getElementById('refresh').addEventListener( 'command', function() {
287                                                                         JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
288                                                                 }, false);
289                                                         };
290                                                 },
291                                         ],
292
293                                         'record_buckets_add' : [
294                                                 ['command'],
295                                                 function() {
296                                                         var bucket_id = obj.controller.view.bucket_menulist.value;
297                                                         if (!bucket_id) return;
298                                                         for (var i = 0; i < obj.record_ids.length; i++) {
299                                                                 var bucket_item = new cbrebi();
300                                                                 bucket_item.isnew('1');
301                                                                 bucket_item.bucket(bucket_id);
302                                                                 bucket_item.target_biblio_record_entry( obj.record_ids[i] );
303                                                                 try {
304                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
305                                                                                 [ ses(), 'biblio', bucket_item ]);
306
307                                                                         if (typeof robj == 'object') throw robj;
308
309                                                                         var item = obj.flesh_item_for_list( obj.record_ids[i], robj );
310                                                                         if (!item) continue;
311
312                                                                         obj.list2.append( item );
313                                                                 } catch(E) {
314                                                                         alert( js2JSON(E) );
315                                                                 }
316                                                         }
317                                                 }
318                                         ],
319                                         'record_buckets_sel_add' : [
320                                                 ['command'],
321                                                 function() {                                                        
322                                                         var bucket_id = obj.controller.view.bucket_menulist.value;
323                                                         if (!bucket_id) return;
324                                                         for (var i = 0; i < obj.selection_list1.length; i++) {
325                                                                 var docid = obj.selection_list1[i].docid;
326                                                                 var bucket_item = new cbrebi();
327                                                                 bucket_item.isnew('1');
328                                                                 bucket_item.bucket(bucket_id);
329                                                                 bucket_item.target_biblio_record_entry( docid );
330                                                                 try {
331                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
332                                                                                 [ ses(), 'biblio', bucket_item ]);
333
334                                                                         if (typeof robj == 'object') throw robj;
335
336                                                                         var item = obj.flesh_item_for_list( docid, robj );
337                                                                         if (!item) continue;
338
339                                                                         obj.list2.append( item );
340                                                                 } catch(E) {
341                                                                         alert( js2JSON(E) );
342                                                                 }
343                                                         }
344
345                                                 }
346                                         ],
347                                         'record_buckets_export' : [
348                                                 ['command'],
349                                                 function() {                                                        
350                                                         for (var i = 0; i < obj.selection_list2.length; i++) {
351                                                                 var docid = obj.selection_list2[i].docid;
352                                                                 var item = obj.flesh_item_for_list( docid );
353                                                                 if (item) {
354                                                                         obj.list1.append( item );
355                                                                         obj.record_ids.push( docid );
356                                                                 }
357                                                         }
358                                                 }
359                                         ],
360
361                                         'record_buckets_delete_item' : [
362                                                 ['command'],
363                                                 function() {
364                                                         for (var i = 0; i < obj.selection_list2.length; i++) {
365                                                                 try {
366                                                                         var bucket_item_id = obj.selection_list2[i].bucket_item_id;
367                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_DELETE',
368                                                                                 [ ses(), 'biblio', bucket_item_id ]);
369                                                                         if (typeof robj == 'object') throw robj;
370                                                                 } catch(E) {
371                                                                         alert(js2JSON(E));
372                                                                 }
373                                                         }
374                                                         alert("Action completed.");
375                                                         setTimeout(
376                                                                 function() {
377                                                                         JSAN.use('util.widgets'); 
378                                                                         util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
379                                                                 }, 0
380                                                         );
381                                                 }
382                                         ],
383                                         'record_buckets_delete_bucket' : [
384                                                 ['command'],
385                                                 function() {
386                                                         try {
387                                                                 var bucket = obj.controller.view.bucket_menulist.value;
388                                                                 var name = obj.bucket_id_name_map[ bucket ];
389                                                                 var conf = window.confirm('Delete the bucket named ' + name + '?');
390                                                                 if (!conf) return;
391                                                                 obj.list2.clear();
392                                                                 var robj = obj.network.simple_request('BUCKET_DELETE',[ses(),'biblio',bucket]);
393                                                                 if (typeof robj == 'object') throw robj;
394                                                                 alert("Action completed.");
395                                                                 obj.controller.render('record_buckets_menulist_placeholder');
396                                                                 setTimeout(
397                                                                         function() {
398                                                                                 JSAN.use('util.widgets'); 
399                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
400                                                                         }, 0
401                                                                 );
402
403                                                         } catch(E) {
404                                                                 alert('FIXME -- ' + E);
405                                                         }
406                                                 }
407                                         ],
408                                         'record_buckets_new_bucket' : [
409                                                 ['command'],
410                                                 function() {
411                                                         try {
412                                                                 var name = prompt('What would you like to name the bucket?','','Bucket Creation');
413
414                                                                 if (name) {
415                                                                         var bucket = new cbreb();
416                                                                         bucket.btype('staff_client');
417                                                                         bucket.owner( obj.data.list.au[0].id() );
418                                                                         bucket.name( name );
419
420                                                                         var robj = obj.network.simple_request('BUCKET_CREATE',[ses(),'biblio',bucket]);
421
422                                                                         if (typeof robj == 'object') {
423                                                                                 if (robj.ilsevent == 1710 /* CONTAINER_EXISTS */) {
424                                                                                         alert('You already have a bucket with that name.');
425                                                                                         return;
426                                                                                 }
427                                                                                 throw robj;
428                                                                         }
429
430
431                                                                         alert('Bucket "' + name + '" created.');
432
433                                                                         obj.controller.render('record_buckets_menulist_placeholder');
434                                                                         obj.controller.view.bucket_menulist.value = robj;
435                                                                         setTimeout(
436                                                                                 function() {
437                                                                                         JSAN.use('util.widgets'); 
438                                                                                         util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
439                                                                                 }, 0
440                                                                         );
441                                                                 }
442                                                         } catch(E) {
443                                                                 alert( js2JSON(E) );
444                                                         }
445                                                 }
446                                         ],
447                                         
448                                         'cmd_record_buckets_export' : [
449                                                 ['command'],
450                                                 function() {
451                                                         obj.list2.on_all_fleshed = function() {
452                                                                 try {
453                                                                         dump(obj.list2.dump_csv() + '\n');
454                                                                         copy_to_clipboard(obj.list2.dump_csv());
455                                                                         setTimeout(function(){obj.list2.on_all_fleshed = null;},0);
456                                                                 } catch(E) {
457                                                                         alert(E); 
458                                                                 }
459                                                         }
460                                                         obj.list2.full_retrieve();
461                                                 }
462                                         ],
463
464                                         'cmd_export1' : [
465                                                 ['command'],
466                                                 function() {
467                                                         obj.list1.on_all_fleshed = function() {
468                                                                 try {
469                                                                         dump(obj.list1.dump_csv() + '\n');
470                                                                         copy_to_clipboard(obj.list1.dump_csv());
471                                                                         setTimeout(function(){obj.list1.on_all_fleshed = null;},0);
472                                                                 } catch(E) {
473                                                                         alert(E); 
474                                                                 }
475                                                         }
476                                                         obj.list1.full_retrieve();
477                                                 }
478                                         ],
479
480                     'cmd_print_export1' : [
481                         ['command'],
482                         function() {
483                             try {
484                                 obj.list1.on_all_fleshed =
485                                     function() {
486                                         try {
487                                             dump( obj.list1.dump_csv() + '\n' );
488                                             //copy_to_clipboard(obj.list.dump_csv());
489                                             JSAN.use('util.print'); var print = new util.print();
490                                             print.simple(obj.list1.dump_csv(),{'content_type':'text/plain'});
491                                             setTimeout(function(){ obj.list1.on_all_fleshed = null; },0);
492                                         } catch(E) {
493                                             obj.error.standard_unexpected_error_alert('print export',E);
494                                         }
495                                     }
496                                 obj.list1.full_retrieve();
497                             } catch(E) {
498                                 obj.error.standard_unexpected_error_alert('print export',E);
499                             }
500                         }
501                     ],
502
503
504                     'cmd_print_export2' : [
505                         ['command'],
506                         function() {
507                             try {
508                                 obj.list2.on_all_fleshed =
509                                     function() {
510                                         try {
511                                             dump( obj.list2.dump_csv() + '\n' );
512                                             //copy_to_clipboard(obj.list.dump_csv());
513                                             JSAN.use('util.print'); var print = new util.print();
514                                             print.simple(obj.list2.dump_csv(),{'content_type':'text/plain'});
515                                             setTimeout(function(){ obj.list2.on_all_fleshed = null; },0);
516                                         } catch(E) {
517                                             obj.error.standard_unexpected_error_alert('print export',E);
518                                         }
519                                     }
520                                 obj.list2.full_retrieve();
521                             } catch(E) {
522                                 obj.error.standard_unexpected_error_alert('print export',E);
523                             }
524                         }
525                     ],
526
527                                         'cmd_export_records_usmarc' : [
528                                                 ['command'],
529                                                 function () { return cat.record_buckets.export_records('usmarc') }
530                                         ],
531
532                                         'cmd_export_records_unimarc' : [
533                                                 ['command'],
534                                                 function () { return cat.record_buckets.export_records('unimarc') }
535                                         ],
536
537                                         'cmd_export_records_xml' : [
538                                                 ['command'],
539                                                 function () { return cat.record_buckets.export_records('xml') }
540                                         ],
541
542                                         'cmd_export_records_bre' : [
543                                                 ['command'],
544                                                 function () { return cat.record_buckets.export_records('bre') }
545                                         ],
546
547                                         'cmd_merge_records' : [
548                                                 ['command'],
549                                                 function() {
550                                                         try {
551                                                                 obj.list2.select_all();
552                                                                 obj.data.stash_retrieve();
553                                                                 JSAN.use('util.functional');
554
555                                                                 var record_ids = util.functional.map_list(
556                                                                         obj.list2.dump_retrieve_ids(),
557                                                                         function (o) {
558                                                                                 return JSON2js(o).docid; // docid
559                                                                         }
560                                                                 );
561
562                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
563                                                                 var top_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" >';
564                                                                 top_xml += '<description>Merge these records? (Select the "lead" record first)</description>';
565                                                                 top_xml += '<hbox><button id="lead" disabled="true" label="Merge" name="fancy_submit"/><button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox></vbox>';
566
567                                                                 var xml = '<form xmlns="http://www.w3.org/1999/xhtml">';
568                                                                 xml += '<table><tr valign="top">';
569                                                                 for (var i = 0; i < record_ids.length; i++) {
570                                                                         xml += '<td><input value="Lead" id="record_' + record_ids[i] + '" type="radio" name="lead"';
571                                                                         xml += ' onclick="' + "try { var x = document.getElementById('lead'); x.setAttribute('value',";
572                                                                         xml += record_ids[i] + '); x.disabled = false; } catch(E) { alert(E); }">';
573                                                                         xml += '</input>Lead Record? #' + record_ids[i] + '</td>';
574                                                                 }
575                                                                 xml += '</tr><tr valign="top">';
576                                                                 for (var i = 0; i < record_ids.length; i++) {
577                                                                         xml += '<td nowrap="nowrap"><iframe src="' + urls.XUL_BIB_BRIEF; 
578                                                                         xml += '?docid=' + record_ids[i] + '"/></td>';
579                                                                 }
580                                                                 xml += '</tr><tr valign="top">';
581                                                                 for (var i = 0; i < record_ids.length; i++) {
582                                                                         html = obj.network.simple_request('MARC_HTML_RETRIEVE',[ record_ids[i] ]);
583                                                                         xml += '<td nowrap="nowrap"><iframe style="min-height: 1000px; min-width: 300px;" flex="1" src="data:text/html,' + window.escape(html) + '"/></td>';
584                                                                 }
585                                                                 xml += '</tr></table></form>';
586                                                                 //obj.data.temp_merge_top = top_xml; obj.data.stash('temp_merge_top');
587                                                                 //obj.data.temp_merge_mid = xml; obj.data.stash('temp_merge_mid');
588                                                                 JSAN.use('util.window'); var win = new util.window();
589                                                                 var fancy_prompt_data = win.open(
590                                                                         urls.XUL_FANCY_PROMPT,
591                                                                         //+ '?xml_in_stash=temp_merge_mid'
592                                                                         //+ '&top_xml_in_stash=temp_merge_top'
593                                                                         //+ '&title=' + window.escape('Record Merging'),
594                                                                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
595                                                                         {
596                                                                                 'top_xml' : top_xml, 'xml' : xml, 'title' : 'Record Merging'
597                                                                         }
598                                                                 );
599                                                                 //obj.data.stash_retrieve();
600
601                                                                 if (typeof fancy_prompt_data.fancy_status == 'undefined' || fancy_prompt_data.fancy_status == 'incomplete') { alert('Merge Aborted'); return; }
602                                                                 var robj = obj.network.simple_request('MERGE_RECORDS', 
603                                                                         [ 
604                                                                                 ses(), 
605                                                                                 fancy_prompt_data.lead, 
606                                                                                 util.functional.filter_list( record_ids,
607                                                                                         function(o) {
608                                                                                                 return o != fancy_prompt_data.lead;
609                                                                                         }
610                                                                                 )
611                                                                         ]
612                                                                 );
613                                                                 if (typeof robj.ilsevent != 'undefined') {
614                                                                         throw(robj);
615                                                                 } else {
616                                                                         alert('Records were successfully merged.');
617                                                                 }
618
619                                                                 obj.render_pending_records(); // FIXME -- need a generic refresh for lists
620                                                                 setTimeout(
621                                                                         function() {
622                                                                                 JSAN.use('util.widgets'); 
623                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
624                                                                         }, 0
625                                                                 );
626                                                         } catch(E) {
627                                                                 obj.error.standard_unexpected_error_alert('Records were not likely merged.',E);
628                                                         }
629
630                                                 }
631                                         ],
632                                         
633                                         'cmd_delete_records' : [
634                                                 ['command'],
635                                                 function() {
636                                                         try {
637                                                                 obj.list2.select_all();
638                                                                 obj.data.stash_retrieve();
639                                                                 JSAN.use('util.functional');
640
641                                                                 var record_ids = util.functional.map_list(
642                                                                         obj.list2.dump_retrieve_ids(),
643                                                                         function (o) {
644                                                                                 return JSON2js(o).docid; // docid
645                                                                         }
646                                                                 );
647
648                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
649                                                                 var top_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" >';
650                                                                 top_xml += '<description>Delete these records?</description>';
651                                                                 top_xml += '<hbox><button id="lead" disabled="false" label="Delete" name="fancy_submit"/><button label="Cancel" accesskey="C" name="fancy_cancel"/></hbox></vbox>';
652
653                                                                 var xml = '<form xmlns="http://www.w3.org/1999/xhtml">';
654                                                                 xml += '<table><tr valign="top">';
655                                                                 for (var i = 0; i < record_ids.length; i++) {
656                                                                         xml += '<td>Record #' + record_ids[i] + '</td>';
657                                                                 }
658                                                                 xml += '</tr><tr valign="top">';
659                                                                 for (var i = 0; i < record_ids.length; i++) {
660                                                                         xml += '<td nowrap="nowrap"><iframe src="' + urls.XUL_BIB_BRIEF; 
661                                                                         xml += '?docid=' + record_ids[i] + '"/></td>';
662                                                                 }
663                                                                 xml += '</tr><tr valign="top">';
664                                                                 for (var i = 0; i < record_ids.length; i++) {
665                                                                         html = obj.network.simple_request('MARC_HTML_RETRIEVE',[ record_ids[i] ]);
666                                                                         xml += '<td nowrap="nowrap"><iframe style="min-height: 1000px; min-width: 300px;" flex="1" src="data:text/html,' + window.escape(html) + '"/></td>';
667                                                                 }
668                                                                 xml += '</tr></table></form>';
669                                                                 //obj.data.temp_merge_top = top_xml; obj.data.stash('temp_merge_top');
670                                                                 //obj.data.temp_merge_mid = xml; obj.data.stash('temp_merge_mid');
671                                                                 JSAN.use('util.window'); var win = new util.window();
672                                                                 var fancy_prompt_data = win.open(
673                                                                         urls.XUL_FANCY_PROMPT,
674                                                                         //+ '?xml_in_stash=temp_merge_mid'
675                                                                         //+ '&top_xml_in_stash=temp_merge_top'
676                                                                         //+ '&title=' + window.escape('Record Purging'),
677                                                                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
678                                                                         {
679                                                                                 'top_xml' : top_xml, 'xml' : xml, 'title' : 'Record Purging'
680                                                                         }
681                                                                 );
682                                                                 //obj.data.stash_retrieve();
683                                                                 if (typeof fancy_prompt_data.fancy_status == 'undefined' || fancy_prompt_data.fancy_status != 'complete') { alert('Delete Aborted'); return; }
684                                                                 var s = '';
685                                                                 for (var i = 0; i < record_ids.length; i++) {
686                                                                         var robj = obj.network.simple_request('FM_BRE_DELETE',[ses(),record_ids[i]]);
687                                                                         if (typeof robj.ilsevent != 'undefined') {
688                                                                                 if (!s) s = 'Error deleting these records:\n';
689                                                                                 s += 'Record #' + record_ids[i] + ' : ' + robj.textcode + ' : ' + robj.desc + '\n';
690                                                                         }
691                                                                 }
692                                                                 if (s) { alert(s); } else { alert('Records deleted.'); }
693
694                                                                 obj.render_pending_records(); // FIXME -- need a generic refresh for lists
695                                                                 setTimeout(
696                                                                         function() {
697                                                                                 JSAN.use('util.widgets'); 
698                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
699                                                                         }, 0
700                                                                 );
701                                                         } catch(E) {
702                                                                 obj.error.standard_unexpected_error_alert('Records were not likely deleted.',E);
703                                                         }
704
705                                                 }
706                                         ],
707
708                                         'cmd_broken' : [
709                                                 ['command'],
710                                                 function() { alert('Not Yet Implemented'); }
711                                         ],
712                                         'cmd_record_buckets_done' : [
713                                                 ['command'],
714                                                 function() {
715                                                         window.close();
716                                                 }
717                                         ],
718                                         'cmd_sel_opac' : [
719                                                 ['command'],
720                                                 function() {
721                                                         try {
722                                                                 obj.list2.select_all();
723                                                                 JSAN.use('util.functional');
724                                                                 var docids = util.functional.map_list(
725                                                                         obj.list2.dump_retrieve_ids(),
726                                                                         function (o) {
727                                                                                 return JSON2js(o).docid; // docid
728                                                                         }
729                                                                 );
730                                                                 for (var i = 0; i < docids.length; i++) {
731                                                                         var doc_id = docids[i];
732                                                                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
733                                                                         var content_params = { 
734                                                                                 'session' : ses(),
735                                                                                 'authtime' : ses('authtime'),
736                                                                                 'opac_url' : opac_url,
737                                                                         };
738                                                                         xulG.new_tab(
739                                                                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
740                                                                                 {'tab_name':'Retrieving title...'}, 
741                                                                                 content_params
742                                                                         );
743                                                                 }
744                                                         } catch(E) {
745                                                                 obj.error.standard_unexpected_error_alert('Showing in OPAC',E);
746                                                         }
747                                                 }
748                                         ],
749
750                                 }
751                         }
752                 );
753                 this.controller.render();
754
755                 if (typeof xulG == 'undefined') {
756                         obj.controller.view.cmd_sel_opac.disabled = true;
757                         obj.controller.view.cmd_sel_opac.setAttribute('disabled',true);
758                 } else {
759                         obj.controller.view.cmd_record_buckets_done.disabled = true;
760                         obj.controller.view.cmd_record_buckets_done.setAttribute('disabled',true);
761                 }
762         },
763
764         'flesh_item_for_list' : function(docid,bucket_item_id) {
765                 var obj = this;
766                 try {
767                         var record = obj.network.simple_request( 'MODS_SLIM_RECORD_RETRIEVE', [ docid ]);
768                         if (record == null || typeof(record.ilsevent) != 'undefined') {
769                                 throw(record);
770                         } else {
771                                 var item = {
772                                         'retrieve_id' : js2JSON( { 'docid' : docid, 'bucket_item_id' : bucket_item_id } ),
773                                         'row' : {
774                                                 'my' : {
775                                                         'mvr' : record,
776                                                 }
777                                         }
778                                 };
779                                 return item;
780                         }
781                 } catch(E) {
782                         obj.error.standard_unexpected_error_alert('Could not retrieve this record: ' + docid,E);
783                         return null;
784                 }
785
786         },
787         
788 };
789
790 dump('exiting cat.record_buckets.js\n');