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 if (g.cgi.param('single_edit') == '1') {
62 document.getElementById('caption').setAttribute('label','Copy Editor');
63 document.getElementById('nav').setAttribute('hidden','false');
66 /******************************************************************************************************/
67 /* Show the Record Details? */
70 document.getElementById('brief_display').setAttribute(
72 urls.XUL_BIB_BRIEF + '?docid=' + g.docid
75 document.getElementById('brief_display').setAttribute('hidden','true');
78 /******************************************************************************************************/
79 /* Add stat cats to the right_pane_field_names */
81 var stat_cat_seen = {};
83 function add_stat_cat(sc) {
85 if (typeof g.data.hash.asc == 'undefined') { g.data.hash.asc = {}; g.data.stash('hash'); }
89 if (typeof sc == 'object') {
94 if (typeof stat_cat_seen[sc_id] != 'undefined') { return; }
96 stat_cat_seen[ sc_id ] = 1;
98 if (typeof sc != 'object') {
100 sc = g.network.simple_request(
101 'FM_ASC_BATCH_RETRIEVE',
102 [ g.session, [ sc_id ] ]
107 g.data.hash.asc[ sc.id() ] = sc; g.data.stash('hash');
109 var label_name = g.data.hash.aou[ sc.owner() ].shortname() + " : " + sc.name();
114 render: 'var l = util.functional.find_list( fm.stat_cat_entries(), function(e){ return e.stat_cat() == '
115 + sc.id() + '; } ); l ? l.value() : null;',
116 input: 'x = util.widgets.make_menulist( util.functional.map_list( g.data.hash.asc[' + sc.id()
117 + '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ).sort() ); '
118 + 'x.addEventListener("command",function(ev) { g.apply_stat_cat(' + sc.id()
119 + ', ev.target.value); } ,false);',
123 dump('temp_array = ' + js2JSON(temp_array) + '\n');
125 g.right_pane_field_names.push( temp_array );
128 /* The stat cats for the pertinent library */
129 for (var i = 0; i < g.data.list.my_asc.length; i++) {
130 add_stat_cat( g.data.list.my_asc[i] );
133 /* Other stat cats present on these copies */
134 for (var i = 0; i < g.copies.length; i++) {
135 var entries = g.copies[i].stat_cat_entries();
136 if (!entries) entries = [];
137 for (var j = 0; j < entries.length; j++) {
138 var sc_id = entries[j].stat_cat();
139 add_stat_cat( sc_id );
143 /******************************************************************************************************/
146 g.summarize( g.copies );
150 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
151 "system administrator or software developer the following:\ncat/copy_editor.xul\n" + E + '\n';
152 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
157 /******************************************************************************************************/
158 /* Apply a value to a specific field on all the copies being edited */
160 g.apply = function(field,value) {
161 g.error.sdump('D_TRACE','field = ' + field + ' value = ' + value + '\n');
162 for (var i = 0; i < g.copies.length; i++) {
163 var copy = g.copies[i];
165 copy[field]( value ); copy.ischanged('1');
172 /******************************************************************************************************/
173 /* Apply a stat cat entry to all the copies being edited */
175 g.apply_stat_cat = function(sc_id,entry_id) {
176 g.error.sdump('D_TRACE','sc_id = ' + sc_id + ' entry_id = ' + entry_id + '\n');
177 for (var i = 0; i < g.copies.length; i++) {
178 var copy = g.copies[i];
181 var temp = copy.stat_cat_entries();
182 if (!temp) temp = [];
183 temp = util.functional.filter_list(
186 return (obj.stat_cat() != sc_id);
190 util.functional.find_id_object_in_list(
191 g.data.hash.asc[sc_id].entries(),
195 copy.stat_cat_entries( temp );
204 /******************************************************************************************************/
205 /* These need data from the middle layer to render */
207 g.special_exception = {
208 'Call Number' : function(label,value) {
209 if (value>0) { /* an existing call number */
211 api.FM_ACN_RETRIEVE.app,
212 api.FM_ACN_RETRIEVE.method,
215 var cn = '??? id = ' + value;
217 cn = req.getResultObject().label();
219 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
221 label.setAttribute('value',cn);
224 } else { /* a yet to be created call number */
226 label.setAttribute('value',g.callnumbers[value]);
230 'Creator' : function(label,value) {
232 api.FM_AU_RETRIEVE_VIA_ID.app,
233 api.FM_AU_RETRIEVE_VIA_ID.method,
234 [ g.session, value ],
236 var p = '??? id = ' + value;
238 p = req.getResultObject();
239 p = p.card().barcode() + ' : ' + p.family_name();
242 g.error.sdump('D_ERROR','patron retrieve: ' + E);
244 label.setAttribute('value',p);
248 'Last Editor' : function(label,value) {
250 api.FM_AU_RETRIEVE_VIA_ID.app,
251 api.FM_AU_RETRIEVE_VIA_ID.method,
252 [ g.session, value ],
254 var p = '??? id = ' + value;
256 p = req.getResultObject();
257 p = p.card().barcode() + ' : ' + p.family_name();
260 g.error.sdump('D_ERROR','patron retrieve: ' + E);
262 label.setAttribute('value',p);
269 /******************************************************************************************************/
270 g.readonly_stat_cat_names = [];
271 g.editable_stat_cat_names = [];
273 /******************************************************************************************************/
274 /* These get show in the left panel */
276 g.left_pane_field_names = [
280 render: 'fm.barcode();',
286 render: 'fm.call_number();',
292 render: 'util.date.formatted_date( fm.create_date(), "%F");',
298 render: 'util.date.formatted_date( fm.edit_date(), "%F");',
304 /******************************************************************************************************/
305 /* These get shown in the right panel */
307 g.right_pane_field_names = [
311 render: 'fm.creator();',
317 render: 'fm.editor();',
323 render: 'fm.circ_as_type();',
324 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_as_type",ev.target.value); }, false);',
328 "Circulation Library",
330 render: 'fm.circ_lib().shortname();',
331 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);',
335 "Circulation Modifier",
337 render: 'fm.circ_modifier();',
338 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_modifier",ev.target.value); }, false);',
344 render: 'fm.circulate() ? "Yes" : "No";',
345 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("circulate",ev.target.value); }, false);',
351 render: 'fm.copy_number();',
352 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("copy_number",ev.target.value); }, false);',
358 render: 'fm.deposit() ? "Yes" : "No";',
359 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("deposit",ev.target.value); }, false);',
365 render: 'util.money.sanitize( fm.deposit_amount() );',
366 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("deposit_amount",ev.target.value); }, false);',
372 render: 'switch(fm.fine_level()){ case 1: "Low"; break; case 2: "Normal"; break; case 3: "High"; break; }',
373 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);',
379 render: 'fm.holdable() ? "Yes" : "No";',
380 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("holdable",ev.target.value); }, false);',
386 render: 'switch(fm.loan_duration()){ case 1: "Short"; break; case 2: "Normal"; break; case 3: "Long"; break; }',
387 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);',
394 render: 'fm.location().name();',
395 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);',
402 render: 'fm.opac_visible() ? "Yes" : "No";',
403 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("opac_visible",ev.target.value); }, false);',
409 render: 'util.money.sanitize( fm.price() );',
410 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("deposit_amount",ev.target.value); }, false);',
416 render: 'fm.ref() ? "Yes" : "No";',
417 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("ref",ev.target.value); }, false);',
423 render: 'fm.status().name();',
424 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);',
431 /******************************************************************************************************/
432 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
434 g.summarize = function( copies ) {
435 /******************************************************************************************************/
438 JSAN.use('util.date'); JSAN.use('util.money');
440 g.field_names = g.left_pane_field_names;
441 g.field_names = g.field_names.concat( g.right_pane_field_names );
442 g.field_names = g.field_names.concat( g.editable_stat_cat_names );
443 g.field_names = g.field_names.concat( g.readonly_stat_cat_names );
445 /******************************************************************************************************/
446 /* Loop through the field names */
448 for (var i = 0; i < g.field_names.length; i++) {
450 var field_name = g.field_names[i][0];
451 var render = g.field_names[i][1].render;
452 g.summary[ field_name ] = {};
454 /******************************************************************************************************/
455 /* Loop through the copies */
457 for (var j = 0; j < copies.length; j++) {
460 var cmd = render || ('fm.' + field_name + '();');
463 /**********************************************************************************************/
464 /* Try to retrieve the value for this field for this copy */
469 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n');
471 if (typeof value == 'object' && value != null) {
472 alert('FIXME: field_name = ' + field_name + ' value = ' + js2JSON(value) + '\n');
475 /**********************************************************************************************/
476 /* Tally the count */
478 if (g.summary[ field_name ][ value ]) {
479 g.summary[ field_name ][ value ]++;
481 g.summary[ field_name ][ value ] = 1;
485 g.error.sdump('D_TRACE','summary = ' + js2JSON(g.summary) + '\n');
488 /******************************************************************************************************/
489 /* Display the summarized data and inputs for editing */
491 g.render = function() {
493 /******************************************************************************************************/
494 /* Library setup and clear any existing interface */
496 JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
498 var cns = document.getElementById('call_number_summary');
499 util.widgets.remove_children( cns );
500 var bcs = document.getElementById('barcode_summary');
501 util.widgets.remove_children( bcs );
502 var rp = document.getElementById('right_pane');
503 util.widgets.remove_children( rp );
505 /******************************************************************************************************/
506 /* Make the call number summary */
508 var grid = util.widgets.make_grid( [ { 'flex' : '1' } ] );
509 cns.appendChild(grid);
510 for (var i in g.summary['Call Number']) {
511 var cn_id = i; var count = g.summary['Call Number'][i];
512 var row = document.createElement('row'); grid.lastChild.appendChild(row);
513 var cn_label = document.createElement('label'); row.appendChild(cn_label);
514 g.special_exception['Call Number']( cn_label, cn_id );
515 var count_label = document.createElement('label'); row.appendChild(count_label);
516 var unit = count == 1 ? 'copy' : 'copies';
517 count_label.setAttribute('value',count + ' ' + unit);
520 /******************************************************************************************************/
521 /* List the copy barcodes */
523 for (var i in g.summary['Barcode']) {
525 var hbox = document.createElement('hbox'); bcs.appendChild(hbox);
526 var bc_label = document.createElement('label'); hbox.appendChild(bc_label);
527 bc_label.setAttribute('value',bc);
530 /******************************************************************************************************/
531 /* List the other non-editable fields in this pane */
533 var groupbox; var caption; var vbox; var grid; var rows;
534 for (var i = 0; i < g.left_pane_field_names.length; i++) {
536 var f = g.left_pane_field_names[i]; var fn = f[0];
537 if (fn == 'Call Number' || fn == 'Barcode') continue;
538 groupbox = document.createElement('groupbox'); bcs.parentNode.parentNode.appendChild(groupbox);
539 caption = document.createElement('caption'); groupbox.appendChild(caption);
540 caption.setAttribute('label',fn);
541 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
542 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
543 grid.setAttribute('flex','1');
544 rows = grid.lastChild;
547 /**************************************************************************************/
548 /* Loop through each value for the field */
550 for (var j in g.summary[fn]) {
551 var value = j; var count = g.summary[fn][j];
552 row = document.createElement('row'); rows.appendChild(row);
553 var label1 = document.createElement('label'); row.appendChild(label1);
554 if (g.special_exception[ fn ]) {
555 g.special_exception[ fn ]( label1, value );
557 label1.setAttribute('value',value);
559 var label2 = document.createElement('label'); row.appendChild(label2);
560 var unit = count == 1 ? 'copy' : 'copies';
561 label2.setAttribute('value',count + ' ' + unit);
563 var hbox = document.createElement('hbox');
564 vbox.appendChild(hbox);
566 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
570 /******************************************************************************************************/
571 /* Prepare the right panel, which is different for 1-copy view and multi-copy view */
575 /******************************************************************************************************/
576 /* For a less dangerous batch edit, choose one field here */
578 var gb = document.createElement('groupbox'); rp.appendChild(gb);
579 var c = document.createElement('caption'); gb.appendChild(c);
580 c.setAttribute('label','Choose a field to edit');
581 JSAN.use('util.widgets'); JSAN.use('util.functional');
582 var ml = util.widgets.make_menulist(
583 util.functional.map_list(
584 g.right_pane_field_names,
585 function(o,i) { return [ o[0], i ]; }
592 g.render_input(gb, g.right_pane_field_names[ ev.target.value ][1].input);
600 if (g.copies.length == 1) {
602 /******************************************************************************************************/
603 /* 1-copy mode has a single groupbox and each field is a row on a grid */
605 var groupbox; var caption; var vbox; var grid; var rows;
606 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
607 caption = document.createElement('caption'); groupbox.appendChild(caption);
608 caption.setAttribute('label','Fields');
609 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
610 grid = util.widgets.make_grid( [ {}, { 'flex' : 1 } ] ); vbox.appendChild(grid);
611 grid.setAttribute('flex','1');
612 rows = grid.lastChild;
614 /******************************************************************************************************/
615 /* Loop through the field names */
617 for (var i = 0; i < g.right_pane_field_names.length; i++) {
619 var f = g.right_pane_field_names[i]; var fn = f[0];
622 /**************************************************************************************/
623 /* Loop through each value for the field */
625 for (var j in g.summary[fn]) {
626 var value = j; var count = g.summary[fn][j];
627 row = document.createElement('row'); rows.appendChild(row);
628 var label0 = document.createElement('label'); row.appendChild(label0);
629 label0.setAttribute('value',fn);
630 label0.setAttribute('style','font-weight: bold');
631 var label1 = document.createElement('label'); row.appendChild(label1);
632 if (g.special_exception[ fn ]) {
633 g.special_exception[ fn ]( label1, value );
635 label1.setAttribute('value',value);
640 /**************************************************************************************/
641 /* Render the input widget */
643 var hbox = document.createElement('hbox');
644 hbox.setAttribute('id',fn);
645 row.setAttribute('style','border-bottom: dotted black thin');
646 row.appendChild(hbox);
647 if (f[1].input && g.edit) {
648 g.render_input(hbox,f[1].input);
652 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
658 /******************************************************************************************************/
659 /* multi-copy mode has a groupbox for each field */
661 var groupbox; var caption; var vbox; var grid; var rows;
663 /******************************************************************************************************/
664 /* Loop through the field names */
666 for (var i = 0; i < g.right_pane_field_names.length; i++) {
668 var f = g.right_pane_field_names[i]; var fn = f[0];
669 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
670 caption = document.createElement('caption'); groupbox.appendChild(caption);
671 caption.setAttribute('label',fn);
672 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
673 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
674 grid.setAttribute('flex','1');
675 rows = grid.lastChild;
678 /**************************************************************************************/
679 /* Loop through each value for the field */
681 for (var j in g.summary[fn]) {
682 var value = j; var count = g.summary[fn][j];
683 row = document.createElement('row'); rows.appendChild(row);
684 var label1 = document.createElement('label'); row.appendChild(label1);
685 if (g.special_exception[ fn ]) {
686 g.special_exception[ fn ]( label1, value );
688 label1.setAttribute('value',value);
690 var label2 = document.createElement('label'); row.appendChild(label2);
691 var unit = count == 1 ? 'copy' : 'copies';
692 label2.setAttribute('value',count + ' ' + unit);
695 var hbox = document.createElement('hbox');
696 hbox.setAttribute('id',fn);
697 vbox.appendChild(hbox);
699 /**************************************************************************************/
700 /* Render the input widget */
702 if (f[1].input && g.edit) {
703 g.render_input(hbox,f[1].input);
706 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
712 /******************************************************************************************************/
713 /* This actually draws the change button and input widget for a given field */
714 g.render_input = function(node,input_cmd) {
716 var spacer = document.createElement('spacer'); node.appendChild(spacer);
717 spacer.setAttribute('flex','1');
718 var deck = document.createElement('deck'); node.appendChild(deck);
719 var btn = document.createElement('button'); deck.appendChild(btn);
720 deck.setAttribute('style','width: 200px; min-width: 200px;');
721 btn.setAttribute('label','Change');
722 btn.setAttribute('oncommand','this.parentNode.selectedIndex = 1;');
723 var x; eval( input_cmd );
724 if (x) deck.appendChild(x);
727 g.error.sdump('D_ERROR',E + '\n');
731 /******************************************************************************************************/
732 /* store the copies in the global xpcom stash */
734 g.stash_and_close = function() {
735 g.data.temp = js2JSON( g.copies );
736 g.error.sdump('D_CAT','in modal window, g.data.temp = \n' + g.data.temp + '\n');
737 g.data.stash('temp');