5 /******************************************************************************************************/
6 /* setup JSAN and some initial libraries */
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');
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();
21 g.session = g.cgi.param('session') || g.cgi.param('ses');
22 g.docid = g.cgi.param('docid');
24 /******************************************************************************************************/
25 /* Get the copy ids from various sources and flesh them */
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 );
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,
38 /******************************************************************************************************/
39 /* And other fleshed copies if any */
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') ) );
45 /******************************************************************************************************/
46 /* We try to retrieve callnumbers for existing copies, but for new copies, we rely on this */
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') );
51 /******************************************************************************************************/
52 /* Is the interface an editor or a viewer? */
54 if (g.cgi.param('edit') == '1') {
56 document.getElementById('caption').setAttribute('label','Copy Editor');
57 document.getElementById('nav').setAttribute('hidden','false');
60 /******************************************************************************************************/
61 /* Show the Record Details? */
64 document.getElementById('brief_display').setAttribute(
66 urls.XUL_BIB_BRIEF + '?docid=' + g.docid
69 document.getElementById('brief_display').setAttribute('hidden','true');
72 /******************************************************************************************************/
73 /* Add stat cats to the right_pane_field_names */
75 var stat_cat_seen = {};
77 function add_stat_cat(sc) {
79 if (typeof g.data.hash.asc == 'undefined') { g.data.hash.asc = {}; g.data.stash('hash'); }
83 if (typeof sc == 'object') {
88 if (typeof stat_cat_seen[sc_id] != 'undefined') { return; }
90 stat_cat_seen[ sc_id ] = 1;
92 if (typeof sc != 'object') {
94 sc = g.network.simple_request(
95 'FM_ASC_BATCH_RETRIEVE',
96 [ g.session, [ sc_id ] ]
101 g.data.hash.asc[ sc.id() ] = sc; g.data.stash('hash');
103 var label_name = g.data.hash.aou[ sc.owner() ].shortname() + " : " + sc.name();
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);',
117 dump('temp_array = ' + js2JSON(temp_array) + '\n');
119 g.right_pane_field_names.push( temp_array );
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] );
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 );
137 /******************************************************************************************************/
140 g.summarize( g.copies );
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)); }
151 /******************************************************************************************************/
152 /* Apply a value to a specific field on all the copies being edited */
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];
159 copy[field]( value ); copy.ischanged('1');
166 /******************************************************************************************************/
167 /* Apply a stat cat entry to all the copies being edited */
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];
175 var temp = copy.stat_cat_entries();
176 if (!temp) temp = [];
177 temp = util.functional.filter_list(
180 return (obj.stat_cat() != sc_id);
184 util.functional.find_id_object_in_list(
185 g.data.hash.asc[sc_id].entries(),
189 copy.stat_cat_entries( temp );
198 /******************************************************************************************************/
199 /* These need data from the middle layer to render */
201 g.special_exception = {
202 'Call Number' : function(label,value) {
203 if (value>0) { /* an existing call number */
205 api.FM_ACN_RETRIEVE.app,
206 api.FM_ACN_RETRIEVE.method,
209 var cn = '??? id = ' + value;
211 cn = req.getResultObject().label();
213 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
215 label.setAttribute('value',cn);
218 } else { /* a yet to be created call number */
220 label.setAttribute('value',g.callnumbers[value]);
224 'Creator' : function(label,value) {
226 api.FM_AU_RETRIEVE_VIA_ID.app,
227 api.FM_AU_RETRIEVE_VIA_ID.method,
228 [ g.session, value ],
230 var p = '??? id = ' + value;
232 p = req.getResultObject();
233 p = p.card().barcode() + ' : ' + p.family_name();
236 g.error.sdump('D_ERROR','patron retrieve: ' + E);
238 label.setAttribute('value',p);
242 'Last Editor' : function(label,value) {
244 api.FM_AU_RETRIEVE_VIA_ID.app,
245 api.FM_AU_RETRIEVE_VIA_ID.method,
246 [ g.session, value ],
248 var p = '??? id = ' + value;
250 p = req.getResultObject();
251 p = p.card().barcode() + ' : ' + p.family_name();
254 g.error.sdump('D_ERROR','patron retrieve: ' + E);
256 label.setAttribute('value',p);
263 /******************************************************************************************************/
264 g.readonly_stat_cat_names = [];
265 g.editable_stat_cat_names = [];
267 /******************************************************************************************************/
268 /* These get show in the left panel */
270 g.left_pane_field_names = [
274 render: 'fm.barcode();',
280 render: 'fm.call_number();',
286 render: 'util.date.formatted_date( fm.create_date(), "%F");',
292 render: 'util.date.formatted_date( fm.edit_date(), "%F");',
298 /******************************************************************************************************/
299 /* These get shown in the right panel */
301 g.right_pane_field_names = [
305 render: 'fm.creator();',
311 render: 'fm.editor();',
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);',
322 "Circulation Library",
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);',
329 "Circulation Modifier",
331 render: 'fm.circ_modifier();',
332 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_modifier",ev.target.value); }, false);',
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);',
345 render: 'fm.copy_number();',
346 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("copy_number",ev.target.value); }, false);',
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);',
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);',
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);',
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);',
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);',
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);',
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);',
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);',
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);',
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);',
425 /******************************************************************************************************/
426 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
428 g.summarize = function( copies ) {
429 /******************************************************************************************************/
432 JSAN.use('util.date'); JSAN.use('util.money');
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 );
439 /******************************************************************************************************/
440 /* Loop through the field names */
442 for (var i = 0; i < g.field_names.length; i++) {
444 var field_name = g.field_names[i][0];
445 var render = g.field_names[i][1].render;
446 g.summary[ field_name ] = {};
448 /******************************************************************************************************/
449 /* Loop through the copies */
451 for (var j = 0; j < copies.length; j++) {
454 var cmd = render || ('fm.' + field_name + '();');
457 /**********************************************************************************************/
458 /* Try to retrieve the value for this field for this copy */
463 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n');
465 if (typeof value == 'object' && value != null) {
466 alert('FIXME: field_name = ' + field_name + ' value = ' + js2JSON(value) + '\n');
469 /**********************************************************************************************/
470 /* Tally the count */
472 if (g.summary[ field_name ][ value ]) {
473 g.summary[ field_name ][ value ]++;
475 g.summary[ field_name ][ value ] = 1;
479 g.error.sdump('D_TRACE','summary = ' + js2JSON(g.summary) + '\n');
482 /******************************************************************************************************/
483 /* Display the summarized data and inputs for editing */
485 g.render = function() {
487 /******************************************************************************************************/
488 /* Library setup and clear any existing interface */
490 JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
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 );
499 /******************************************************************************************************/
500 /* Make the call number summary */
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);
514 /******************************************************************************************************/
515 /* List the copy barcodes */
517 for (var i in g.summary['Barcode']) {
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);
524 /******************************************************************************************************/
525 /* List the other non-editable fields in this pane */
527 var groupbox; var caption; var vbox; var grid; var rows;
528 for (var i = 0; i < g.left_pane_field_names.length; i++) {
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;
541 /**************************************************************************************/
542 /* Loop through each value for the field */
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 );
551 label1.setAttribute('value',value);
553 var label2 = document.createElement('label'); row.appendChild(label2);
554 var unit = count == 1 ? 'copy' : 'copies';
555 label2.setAttribute('value',count + ' ' + unit);
557 var hbox = document.createElement('hbox');
558 vbox.appendChild(hbox);
560 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
564 /******************************************************************************************************/
565 /* Prepare the right panel, which is different for 1-copy view and multi-copy view */
567 if (g.copies.length == 1) {
569 /******************************************************************************************************/
570 /* 1-copy mode has a single groupbox and each field is a row on a grid */
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;
581 /******************************************************************************************************/
582 /* Loop through the field names */
584 for (var i = 0; i < g.right_pane_field_names.length; i++) {
586 var f = g.right_pane_field_names[i]; var fn = f[0];
589 /**************************************************************************************/
590 /* Loop through each value for the field */
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 );
602 label1.setAttribute('value',value);
607 /**************************************************************************************/
608 /* Render the input widget */
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) {
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);
626 g.error.sdump('D_ERROR',E + '\n');
631 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
637 /******************************************************************************************************/
638 /* multi-copy mode has a groupbox for each field */
640 var groupbox; var caption; var vbox; var grid; var rows;
642 /******************************************************************************************************/
643 /* Loop through the field names */
645 for (var i = 0; i < g.right_pane_field_names.length; i++) {
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;
657 /**************************************************************************************/
658 /* Loop through each value for the field */
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 );
667 label1.setAttribute('value',value);
669 var label2 = document.createElement('label'); row.appendChild(label2);
670 var unit = count == 1 ? 'copy' : 'copies';
671 label2.setAttribute('value',count + ' ' + unit);
674 var hbox = document.createElement('hbox');
675 vbox.appendChild(hbox);
677 /**************************************************************************************/
678 /* Render the input widget */
680 if (f[1].input && g.edit) {
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);
693 g.error.sdump('D_ERROR',E + '\n');
697 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
703 /******************************************************************************************************/
704 /* store the copies in the global xpcom stash */
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');