2b6fe9ef97509b994c7c6a5595c78ed02b7c6013
[Evergreen.git] / Open-ILS / xul / staff_client / server / cat / copy_editor.js
1 var g = {};
2
3 function my_init() {
4         try {
5                 /******************************************************************************************************/
6                 /* setup JSAN and some initial libraries */
7
8                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
9                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is missing."); }
10                 JSAN.errorLevel = "die"; // none, warn, or die
11                 JSAN.addRepository('/xul/server/');
12                 JSAN.use('util.error'); g.error = new util.error();
13                 g.error.sdump('D_TRACE','my_init() for cat/copy_editor.xul');
14
15                 JSAN.use('util.functional');
16                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
17                 JSAN.use('util.network'); g.network = new util.network();
18
19                 g.cgi = new CGI();
20
21                 g.session = g.cgi.param('session') || g.cgi.param('ses');
22                 g.docid = g.cgi.param('docid');
23
24                 /******************************************************************************************************/
25                 /* Get the copy ids from various sources and flesh them */
26
27                 var copy_ids = [];
28                 if (g.cgi.param('copy_ids')) copy_ids = JSON2js( g.cgi.param('copy_ids') );
29                 if (!copy_ids) copy_ids = [];
30                 if (window.xulG && window.xulG.copy_ids) copy_ids = copy_ids.concat( window.xulG.copy_ids );
31
32                 if (copy_ids.length > 0) g.copies = g.network.request(
33                         api.FM_ACP_FLESHED_BATCH_RETRIEVE.app,
34                         api.FM_ACP_FLESHED_BATCH_RETRIEVE.method,
35                         [ copy_ids ]
36                 );
37
38                 /******************************************************************************************************/
39                 /* And other fleshed copies if any */
40
41                 if (!g.copies) g.copies = [];
42                 if (window.xulG && window.xulG.copies) g.copies = g.copies.concat( window.xulG.copies );
43                 if (g.cgi.param('copies')) g.copies = g.copies.concat( JSON2js( g.cgi.param('copies') ) );
44
45                 /******************************************************************************************************/
46                 /* We try to retrieve callnumbers for existing copies, but for new copies, we rely on this */
47
48                 if (window.xulG && window.xulG.callnumbers) g.callnumbers = window.xulG.callnumbers;
49                 if (g.cgi.param('callnumbers')) g.callnumbers =  JSON2js( g.cgi.param('callnumbers') );
50
51                 /******************************************************************************************************/
52                 /* Is the interface an editor or a viewer? */
53
54                 if (g.cgi.param('edit') == '1') { 
55                         g.edit = true;
56                         document.getElementById('caption').setAttribute('label','Copy Editor'); 
57                         document.getElementById('nav').setAttribute('hidden','false'); 
58                 }
59
60                 /******************************************************************************************************/
61                 /* Show the Record Details? */
62
63                 if (g.docid) {
64                         document.getElementById('brief_display').setAttribute(
65                                 'src',
66                                 urls.XUL_BIB_BRIEF + '?docid=' + g.docid
67                         );
68                 } else {
69                         document.getElementById('brief_display').setAttribute('hidden','true');
70                 }
71
72                 /******************************************************************************************************/
73                 /* Add stat cats to the right_pane_field_names */
74
75                 var stat_cat_seen = {};
76
77                 function add_stat_cat(sc) {
78
79                         if (typeof g.data.hash.asc == 'undefined') { g.data.hash.asc = {}; g.data.stash('hash'); }
80
81                         var sc_id = sc;
82
83                         if (typeof sc == 'object') {
84
85                                 sc_id = sc.id();
86                         }
87
88                         if (typeof stat_cat_seen[sc_id] != 'undefined') { return; }
89
90                         stat_cat_seen[ sc_id ] = 1;
91
92                         if (typeof sc != 'object') {
93
94                                 sc = g.network.simple_request(
95                                         'FM_ASC_BATCH_RETRIEVE',
96                                         [ g.session, [ sc_id ] ]
97                                 )[0];
98
99                         }
100
101                         g.data.hash.asc[ sc.id() ] = sc; g.data.stash('hash');
102
103                         var label_name = g.data.hash.aou[ sc.owner() ].shortname() + " : " + sc.name();
104
105                         var temp_array = [
106                                 label_name,
107                                 {
108                                         render: 'var l = util.functional.find_list( fm.stat_cat_entries(), function(e){ return e.stat_cat() == ' 
109                                                 + sc.id() + '; } ); l ? l.value() : null;',
110                                         input: 'x = util.widgets.make_menulist( util.functional.map_list( g.data.hash.asc[' + sc.id() 
111                                                 + '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ).sort() ); '
112                                                 + 'x.addEventListener("command",function(ev) { g.apply_stat_cat(' + sc.id()
113                                                 + ', ev.target.value); } ,false);',
114                                 }
115                         ];
116
117                         dump('temp_array = ' + js2JSON(temp_array) + '\n');
118
119                         g.right_pane_field_names.push( temp_array );
120                 }
121
122                 /* The stat cats for the pertinent library */
123                 for (var i = 0; i < g.data.list.my_asc.length; i++) {
124                         add_stat_cat( g.data.list.my_asc[i] );  
125                 }
126
127                 /* Other stat cats present on these copies */
128                 for (var i = 0; i < g.copies.length; i++) {
129                         var entries = g.copies[i].stat_cat_entries();
130                         for (var j = 0; j < entries.length; j++) {
131                                 var sc_id = entries[j].stat_cat();
132                                 add_stat_cat( sc_id );
133                         }
134                 }
135
136                 /******************************************************************************************************/
137                 /* Do it */
138
139                 g.summarize( g.copies );
140                 g.render();
141
142         } catch(E) {
143                 var err_msg = "!! This software has encountered an error.  Please tell your friendly " +
144                         "system administrator or software developer the following:\ncat/copy_editor.xul\n" + E + '\n';
145                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
146                 alert(err_msg);
147         }
148 }
149
150 /******************************************************************************************************/
151 /* Apply a value to a specific field on all the copies being edited */
152
153 g.apply = function(field,value) {
154         g.error.sdump('D_TRACE','field = ' + field + '  value = ' + value + '\n');
155         for (var i = 0; i < g.copies.length; i++) {
156                 var copy = g.copies[i];
157                 try {
158                         copy[field]( value ); copy.ischanged('1');
159                 } catch(E) {
160                         alert(E);
161                 }
162         }
163 }
164
165 /******************************************************************************************************/
166 /* Apply a stat cat entry to all the copies being edited */
167
168 g.apply_stat_cat = function(sc_id,entry_id) {
169         g.error.sdump('D_TRACE','sc_id = ' + sc_id + '  entry_id = ' + entry_id + '\n');
170         for (var i = 0; i < g.copies.length; i++) {
171                 var copy = g.copies[i];
172                 try {
173                         copy.ischanged('1');
174                         var temp = copy.stat_cat_entries();
175                         temp = util.functional.filter_list(
176                                 temp,
177                                 function (obj) {
178                                         return (obj.stat_cat() != sc_id);
179                                 }
180                         );
181                         temp.push( 
182                                 util.functional.find_id_object_in_list( 
183                                         g.data.hash.asc[sc_id].entries(), 
184                                         entry_id
185                                 )
186                         );
187                         copy.stat_cat_entries( temp );
188
189                 } catch(E) {
190                         alert(E);
191                 }
192         }
193 }
194
195
196 /******************************************************************************************************/
197 /* These need data from the middle layer to render */
198
199 g.special_exception = {
200         'Call Number' : function(label,value) {
201                 if (value>0) { /* an existing call number */
202                         g.network.request(
203                                 api.FM_ACN_RETRIEVE.app,
204                                 api.FM_ACN_RETRIEVE.method,
205                                 [ value ],
206                                 function(req) {
207                                         var cn = '??? id = ' + value;
208                                         try {
209                                                 cn = req.getResultObject().label();
210                                         } catch(E) {
211                                                 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
212                                         }
213                                         label.setAttribute('value',cn);
214                                 }
215                         );
216                 } else { /* a yet to be created call number */
217                         if (g.callnumbers) {
218                                 label.setAttribute('value',g.callnumbers[value]);
219                         }
220                 }
221         },
222         'Creator' : function(label,value) {
223                 g.network.request(
224                         api.FM_AU_RETRIEVE_VIA_ID.app,
225                         api.FM_AU_RETRIEVE_VIA_ID.method,
226                         [ g.session, value ],
227                         function(req) {
228                                 var p = '??? id = ' + value;
229                                 try {
230                                         p = req.getResultObject();
231                                         p = p.card().barcode() + ' : ' + p.family_name();
232
233                                 } catch(E) {
234                                         g.error.sdump('D_ERROR','patron retrieve: ' + E);
235                                 }
236                                 label.setAttribute('value',p);
237                         }
238                 );
239         },
240         'Last Editor' : function(label,value) {
241                 g.network.request(
242                         api.FM_AU_RETRIEVE_VIA_ID.app,
243                         api.FM_AU_RETRIEVE_VIA_ID.method,
244                         [ g.session, value ],
245                         function(req) {
246                                 var p = '??? id = ' + value;
247                                 try {
248                                         p = req.getResultObject();
249                                         p = p.card().barcode() + ' : ' + p.family_name();
250
251                                 } catch(E) {
252                                         g.error.sdump('D_ERROR','patron retrieve: ' + E);
253                                 }
254                                 label.setAttribute('value',p);
255                         }
256                 );
257         }
258
259 }
260
261 /******************************************************************************************************/
262 g.readonly_stat_cat_names = [];
263 g.editable_stat_cat_names = [];
264
265 /******************************************************************************************************/
266 /* These get show in the left panel */
267
268 g.left_pane_field_names = [
269         [
270                 "Barcode",               
271                 {
272                         render: 'fm.barcode();',
273                 }
274         ], 
275         [
276                 "Call Number",  
277                 {
278                         render: 'fm.call_number();',
279                 }
280         ],
281         [
282                 "Creation Date",
283                 { 
284                         render: 'util.date.formatted_date( fm.create_date(), "%F");',
285                 }
286         ],
287         [
288                 "Last Edit Date",
289                 { 
290                         render: 'util.date.formatted_date( fm.edit_date(), "%F");',
291                 }
292         ],
293
294 ];
295
296 /******************************************************************************************************/
297 /* These get shown in the right panel */
298
299 g.right_pane_field_names = [
300         [
301                 "Creator",
302                 { 
303                         render: 'fm.creator();',
304                 }
305         ],
306         [
307                 "Last Editor",
308                 {
309                         render: 'fm.editor();',
310                 }
311         ],
312          [
313                 "Circulate as Type",    
314                 {       
315                         render: 'fm.circ_as_type();',
316                         input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_as_type",ev.target.value); }, false);',
317                 } 
318         ],
319         [
320                 "Circulation Library",          
321                 {       
322                         render: 'fm.circ_lib().shortname();',
323                         input: 'x = util.widgets.make_menulist( util.functional.map_list( util.functional.filter_list(g.data.list.my_aou, function(obj) { return g.data.hash.aout[ obj.ou_type() ].can_have_vols(); }), function(obj) { return [ obj.shortname(), obj.id() ]; }).sort() ); x.addEventListener("command",function(ev) { g.apply("circ_lib",ev.target.value); }, false);',
324                 } 
325         ],
326         [
327                 "Circulation Modifier",
328                 {       
329                         render: 'fm.circ_modifier();',
330                         input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_modifier",ev.target.value); }, false);',
331                 }
332         ],
333         [
334                 "Circulate?",
335                 {       
336                         render: 'fm.circulate() ? "Yes" : "No";',
337                         input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("circulate",ev.target.value); }, false);',
338                 }
339         ],
340         [
341                 "Copy Number",
342                 { 
343                         render: 'fm.copy_number();',
344                         input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("copy_number",ev.target.value); }, false);',
345                 }
346         ],
347         [
348                 "Deposit?",
349                 { 
350                         render: 'fm.deposit() ? "Yes" : "No";',
351                         input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("deposit",ev.target.value); }, false);',
352                 }
353         ],
354         [
355                 "Deposit Amount",
356                 { 
357                         render: 'util.money.sanitize( fm.deposit_amount() );',
358                         input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("deposit_amount",ev.target.value); }, false);',
359                 }
360         ],
361         [
362                 "Fine Level",
363                 {
364                         render: 'switch(fm.fine_level()){ case 1: "Low"; break; case 2: "Normal"; break; case 3: "High"; break; }',
365                         input: 'x = util.widgets.make_menulist( [ [ "Low", "1" ], [ "Normal", "2" ], [ "High", "3" ] ] ); x.addEventListener("command",function(ev) { g.apply("fine_level",ev.target.value); }, false);',
366                 }
367         ],
368         [
369                 "Holdable?",
370                 { 
371                         render: 'fm.holdable() ? "Yes" : "No";', 
372                         input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("holdable",ev.target.value); }, false);',
373                 }
374         ],
375         [
376                 "Loan Duration",
377                 { 
378                         render: 'switch(fm.loan_duration()){ case 1: "Short"; break; case 2: "Normal"; break; case 3: "Long"; break; }',
379                         input: 'x = util.widgets.make_menulist( [ [ "Short", "1" ], [ "Normal", "2" ], [ "Long", "3" ] ] ); x.addEventListener("command",function(ev) { g.apply("loan_duration",ev.target.value); }, false);',
380
381                 }
382         ],
383         [
384                 "Shelving Location",
385                 { 
386                         render: 'fm.location().name();', 
387                         input: 'x = util.widgets.make_menulist( util.functional.map_list( g.data.list.acpl, function(obj) { return [ obj.name(), obj.id() ]; }).sort()); x.addEventListener("command",function(ev) { g.apply("location",ev.target.value); }, false);',
388
389                 }
390         ],
391         [
392                 "OPAC Visible?",
393                 { 
394                         render: 'fm.opac_visible() ? "Yes" : "No";', 
395                         input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("opac_visible",ev.target.value); }, false);',
396                 }
397         ],
398         [
399                 "Price",
400                 { 
401                         render: 'util.money.sanitize( fm.price() );', 
402                         input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("deposit_amount",ev.target.value); }, false);',
403                 }
404         ],
405         [
406                 "Reference?",
407                 { 
408                         render: 'fm.ref() ? "Yes" : "No";', 
409                         input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("ref",ev.target.value); }, false);',
410                 }
411         ],
412         [
413                 "Status",
414                 { 
415                         render: 'fm.status().name();', 
416                         input: 'x = util.widgets.make_menulist( util.functional.map_list( g.data.list.ccs, function(obj) { return [ obj.name(), obj.id() ]; } ).sort() ); x.addEventListener("command",function(ev) { g.apply("status",ev.target.value); }, false);',
417
418
419                 }
420         ],
421 ];
422
423 /******************************************************************************************************/
424 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
425
426 g.summarize = function( copies ) {
427         /******************************************************************************************************/
428         /* Setup */
429
430         JSAN.use('util.date'); JSAN.use('util.money');
431         g.summary = {};
432         g.field_names = g.left_pane_field_names;
433         g.field_names = g.field_names.concat( g.right_pane_field_names );
434         g.field_names = g.field_names.concat( g.editable_stat_cat_names );
435         g.field_names = g.field_names.concat( g.readonly_stat_cat_names );
436
437         /******************************************************************************************************/
438         /* Loop through the field names */
439
440         for (var i = 0; i < g.field_names.length; i++) {
441
442                 var field_name = g.field_names[i][0];
443                 var render = g.field_names[i][1].render;
444                 g.summary[ field_name ] = {};
445
446                 /******************************************************************************************************/
447                 /* Loop through the copies */
448
449                 for (var j = 0; j < copies.length; j++) {
450
451                         var fm = copies[j];
452                         var cmd = render || ('fm.' + field_name + '();');
453                         var value = '???';
454
455                         /**********************************************************************************************/
456                         /* Try to retrieve the value for this field for this copy */
457
458                         try { 
459                                 value = eval( cmd ); 
460                         } catch(E) { 
461                                 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' +  E + '\n'); 
462                         }
463                         if (typeof value == 'object' && value != null) {
464                                 alert('FIXME: field_name = ' + field_name + '  value = ' + js2JSON(value) + '\n');
465                         }
466
467                         /**********************************************************************************************/
468                         /* Tally the count */
469
470                         if (g.summary[ field_name ][ value ]) {
471                                 g.summary[ field_name ][ value ]++;
472                         } else {
473                                 g.summary[ field_name ][ value ] = 1;
474                         }
475                 }
476         }
477         g.error.sdump('D_TRACE','summary = ' + js2JSON(g.summary) + '\n');
478 }
479
480 /******************************************************************************************************/
481 /* Display the summarized data and inputs for editing */
482
483 g.render = function() {
484
485         /******************************************************************************************************/
486         /* Library setup and clear any existing interface */
487
488         JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
489
490         var cns = document.getElementById('call_number_summary');
491         util.widgets.remove_children( cns );
492         var bcs = document.getElementById('barcode_summary');
493         util.widgets.remove_children( bcs );
494         var rp = document.getElementById('right_pane');
495         util.widgets.remove_children( rp );
496
497         /******************************************************************************************************/
498         /* Make the call number summary */
499
500         var grid = util.widgets.make_grid( [ { 'flex' : '1' } ] );
501         cns.appendChild(grid);
502         for (var i in g.summary['Call Number']) {
503                 var cn_id = i; var count = g.summary['Call Number'][i];
504                 var row = document.createElement('row'); grid.lastChild.appendChild(row);
505                 var cn_label = document.createElement('label'); row.appendChild(cn_label);
506                 g.special_exception['Call Number']( cn_label, cn_id );
507                 var count_label = document.createElement('label'); row.appendChild(count_label);
508                 var unit = count == 1 ? 'copy' : 'copies';
509                 count_label.setAttribute('value',count + ' ' + unit);
510         }
511
512         /******************************************************************************************************/
513         /* List the copy barcodes */
514
515         for (var i in g.summary['Barcode']) {
516                 var bc = i;
517                 var hbox = document.createElement('hbox'); bcs.appendChild(hbox);
518                 var bc_label = document.createElement('label'); hbox.appendChild(bc_label);
519                 bc_label.setAttribute('value',bc);
520         }
521
522         /******************************************************************************************************/
523         /* List the other non-editable fields in this pane */
524
525         var groupbox; var caption; var vbox; var grid; var rows;
526         for (var i = 0; i < g.left_pane_field_names.length; i++) {
527                 try {
528                         var f = g.left_pane_field_names[i]; var fn = f[0];
529                         if (fn == 'Call Number' || fn == 'Barcode') continue;
530                         groupbox = document.createElement('groupbox'); bcs.parentNode.parentNode.appendChild(groupbox);
531                         caption = document.createElement('caption'); groupbox.appendChild(caption);
532                         caption.setAttribute('label',fn);
533                         vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
534                         grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
535                         grid.setAttribute('flex','1');
536                         rows = grid.lastChild;
537                         var row;
538                         
539                         /**************************************************************************************/
540                         /* Loop through each value for the field */
541
542                         for (var j in g.summary[fn]) {
543                                 var value = j; var count = g.summary[fn][j];
544                                 row = document.createElement('row'); rows.appendChild(row);
545                                 var label1 = document.createElement('label'); row.appendChild(label1);
546                                 if (g.special_exception[ fn ]) {
547                                         g.special_exception[ fn ]( label1, value );
548                                 } else {
549                                         label1.setAttribute('value',value);
550                                 }
551                                 var label2 = document.createElement('label'); row.appendChild(label2);
552                                 var unit = count == 1 ? 'copy' : 'copies';
553                                 label2.setAttribute('value',count + ' ' + unit);
554                         }
555                         var hbox = document.createElement('hbox'); 
556                         vbox.appendChild(hbox);
557                 } catch(E) {
558                         g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
559                 }
560         }
561
562         /******************************************************************************************************/
563         /* Prepare the right panel, which is different for 1-copy view and multi-copy view */
564
565         if (g.copies.length == 1) {
566
567                 /******************************************************************************************************/
568                 /* 1-copy mode has a single groupbox and each field is a row on a grid */
569
570                 var groupbox; var caption; var vbox; var grid; var rows;
571                 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
572                 caption = document.createElement('caption'); groupbox.appendChild(caption);
573                 caption.setAttribute('label','Fields');
574                 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
575                 grid = util.widgets.make_grid( [ {}, { 'flex' : 1 } ] ); vbox.appendChild(grid);
576                 grid.setAttribute('flex','1');
577                 rows = grid.lastChild;
578
579                 /******************************************************************************************************/
580                 /* Loop through the field names */
581
582                 for (var i = 0; i < g.right_pane_field_names.length; i++) {
583                         try {
584                                 var f = g.right_pane_field_names[i]; var fn = f[0];
585                                 var row;
586
587                                 /**************************************************************************************/
588                                 /* Loop through each value for the field */
589
590                                 for (var j in g.summary[fn]) {
591                                         var value = j; var count = g.summary[fn][j];
592                                         row = document.createElement('row'); rows.appendChild(row);
593                                         var label0 = document.createElement('label'); row.appendChild(label0);
594                                         label0.setAttribute('value',fn);
595                                         label0.setAttribute('style','font-weight: bold');
596                                         var label1 = document.createElement('label'); row.appendChild(label1);
597                                         if (g.special_exception[ fn ]) {
598                                                 g.special_exception[ fn ]( label1, value );
599                                         } else {
600                                                 label1.setAttribute('value',value);
601                                         }
602
603                                 }
604
605                                 /**************************************************************************************/
606                                 /* Render the input widget */
607
608                                 var hbox = document.createElement('hbox'); 
609                                 row.setAttribute('style','border-bottom: dotted black thin');
610                                 row.appendChild(hbox);
611                                 if (f[1].input && g.edit) {
612                                         try {
613                                                 var spacer = document.createElement('spacer'); hbox.appendChild(spacer);
614                                                 spacer.setAttribute('flex','1');
615                                                 var deck = document.createElement('deck'); hbox.appendChild(deck);
616                                                 var btn = document.createElement('button'); deck.appendChild(btn);
617                                                 deck.setAttribute('style','width: 200px; min-width: 200px;');
618                                                 btn.setAttribute('label','Change');
619                                                 btn.setAttribute('oncommand','this.parentNode.selectedIndex = 1;');
620                                                 var x; eval( f[1].input );
621                                                 if (x) deck.appendChild(x);
622
623                                         } catch(E) {
624                                                 g.error.sdump('D_ERROR',E + '\n');
625                                         }
626                                 }
627
628                         } catch(E) {
629                                 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
630                         }
631                 }
632
633         } else {
634
635                 /******************************************************************************************************/
636                 /* multi-copy mode has a groupbox for each field */
637
638                 var groupbox; var caption; var vbox; var grid; var rows;
639                 
640                 /******************************************************************************************************/
641                 /* Loop through the field names */
642
643                 for (var i = 0; i < g.right_pane_field_names.length; i++) {
644                         try {
645                                 var f = g.right_pane_field_names[i]; var fn = f[0];
646                                 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
647                                 caption = document.createElement('caption'); groupbox.appendChild(caption);
648                                 caption.setAttribute('label',fn);
649                                 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
650                                 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
651                                 grid.setAttribute('flex','1');
652                                 rows = grid.lastChild;
653                                 var row;
654                                 
655                                 /**************************************************************************************/
656                                 /* Loop through each value for the field */
657
658                                 for (var j in g.summary[fn]) {
659                                         var value = j; var count = g.summary[fn][j];
660                                         row = document.createElement('row'); rows.appendChild(row);
661                                         var label1 = document.createElement('label'); row.appendChild(label1);
662                                         if (g.special_exception[ fn ]) {
663                                                 g.special_exception[ fn ]( label1, value );
664                                         } else {
665                                                 label1.setAttribute('value',value);
666                                         }
667                                         var label2 = document.createElement('label'); row.appendChild(label2);
668                                         var unit = count == 1 ? 'copy' : 'copies';
669                                         label2.setAttribute('value',count + ' ' + unit);
670
671                                 }
672                                 var hbox = document.createElement('hbox'); 
673                                 vbox.appendChild(hbox);
674
675                                 /**************************************************************************************/
676                                 /* Render the input widget */
677
678                                 if (f[1].input && g.edit) {
679                                         try {
680                                                 var spacer = document.createElement('spacer'); hbox.appendChild(spacer);
681                                                 spacer.setAttribute('flex','1');
682                                                 var deck = document.createElement('deck'); hbox.appendChild(deck);
683                                                 var btn = document.createElement('button'); deck.appendChild(btn);
684                                                 deck.setAttribute('style','width: 200px; min-width: 200px;');
685                                                 btn.setAttribute('label','Change');
686                                                 btn.setAttribute('oncommand','this.parentNode.selectedIndex = 1;');
687                                                 var x; eval( f[1].input );
688                                                 if (x) deck.appendChild(x);
689
690                                         } catch(E) {
691                                                 g.error.sdump('D_ERROR',E + '\n');
692                                         }
693                                 }
694                         } catch(E) {
695                                 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
696                         }
697                 }
698         }
699 }
700
701 /******************************************************************************************************/
702 /* store the copies in the global xpcom stash */
703
704 g.stash_and_close = function() {
705         g.data.temp = js2JSON( g.copies );
706         g.error.sdump('D_CAT','in modal window, g.data.temp = \n' + g.data.temp + '\n');
707         g.data.stash('temp');
708         window.close();
709 }
710