i18n patch from Craig Ricciuto:
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / record_buckets.js
1 dump('entering cat.record_buckets.js\n');
2
3 function $(id) { return document.getElementById(id); }
4
5 if (typeof cat == 'undefined') cat = {};
6 cat.record_buckets = function (params) {
7
8         JSAN.use('util.error'); this.error = new util.error();
9         JSAN.use('util.network'); this.network = new util.network();
10         JSAN.use('util.date');
11         JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
12         this.first_pause = true;
13     var x = document.getElementById("record_buckets_tabbox");
14     if (x) x.selectedIndex = 2;
15 };
16
17 cat.record_buckets.pick_file = function (defaultFileName) {
18         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
19
20         var nsIFilePicker = Components.interfaces.nsIFilePicker;
21         var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance( nsIFilePicker );
22
23         fp.init( window, $("catStrings").getString('staff.cat.record_buckets.save_file_as'), nsIFilePicker.modeSave );
24         if (defaultFileName)
25                 fp.defaultString = defaultFileName;
26
27         fp.appendFilters( nsIFilePicker.filterAll );
28
29         var result = fp.show(); 
30         if ( (result == nsIFilePicker.returnOK || result == nsIFilePicker.returnReplace) && fp.file ) {
31                 return fp.file;
32         } else {
33                 return null;
34         }
35 };
36
37 cat.record_buckets.export_records = function(obj, output_type) {
38         try {
39                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
40                 obj.list2.select_all();
41                 obj.data.stash_retrieve();
42                 JSAN.use('util.functional');
43
44                 var record_ids = util.functional.map_list(
45                         obj.list2.dump_retrieve_ids(),
46                         function (o) { return JSON2js(o).docid }
47                 );
48
49                 var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
50                         .createInstance(Components.interfaces.nsIWebBrowserPersist);
51
52                 var proto_uri = 'http://' + window.location.hostname + '/exporter?format=' + output_type;
53
54                 dump('Record Export URI is ' + proto_uri + '&id=' + record_ids.join('&id=') + '\n');
55
56                 var uri = Components.classes["@mozilla.org/network/io-service;1"]
57                         .getService(Components.interfaces.nsIIOService)
58                         .newURI( proto_uri + '&id=' + record_ids.join('&id='), null, null );
59
60                 var file = cat.record_buckets.pick_file('bucket.' + output_type);
61                                                                 
62                 if (file) {
63                         persist.saveURI(uri,null,null,null,null,file);
64                 } else {
65                         alert( $("catStrings").getString('staff.cat.record_buckets.export_records.alert') );
66                 }
67
68         } catch(E) {
69                 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.record_buckets.export_records.std_unexpected_error'), E);
70         }
71 };
72
73
74 cat.record_buckets.prototype = {
75         'selection_list0' : [],
76         'selection_list1' : [],
77         'selection_list2' : [],
78         'bucket_id_name_map' : {},
79
80         'render_pending_records' : function() {
81                 if (this.first_pause) {
82                         this.first_pause = false;
83                 } else {
84                         alert( $("commonStrings").getString('common.action_complete'));
85                 }
86                 var obj = this;
87                 obj.list1.clear();
88                 for (var i = 0; i < obj.record_ids.length; i++) {
89                         var item = obj.prep_record_for_list( obj.record_ids[i] );
90                         if (item) obj.list1.append( item );
91                 }
92         },
93
94         'init' : function( params ) {
95
96                 var obj = this;
97
98                 obj.record_ids = params['record_ids'] || [];
99
100                 JSAN.use('circ.util');
101                 var columns = circ.util.columns( 
102                         { 
103                                 'title' : { 'hidden' : false },
104                                 'author' : { 'hidden' : false },
105                                 'edition' : { 'hidden' : false },
106                                 'publisher' : { 'hidden' : false },
107                                 'pubdate' : { 'hidden' : false },
108                                 'isbn' : { 'hidden' : false },
109                                 'tcn' : { 'hidden' : false }
110                         } 
111                 );
112
113                 JSAN.use('util.list'); 
114
115         function retrieve_row(params) {
116             var row = params.row;
117             try {
118                             obj.network.simple_request( 'MODS_SLIM_RECORD_RETRIEVE.authoritative', [ row.my.docid ],
119                     function(req) {
120                         try {
121                             var record = req.getResultObject();
122                             if (typeof req.ilsevent != 'undefined') throw(req);
123                             row.my.mvr = record;
124                             if (typeof params.on_retrieve == 'function') { params.on_retrieve(row); }
125
126                         } catch(E) {
127                             obj.error.standard_unexpected_error_alert(
128                               $("catStrings").getFormattedString('staff.cat.record_buckets.retrieve_row.std_unexpected_error', [row.my.docid]), E);
129                         }
130                     }
131                 );
132             } catch(E) {
133                 obj.error.sdump('D_ERROR','retrieve_row: ' + E );
134             }
135             return row;
136         }
137
138                 obj.list0 = new util.list('record_query_list');
139                 obj.list0.init(
140                         {
141                                 'columns' : columns,
142                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
143                 'retrieve_row' : retrieve_row,
144                                 'on_select' : function(ev) {
145                                         try {
146                                                 JSAN.use('util.functional');
147                                                 var sel = obj.list0.retrieve_selection();
148                                                 obj.controller.view.sel_clip1.setAttribute('disabled', sel.length < 1 ? "true" : "false");
149                                                 obj.selection_list0 = util.functional.map_list(
150                                                         sel,
151                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
152                                                 );
153                                                 obj.error.sdump('D_TRACE','circ/record_buckets: selection list 0 = ' + js2JSON(obj.selection_list1) );
154                                                 if (obj.selection_list0.length == 0) {
155                                                         obj.controller.view.cmd_add_sel_query_to_pending.setAttribute('disabled','true');
156                                                 } else {
157                                                         obj.controller.view.cmd_add_sel_query_to_pending.setAttribute('disabled','false');
158                                                 }
159                                         } catch(E) {
160                                                 alert('FIXME: ' + E);
161                                         }
162                                 }
163
164                         }
165                 );
166
167                 obj.list1 = new util.list('pending_records_list');
168                 obj.list1.init(
169                         {
170                                 'columns' : columns,
171                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
172                 'retrieve_row' : retrieve_row,
173                                 'on_select' : function(ev) {
174                                         try {
175                                                 JSAN.use('util.functional');
176                                                 var sel = obj.list1.retrieve_selection();
177                                                 obj.controller.view.sel_clip1.setAttribute('disabled', sel.length < 1 ? "true" : "false");
178                                                 obj.selection_list1 = util.functional.map_list(
179                                                         sel,
180                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
181                                                 );
182                                                 obj.error.sdump('D_TRACE','circ/record_buckets: selection list 1 = ' + js2JSON(obj.selection_list1) );
183                                                 if (obj.selection_list1.length == 0) {
184                                                         obj.controller.view.cmd_add_sel_pending_to_record_bucket.setAttribute('disabled','true');
185                                                 } else {
186                                                         obj.controller.view.cmd_add_sel_pending_to_record_bucket.setAttribute('disabled','false');
187                                                 }
188                                         } catch(E) {
189                                                 alert('FIXME: ' + E);
190                                         }
191                                 }
192
193                         }
194                 );
195
196                 obj.render_pending_records();
197         
198                 obj.list2 = new util.list('records_in_bucket_list');
199                 obj.list2.init(
200                         {
201                                 'columns' : columns,
202                                 'map_row_to_columns' : circ.util.std_map_row_to_columns(),
203                 'retrieve_row' : retrieve_row,
204                                 'on_select' : function(ev) {
205                                         try {
206                                                 JSAN.use('util.functional');
207                                                 var sel = obj.list2.retrieve_selection();
208                                                 obj.controller.view.sel_clip2.setAttribute('disabled', sel.length < 1 ? "true" : "false");
209                                                 obj.selection_list2 = util.functional.map_list(
210                                                         sel,
211                                                         function(o) { return JSON2js(o.getAttribute('retrieve_id')); }
212                                                 );
213                                                 obj.error.sdump('D_TRACE','circ/record_buckets: selection list 2 = ' + js2JSON(obj.selection_list2) );
214                                                 if (obj.selection_list2.length == 0) {
215                                                         obj.controller.view.cmd_record_buckets_delete_item.setAttribute('disabled','true');
216                                                         obj.controller.view.cmd_record_buckets_to_pending_buckets.setAttribute('disabled','true');
217                                                 } else {
218                                                         obj.controller.view.cmd_record_buckets_delete_item.setAttribute('disabled','false');
219                                                         obj.controller.view.cmd_record_buckets_to_pending_buckets.setAttribute('disabled','false');
220                                                 }
221                                         } catch(E) {
222                                                 alert('FIXME: ' + E);
223                                         }
224                                 }
225                         }
226                 );
227                 
228                 JSAN.use('util.controller'); obj.controller = new util.controller();
229                 obj.controller.init(
230                         {
231                                 'control_map' : {
232                                         'save_columns2' : [
233                                                 ['command'],
234                                                 function() { obj.list2.save_columns(); }
235                                         ],
236                                         'save_columns1' : [
237                                                 ['command'],
238                                                 function() { obj.list1.save_columns(); }
239                                         ],
240                                         'save_columns0' : [
241                                                 ['command'],
242                                                 function() { obj.list0.save_columns(); }
243                                         ],
244                                         'sel_clip2' : [
245                                                 ['command'],
246                                                 function() { obj.list2.clipboard(); }
247                                         ],
248                                         'sel_clip1' : [
249                                                 ['command'],
250                                                 function() { obj.list1.clipboard(); }
251                                         ],
252                                         'sel_clip0' : [
253                                                 ['command'],
254                                                 function() { obj.list0.clipboard(); }
255                                         ],
256                     'record_query_input' : [
257                         ['render'],
258                         function(ev) {
259                             ev.addEventListener('keypress',function(ev){
260                                 if (ev.target.tagName != 'textbox') return;
261                                 if (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* enter on a mac */) setTimeout( function() { obj.submit(); }, 0);
262                             },false);
263                         }
264                     ],
265                     'cmd_submit_query' : [
266                         ['command'],
267                         function() { obj.submit(); }
268                     ],
269                                         'record_buckets_menulist_placeholder' : [
270                                                 ['render'],
271                                                 function(e) {
272                                                         return function() {
273                                                                 JSAN.use('util.widgets'); JSAN.use('util.functional');
274                                                                 var buckets = obj.network.simple_request(
275                                                                         'BUCKET_RETRIEVE_VIA_USER',
276                                                                         [ ses(), obj.data.list.au[0].id() ]
277                                                                 );
278                                                                 if (typeof buckets.ilsevent != 'undefined') {
279                                                                         obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.record_buckets.buckets.std_unexpected_error'), buckets);
280                                                                         return;
281                                                                 }
282                                                                 var items = [
283                                                                         [$("catStrings").getString('staff.cat.record_buckets.menulist_placeholder.item1'),''],
284                                                                         [$("catStrings").getString('staff.cat.record_buckets.menulist_placeholder.item2'),-1]
285                                                                 ].concat(
286                                                                         util.functional.map_list(
287                                                                                 util.functional.filter_list(
288                                                                                         buckets.biblio,
289                                                                                         function(o) {
290                                                                                                 return o.btype() == 'staff_client';
291                                                                                         }
292                                                                                 ),
293                                                                                 function(o) {
294                                                                                         obj.bucket_id_name_map[ o.id() ] = o.name();
295                                                                                         return [ o.name(), o.id() ];
296                                                                                 }
297                                                                         ).sort( 
298                                                         function( a, b ) {
299                                                             if (a[0] < b[0]) return -1;
300                                                             if (a[0] > b[0]) return 1;
301                                                             return 0;
302                                                         }
303                                                                         )
304                                                                 );
305                                                                 obj.error.sdump('D_TRACE','items = ' + js2JSON(items));
306                                                                 util.widgets.remove_children( e );
307                                                                 var ml = util.widgets.make_menulist(
308                                                                         items
309                                                                 );
310                                                                 e.appendChild( ml );
311                                                                 ml.setAttribute('id','bucket_menulist');
312                                                                 ml.setAttribute('accesskey','');
313
314                                                                 function change_bucket(ev) {
315                                                                         var bucket_id = ev.target.value;
316                                                                         if (bucket_id < 0 ) {
317                                                                                 bucket_id = window.prompt($("catStrings").getString('staff.cat.record_buckets.change_bucket.bucket_id'));
318                                                                                 ev.target.value = bucket_id;
319                                                                                 ev.target.setAttribute('value',bucket_id);
320                                                                         }
321                                                                         if (!bucket_id) return;
322                                                                         var x = document.getElementById('info_box');
323                                                                         if (x) x.setAttribute('hidden','true');
324                                     x = document.getElementById('bucket_item_count');
325                                     if (x) x.setAttribute('label','');
326                                     obj.controller.view.cmd_record_buckets_delete_bucket.setAttribute('disabled','true');
327                                     obj.controller.view.cmd_record_buckets_refresh.setAttribute('disabled','true');
328                                     obj.controller.view.record_buckets_export_records.disabled = true;
329                                     obj.controller.view.cmd_merge_records.setAttribute('disabled','true');
330                                     obj.controller.view.cmd_delete_records.setAttribute('disabled','true');
331                                     obj.controller.view.cmd_sel_opac.setAttribute('disabled','true');
332                                     obj.controller.view.record_buckets_list_actions.disabled = true;
333                                                                         var bucket = obj.network.simple_request(
334                                                                                 'BUCKET_FLESH',
335                                                                                 [ ses(), 'biblio', bucket_id ]
336                                                                         );
337                                                                         if (typeof bucket.ilsevent != 'undefined') {
338                                                                                 if (bucket.ilsevent == 1506 /* CONTAINER_NOT_FOUND */) {
339                                                                                         alert('Could not find a bucket with ID = ' + bucket_id);
340                                                                                 } else {
341                                                                                         obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.record_buckets.change_bucket.error'),bucket);
342                                                                                 }
343                                                                                 return;
344                                                                         }
345                                                                         try {
346                                         obj.controller.view.cmd_record_buckets_delete_bucket.setAttribute('disabled','false');
347                                         obj.controller.view.cmd_record_buckets_refresh.setAttribute('disabled','false');
348                                         obj.controller.view.record_buckets_export_records.disabled = false;
349                                         obj.controller.view.cmd_merge_records.setAttribute('disabled','false');
350                                         obj.controller.view.cmd_delete_records.setAttribute('disabled','false');
351                                         obj.controller.view.cmd_sel_opac.setAttribute('disabled','false');
352                                         obj.controller.view.record_buckets_list_actions.disabled = false;
353
354                                                                                 var x = document.getElementById('info_box');
355                                                                                 x.setAttribute('hidden','false');
356                                                                                 x = document.getElementById('bucket_number');
357                                                                                 x.setAttribute('value',bucket.id());
358                                                                                 x = document.getElementById('bucket_name');
359                                                                                 x.setAttribute('value',bucket.name());
360                                                                                 x = document.getElementById('bucket_owner');
361                                                                                 var s = bucket.owner(); JSAN.use('patron.util');
362                                                                                 if (s && typeof s != "object") s = patron.util.retrieve_fleshed_au_via_id(ses(),s); 
363                                                                                 x.setAttribute('value',s.family_name() + ' (' + s.card().barcode() + ") @ " + obj.data.hash.aou[ s.home_ou() ].shortname());
364                                                                         } catch(E) {
365                                                                                 alert(E);
366                                                                         }
367                                                                         var items = bucket.items() || [];
368                                                                         obj.list2.clear();
369                                     var x = document.getElementById('bucket_item_count');
370                                     if (x && catStrings) x.setAttribute('value',catStrings.getFormattedString('cat.total_bucket_items_in_bucket',[items.length]));
371                                                                         for (var i = 0; i < items.length; i++) {
372                                                                                 var item = obj.prep_record_for_list( 
373                                                                                         items[i].target_biblio_record_entry(),
374                                                                                         items[i].id()
375                                                                                 );
376                                                                                 if (item) obj.list2.append( item );
377                                                                         }
378                                                                 }
379
380                                                                 ml.addEventListener( 'change_bucket', change_bucket , false);
381                                                                 ml.addEventListener( 'command', function() {
382                                                                         JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
383                                                                 }, false);
384                                                                 obj.controller.view.bucket_menulist = ml;
385                                                                 JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',ml);
386                                                         };
387                                                 },
388                                         ],
389
390                     'cmd_record_buckets_refresh' : [
391                         ['command'],
392                         function() {
393                             JSAN.use('util.widgets'); util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
394                         }
395                     ],
396
397                                         'cmd_add_all_query_to_pending' : [
398                                                 ['command'],
399                                                 function() {
400                                                 obj.list0.select_all();
401                                                         for (var i = 0; i < obj.selection_list0.length; i++) {
402                                                                 var docid = obj.selection_list0[i].docid;
403                                                                 try {
404                                                                         var item = obj.prep_record_for_list( docid );
405                                                                         if (!item) continue;
406                                                                         obj.list1.append( item );
407                                     obj.record_ids.push( docid );
408                                                                 } catch(E) {
409                                                                         alert( js2JSON(E) );
410                                                                 }
411                                                         }
412                                                 }
413                                         ],
414
415                                         'cmd_add_sel_query_to_pending' : [
416                                                 ['command'],
417                                                 function() {
418                                                         for (var i = 0; i < obj.selection_list0.length; i++) {
419                                                                 var docid = obj.selection_list0[i].docid;
420                                                                 try {
421                                                                         var item = obj.prep_record_for_list( docid );
422                                                                         if (!item) continue;
423                                                                         obj.list1.append( item );
424                                     obj.record_ids.push( docid );
425                                                                 } catch(E) {
426                                                                         alert( js2JSON(E) );
427                                                                 }
428                                                         }
429                                                 }
430                                         ],
431
432
433                                         'cmd_add_all_pending_to_record_bucket' : [
434                                                 ['command'],
435                                                 function() {
436                                                         var bucket_id = obj.controller.view.bucket_menulist.value;
437                                                         if (!bucket_id) return;
438                                                         for (var i = 0; i < obj.record_ids.length; i++) {
439                                                                 var bucket_item = new cbrebi();
440                                                                 bucket_item.isnew('1');
441                                                                 bucket_item.bucket(bucket_id);
442                                                                 bucket_item.target_biblio_record_entry( obj.record_ids[i] );
443                                                                 try {
444                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
445                                                                                 [ ses(), 'biblio', bucket_item ]);
446
447                                                                         if (typeof robj == 'object') throw robj;
448
449                                                                         var item = obj.prep_record_for_list( obj.record_ids[i], robj );
450                                                                         if (!item) continue;
451
452                                                                         obj.list2.append( item );
453                                                                 } catch(E) {
454                                                                         alert( js2JSON(E) );
455                                                                 }
456                                                         }
457                                                 }
458                                         ],
459                                         'cmd_add_sel_pending_to_record_bucket' : [
460                                                 ['command'],
461                                                 function() {                                                        
462                                                         var bucket_id = obj.controller.view.bucket_menulist.value;
463                                                         if (!bucket_id) return;
464                                                         for (var i = 0; i < obj.selection_list1.length; i++) {
465                                                                 var docid = obj.selection_list1[i].docid;
466                                                                 var bucket_item = new cbrebi();
467                                                                 bucket_item.isnew('1');
468                                                                 bucket_item.bucket(bucket_id);
469                                                                 bucket_item.target_biblio_record_entry( docid );
470                                                                 try {
471                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_CREATE',
472                                                                                 [ ses(), 'biblio', bucket_item ]);
473
474                                                                         if (typeof robj == 'object') throw robj;
475
476                                                                         var item = obj.prep_record_for_list( docid, robj );
477                                                                         if (!item) continue;
478
479                                                                         obj.list2.append( item );
480                                                                 } catch(E) {
481                                                                         alert( js2JSON(E) );
482                                                                 }
483                                                         }
484
485                                                 }
486                                         ],
487                                         'cmd_record_buckets_to_pending_buckets' : [
488                                                 ['command'],
489                                                 function() {                                                        
490                                                         for (var i = 0; i < obj.selection_list2.length; i++) {
491                                                                 var docid = obj.selection_list2[i].docid;
492                                                                 var item = obj.prep_record_for_list( docid );
493                                                                 if (item) {
494                                                                         obj.list1.append( item );
495                                                                         obj.record_ids.push( docid );
496                                                                 }
497                                                         }
498                                                 }
499                                         ],
500
501                                         'cmd_record_buckets_delete_item' : [
502                                                 ['command'],
503                                                 function() {
504                                                         for (var i = 0; i < obj.selection_list2.length; i++) {
505                                                                 try {
506                                                                         var bucket_item_id = obj.selection_list2[i].bucket_item_id;
507                                                                         var robj = obj.network.simple_request('BUCKET_ITEM_DELETE',
508                                                                                 [ ses(), 'biblio', bucket_item_id ]);
509                                                                         if (typeof robj == 'object') throw robj;
510                                                                 } catch(E) {
511                                                                         alert(js2JSON(E));
512                                                                 }
513                                                         }
514                                                         alert( $("commonStrings").getString('common.action_complete'));
515                                                         setTimeout(
516                                                                 function() {
517                                                                         JSAN.use('util.widgets'); 
518                                                                         util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
519                                                                 }, 0
520                                                         );
521                                                 }
522                                         ],
523                                         'cmd_record_buckets_delete_bucket' : [
524                                                 ['command'],
525                                                 function() {
526                                                         try {
527                                                                 var bucket = obj.controller.view.bucket_menulist.value;
528                                                                 var name = obj.bucket_id_name_map[ bucket ];
529                                                                 var conf = window.confirm('Delete the bucket named ' + name + '?');
530                                                                 if (!conf) return;
531                                                                 obj.list2.clear();
532                                                                 var robj = obj.network.simple_request('BUCKET_DELETE',[ses(),'biblio',bucket]);
533                                                                 if (typeof robj == 'object') throw robj;
534                                                                 alert( $("commonStrings").getString('common.action_complete'));
535                                                                 var x = document.getElementById('info_box');
536                                 x.setAttribute('hidden','true');
537                                 obj.controller.view.cmd_record_buckets_delete_bucket.setAttribute('disabled','true');
538                                 obj.controller.view.cmd_record_buckets_refresh.setAttribute('disabled','true');
539                                 obj.controller.view.record_buckets_export_records.disabled = true;
540                                 obj.controller.view.cmd_merge_records.setAttribute('disabled','true');
541                                 obj.controller.view.cmd_delete_records.setAttribute('disabled','true');
542                                 obj.controller.view.cmd_sel_opac.setAttribute('disabled','true');
543                                 obj.controller.view.record_buckets_list_actions.disabled = true;
544                                                                 obj.controller.render('record_buckets_menulist_placeholder');
545                                                                 setTimeout(
546                                                                         function() {
547                                                                                 JSAN.use('util.widgets'); 
548                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
549                                                                         }, 0
550                                                                 );
551
552                                                         } catch(E) {
553                                                                 alert('FIXME: ' + E);
554                                                         }
555                                                 }
556                                         ],
557                                         'cmd_record_buckets_new_bucket' : [
558                                                 ['command'],
559                                                 function() {
560                                                         try {
561                                                                 var name = prompt(
562                                                                         $("catStrings").getString('staff.cat.record_buckets.new_bucket.bucket_prompt'),
563                                                                         '',
564                                                                         $("catStrings").getString('staff.cat.record_buckets.new_bucket.bucket_prompt_title')
565                                                                 );
566
567                                                                 if (name) {
568                                                                         var bucket = new cbreb();
569                                                                         bucket.btype('staff_client');
570                                                                         bucket.owner( obj.data.list.au[0].id() );
571                                                                         bucket.name( name );
572
573                                                                         var robj = obj.network.simple_request('BUCKET_CREATE',[ses(),'biblio',bucket]);
574
575                                                                         if (typeof robj == 'object') {
576                                                                                 if (robj.ilsevent == 1710 /* CONTAINER_EXISTS */) {
577                                                                                         alert($("catStrings").getString('staff.cat.record_buckets.new_bucket.same_name_alert'));
578                                                                                         return;
579                                                                                 }
580                                                                                 throw robj;
581                                                                         }
582
583                                                                         alert($("catStrings").getFormattedString('staff.cat.record_buckets.new_bucket.bucket_created', [name]));
584
585                                                                         obj.controller.render('record_buckets_menulist_placeholder');
586                                                                         obj.controller.view.bucket_menulist.value = robj;
587                                                                         setTimeout(
588                                                                                 function() {
589                                                                                         JSAN.use('util.widgets'); 
590                                                                                         util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
591                                                                                 }, 0
592                                                                         );
593                                                                 }
594                                                         } catch(E) {
595                                                                 alert( js2JSON(E) );
596                                                         }
597                                                 }
598                                         ],
599                                         
600                                         'cmd_record_query_csv_to_clipboard' : [ ['command'], function() { obj.list0.dump_csv_to_clipboard(); } ], 
601                                         'cmd_pending_buckets_csv_to_clipboard' : [ ['command'], function() { obj.list1.dump_csv_to_clipboard(); } ], 
602                                         'cmd_record_buckets_csv_to_clipboard' : [ ['command'], function() { obj.list2.dump_csv_to_clipboard(); } ],
603                     'cmd_record_query_csv_to_printer' : [ ['command'], function() { obj.list0.dump_csv_to_printer(); } ],
604                     'cmd_pending_buckets_csv_to_printer' : [ ['command'], function() { obj.list1.dump_csv_to_printer(); } ],
605                     'cmd_record_buckets_csv_printer' : [ ['command'], function() { obj.list2.dump_csv_to_printer(); } ], 
606                     'cmd_record_query_csv_to_file' : [ ['command'], function() { obj.list0.dump_csv_to_file( { 'defaultFileName' : 'pending_records.txt' } ); } ],
607                     'cmd_pending_buckets_csv_to_file' : [ ['command'], function() { obj.list1.dump_csv_to_file( { 'defaultFileName' : 'pending_records.txt' } ); } ],
608                     'cmd_record_buckets_csv_file' : [ ['command'], function() { obj.list2.dump_csv_to_file( { 'defaultFileName' : 'bucket_records.txt' } ); } ], 
609
610                                         'cmd_export_records_usmarc' : [
611                                                 ['command'],
612                                                 function () { return cat.record_buckets.export_records(obj, 'usmarc') }
613                                         ],
614
615                                         'cmd_export_records_unimarc' : [
616                                                 ['command'],
617                                                 function () { return cat.record_buckets.export_records(obj, 'unimarc') }
618                                         ],
619
620                                         'cmd_export_records_xml' : [
621                                                 ['command'],
622                                                 function () { return cat.record_buckets.export_records(obj, 'xml') }
623                                         ],
624
625                                         'cmd_export_records_bre' : [
626                                                 ['command'],
627                                                 function () { return cat.record_buckets.export_records(obj, 'bre') }
628                                         ],
629
630                                         'cmd_merge_records' : [
631                                                 ['command'],
632                                                 function() {
633                                                         try {
634                                                                 obj.list2.select_all();
635                                                                 obj.data.stash_retrieve();
636                                                                 JSAN.use('util.functional');
637
638                                                                 var record_ids = util.functional.map_list(
639                                                                         obj.list2.dump_retrieve_ids(),
640                                                                         function (o) {
641                                                                                 return JSON2js(o).docid; // docid
642                                                                         }
643                                                                 );
644
645                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
646                                                                 var top_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" >';
647                                                                 top_xml += '<description>' + $("catStrings").getString('staff.cat.record_buckets.merge_records.merge_lead') + '</description>';
648                                                                 top_xml += '<hbox>';
649                                                                 top_xml += '<button id="lead" disabled="true" label="'
650                                                                                 + $("catStrings").getString('staff.cat.record_buckets.merge_records.button.label') + '" name="fancy_submit"/>';
651                                                                 top_xml += '<button label="' + $("catStrings").getString('staff.cat.record_buckets.merge_records.cancel_button.label') +'" accesskey="'
652                                                                                 + $("catStrings").getString('staff.cat.record_buckets.merge_records.cancel_button.accesskey') +'" name="fancy_cancel"/></hbox></vbox>';
653
654                                                                 var xml = '<form xmlns="http://www.w3.org/1999/xhtml">';
655                                                                 xml += '<table><tr valign="top">';
656                                                                 for (var i = 0; i < record_ids.length; i++) {
657                                                                         xml += '<td><input value="' + $("catStrings").getString('staff.cat.record_buckets.merge_records.lead')
658                                                                                 + ' id="record_' + record_ids[i] + '" type="radio" name="lead"';
659                                                                         xml += ' onclick="' + "try { var x = $('lead'); x.setAttribute('value',";
660                                                                         xml += record_ids[i] + '); x.disabled = false; } catch(E) { alert(E); }">';
661                                                                         xml += '</input>' + $("catStrings").getFormattedString('staff.cat.record_buckets.merge_records.lead_record_number',[record_ids[i]]) + '</td>';
662                                                                 }
663                                                                 xml += '</tr><tr valign="top">';
664                                                                 for (var i = 0; i < record_ids.length; i++) {
665                                                                         xml += '<td nowrap="nowrap"><iframe src="' + urls.XUL_BIB_BRIEF; 
666                                                                         xml += '?docid=' + record_ids[i] + '"/></td>';
667                                                                 }
668                                                                 xml += '</tr><tr valign="top">';
669                                                                 for (var i = 0; i < record_ids.length; i++) {
670                                                                         html = obj.network.simple_request('MARC_HTML_RETRIEVE',[ record_ids[i] ]);
671                                                                         xml += '<td nowrap="nowrap"><iframe style="min-height: 1000px; min-width: 300px;" flex="1" src="data:text/html,' + window.escape(html) + '"/></td>';
672                                                                 }
673                                                                 xml += '</tr></table></form>';
674                                                                 //obj.data.temp_merge_top = top_xml; obj.data.stash('temp_merge_top');
675                                                                 //obj.data.temp_merge_mid = xml; obj.data.stash('temp_merge_mid');
676                                                                 JSAN.use('util.window'); var win = new util.window();
677                                                                 var fancy_prompt_data = win.open(
678                                                                         urls.XUL_FANCY_PROMPT,
679                                                                         //+ '?xml_in_stash=temp_merge_mid'
680                                                                         //+ '&top_xml_in_stash=temp_merge_top'
681                                                                         //+ '&title=' + window.escape('Record Merging'),
682                                                                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
683                                                                         {
684                                                                                 'top_xml' : top_xml, 'xml' : xml, 'title' : $("catStrings").getString('staff.cat.record_buckets.merge_records.fancy_prompt_title')
685                                                                         }
686                                                                 );
687                                                                 //obj.data.stash_retrieve();
688
689                                                                 if (typeof fancy_prompt_data.fancy_status == 'undefined' || fancy_prompt_data.fancy_status == 'incomplete') {
690                                                                         alert($("catStrings").getString('staff.cat.record_buckets.merge_records.fancy_prompt.alert'));
691                                                                         return;
692                                                                 }
693                                                                 var robj = obj.network.simple_request('MERGE_RECORDS', 
694                                                                         [ 
695                                                                                 ses(), 
696                                                                                 fancy_prompt_data.lead, 
697                                                                                 util.functional.filter_list( record_ids,
698                                                                                         function(o) {
699                                                                                                 return o != fancy_prompt_data.lead;
700                                                                                         }
701                                                                                 )
702                                                                         ]
703                                                                 );
704                                                                 if (typeof robj.ilsevent != 'undefined') {
705                                                                         throw(robj);
706                                                                 } else {
707                                                                         alert($("catStrings").getString('staff.cat.record_buckets.merge_records.success'));
708                                                                 }
709
710                                                                 obj.render_pending_records(); // FIXME -- need a generic refresh for lists
711                                                                 setTimeout(
712                                                                         function() {
713                                                                                 JSAN.use('util.widgets'); 
714                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
715                                                                         }, 0
716                                                                 );
717                                                         } catch(E) {
718                                                                 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.record_buckets.merge_records.catch.std_unex_error'),E);
719                                                         }
720
721                                                 }
722                                         ],
723                                         
724                                         'cmd_delete_records' : [
725                                                 ['command'],
726                                                 function() {
727                                                         try {
728                                                                 obj.list2.select_all();
729                                                                 obj.data.stash_retrieve();
730                                                                 JSAN.use('util.functional');
731
732                                                                 var record_ids = util.functional.map_list(
733                                                                         obj.list2.dump_retrieve_ids(),
734                                                                         function (o) {
735                                                                                 return JSON2js(o).docid; // docid
736                                                                         }
737                                                                 );
738
739                                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
740                                                                 var top_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" >';
741                                                                 top_xml += '<description>' + $("catStrings").getString('staff.cat.record_buckets.delete_records.xml1') + '</description>';
742                                                                 top_xml += '<hbox>';
743                                                                 top_xml += '<button id="lead" disabled="false" label="'
744                                                                                 + $("catStrings").getString('staff.cat.record_buckets.delete_records.button.label')
745                                                                                 + '" name="fancy_submit"/>';
746                                                                 top_xml += '<button label="'
747                                                                                 + $("catStrings").getString('staff.cat.record_buckets.delete_records.cancel_button.label') +'" accesskey="'
748                                                                                 + $("catStrings").getString('staff.cat.record_buckets.delete_records.cancel_button.accesskey') +'" name="fancy_cancel"/></hbox></vbox>';
749
750                                                                 var xml = '<form xmlns="http://www.w3.org/1999/xhtml">';
751                                                                 xml += '<table><tr valign="top">';
752                                                                 for (var i = 0; i < record_ids.length; i++) {
753                                                                         xml += '<td>' + $("catStrings").getFormattedString('staff.cat.record_buckets.delete_records.xml2', [record_ids[i]]) + '</td>';
754                                                                 }
755                                                                 xml += '</tr><tr valign="top">';
756                                                                 for (var i = 0; i < record_ids.length; i++) {
757                                                                         xml += '<td nowrap="nowrap"><iframe src="' + urls.XUL_BIB_BRIEF; 
758                                                                         xml += '?docid=' + record_ids[i] + '"/></td>';
759                                                                 }
760                                                                 xml += '</tr><tr valign="top">';
761                                                                 for (var i = 0; i < record_ids.length; i++) {
762                                                                         html = obj.network.simple_request('MARC_HTML_RETRIEVE',[ record_ids[i] ]);
763                                                                         xml += '<td nowrap="nowrap"><iframe style="min-height: 1000px; min-width: 300px;" flex="1" src="data:text/html,' + window.escape(html) + '"/></td>';
764                                                                 }
765                                                                 xml += '</tr></table></form>';
766                                                                 //obj.data.temp_merge_top = top_xml; obj.data.stash('temp_merge_top');
767                                                                 //obj.data.temp_merge_mid = xml; obj.data.stash('temp_merge_mid');
768                                                                 JSAN.use('util.window'); var win = new util.window();
769                                                                 var fancy_prompt_data = win.open(
770                                                                         urls.XUL_FANCY_PROMPT,
771                                                                         //+ '?xml_in_stash=temp_merge_mid'
772                                                                         //+ '&top_xml_in_stash=temp_merge_top'
773                                                                         //+ '&title=' + window.escape('Record Purging'),
774                                                                         'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
775                                                                         {
776                                                                                 'top_xml' : top_xml, 'xml' : xml, 'title' : $("catStrings").getString('staff.cat.record_buckets.delete_records.fancy_prompt_title')
777                                                                         }
778                                                                 );
779                                                                 //obj.data.stash_retrieve();
780                                                                 if (typeof fancy_prompt_data.fancy_status == 'undefined' || fancy_prompt_data.fancy_status != 'complete') {
781                                                                         alert($("catStrings").getString('staff.cat.record_buckets.delete_records.fancy_prompt.alert'));
782                                                                         return;
783                                                                 }
784                                                                 var s = '';
785                                                                 for (var i = 0; i < record_ids.length; i++) {
786                                                                         var robj = obj.network.simple_request('FM_BRE_DELETE',[ses(),record_ids[i]]);
787                                                                         if (typeof robj.ilsevent != 'undefined') {
788                                                                                 if (!s) s = $("catStrings").getString('staff.cat.record_buckets.delete_records.s1');
789                                                                                 s += $("catStrings").getFormattedString('staff.cat.record_buckets.delete_records.s2', [record_ids[i], robj.textcode, robj.desc]);
790                                                                         }
791                                                                 }
792                                                                 if (s) { alert(s); } else { alert($("catStrings").getString('staff.cat.record_buckets.delete_records.delete_success.alert')); }
793
794                                                                 obj.render_pending_records(); // FIXME -- need a generic refresh for lists
795                                                                 setTimeout(
796                                                                         function() {
797                                                                                 JSAN.use('util.widgets'); 
798                                                                                 util.widgets.dispatch('change_bucket',obj.controller.view.bucket_menulist);
799                                                                         }, 0
800                                                                 );
801                                                         } catch(E) {
802                                                                 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.record_buckets.delete_records.catch.std_unex_err',E));
803                                                         }
804
805                                                 }
806                                         ],
807
808                                         'cmd_broken' : [
809                                                 ['command'],
810                                                 function() { alert($("catStrings").getString('staff.cat.record_buckets.cmd_broken.alert')); }
811                                         ],
812                                         'cmd_sel_opac' : [
813                                                 ['command'],
814                                                 function() {
815                                                         try {
816                                                                 obj.list2.select_all();
817                                                                 JSAN.use('util.functional');
818                                                                 var docids = util.functional.map_list(
819                                                                         obj.list2.dump_retrieve_ids(),
820                                                                         function (o) {
821                                                                                 return JSON2js(o).docid; // docid
822                                                                         }
823                                                                 );
824                                 var seen = {};
825                                                                 for (var i = 0; i < docids.length; i++) {
826                                                                         var doc_id = docids[i];
827                                     if (seen[doc_id]) continue; seen[doc_id] = true;
828                                                                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + '?r=' + doc_id;
829                                                                         var content_params = { 
830                                                                                 'session' : ses(),
831                                                                                 'authtime' : ses('authtime'),
832                                                                                 'opac_url' : opac_url
833                                                                         };
834                                                                         xulG.new_tab(
835                                                                                 xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
836                                                                                 {'tab_name':$("catStrings").getString('staff.cat.record_buckets.cmd_sel_opac.tab_name')}, 
837                                                                                 content_params
838                                                                         );
839                                                                 }
840                                                         } catch(E) {
841                                                                 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.record_buckets.cmd_sel_opac.catch.std_unex_err'),E);
842                                                         }
843                                                 }
844                                         ],
845                     'record_buckets_export_records' : [ ['render'], function(){} ],
846                     'record_buckets_list_actions' : [ ['render'], function(){} ]
847                                 }
848                         }
849                 );
850                 this.controller.render();
851
852                 if (typeof xulG == 'undefined') {
853                         obj.controller.view.cmd_sel_opac.disabled = true;
854                         obj.controller.view.cmd_sel_opac.setAttribute('disabled',true);
855                 }
856         },
857
858     'submit' : function() {
859         try {
860             var obj = this;
861             var x = document.getElementById('record_query_input'); 
862             if (x.value == '') {
863                 setTimeout( function() { obj.controller.view.record_query_input.focus(); obj.controller.view.record_query_input.select(); }, 0 );
864                 return;
865             }
866             obj.list0.clear();
867             var y = document.getElementById('query_status');
868             x.disabled = true;
869             if (y) y.value = $("catStrings").getString('staff.cat.record_buckets.submit.query_status');
870             obj.network.simple_request(
871                 'FM_BRE_ID_SEARCH_VIA_MULTICLASS_QUERY',
872                 [ {}, x.value, 1 ],
873                 function(req) {
874                     try {
875                         var resp = req.getResultObject();
876                         if (y) y.value = catStrings.getFormattedString('cat.results_returned',[resp.count]);
877                         x.disabled = false;
878                         if (resp.count > 0) {
879                             JSAN.use('util.exec'); var exec = new util.exec();
880                             var funcs = [];
881                             for (var i = 0; i < resp.ids.length; i++) {
882                                 funcs.push(
883                                     function(b){
884                                         return function() {
885                                             obj.list0.append(obj.prep_record_for_list(b));
886                                         };
887                                     }(resp.ids[i][0])
888                                 );
889                             }
890                             funcs.push(
891                                 function() {
892                                     obj.controller.view.record_query_input.focus();
893                                     obj.controller.view.record_query_input.select();
894                                 }
895                             );
896                             exec.chain( funcs ); 
897                         } else {
898                             setTimeout( function() { obj.controller.view.record_query_input.focus(); obj.controller.view.record_query_input.select(); }, 0 );
899                         }
900                     } catch(E) {
901                         obj.error.standard_unexpected_error_alert('submit_query_callback',E);
902                     }
903                 }
904             );
905         } catch(E) {
906             this.error.standard_unexpected_error_alert('submit_query',E);
907         }
908     },
909
910         'prep_record_for_list' : function(docid,bucket_item_id) {
911                 var obj = this;
912                 try {
913             var item = {
914                 'retrieve_id' : js2JSON( { 'docid' : docid, 'bucket_item_id' : bucket_item_id } ),
915                 'row' : {
916                     'my' : {
917                         'docid' : docid,
918                         'bucket_item_id' : bucket_item_id
919                     }
920                 }
921             };
922             return item;
923                 } catch(E) {
924                         obj.error.standard_unexpected_error_alert($("catStrings").getFormattedString('staff.cat.record_buckets.prep_record_for_list.std_unex_err', [docid]),E);
925                         return null;
926                 }
927         }
928         
929 };
930
931 dump('exiting cat.record_buckets.js\n');