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