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 for (var j = 0; j < entries.length; j++) {
131 var sc_id = entries[j].stat_cat();
132 add_stat_cat( sc_id );
136 /******************************************************************************************************/
139 g.summarize( g.copies );
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)); }
150 /******************************************************************************************************/
151 /* Apply a value to a specific field on all the copies being edited */
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];
158 copy[field]( value ); copy.ischanged('1');
165 /******************************************************************************************************/
166 /* Apply a stat cat entry to all the copies being edited */
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];
174 var temp = copy.stat_cat_entries();
175 temp = util.functional.filter_list(
178 return (obj.id() != entry_id);
182 util.functional.find_id_object_in_list(
183 g.data.hash.asc[sc_id].entries(),
187 copy.stat_cat_entries( temp );
196 /******************************************************************************************************/
197 /* These need data from the middle layer to render */
199 g.special_exception = {
200 'Call Number' : function(label,value) {
201 if (value>0) { /* an existing call number */
203 api.FM_ACN_RETRIEVE.app,
204 api.FM_ACN_RETRIEVE.method,
207 var cn = '??? id = ' + value;
209 cn = req.getResultObject().label();
211 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
213 label.setAttribute('value',cn);
216 } else { /* a yet to be created call number */
218 label.setAttribute('value',g.callnumbers[value]);
222 'Creator' : function(label,value) {
224 api.FM_AU_RETRIEVE_VIA_ID.app,
225 api.FM_AU_RETRIEVE_VIA_ID.method,
226 [ g.session, value ],
228 var p = '??? id = ' + value;
230 p = req.getResultObject();
231 p = p.card().barcode() + ' : ' + p.family_name();
234 g.error.sdump('D_ERROR','patron retrieve: ' + E);
236 label.setAttribute('value',p);
240 'Last Editor' : function(label,value) {
242 api.FM_AU_RETRIEVE_VIA_ID.app,
243 api.FM_AU_RETRIEVE_VIA_ID.method,
244 [ g.session, value ],
246 var p = '??? id = ' + value;
248 p = req.getResultObject();
249 p = p.card().barcode() + ' : ' + p.family_name();
252 g.error.sdump('D_ERROR','patron retrieve: ' + E);
254 label.setAttribute('value',p);
261 /******************************************************************************************************/
262 g.readonly_stat_cat_names = [];
263 g.editable_stat_cat_names = [];
265 /******************************************************************************************************/
266 /* These get show in the left panel */
268 g.left_pane_field_names = [
272 render: 'fm.barcode();',
278 render: 'fm.call_number();',
284 render: 'util.date.formatted_date( fm.create_date(), "%F");',
290 render: 'util.date.formatted_date( fm.edit_date(), "%F");',
296 /******************************************************************************************************/
297 /* These get shown in the right panel */
299 g.right_pane_field_names = [
303 render: 'fm.creator();',
309 render: 'fm.editor();',
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);',
320 "Circulation Library",
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);',
327 "Circulation Modifier",
329 render: 'fm.circ_modifier();',
330 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_modifier",ev.target.value); }, false);',
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);',
343 render: 'fm.copy_number();',
344 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("copy_number",ev.target.value); }, false);',
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);',
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);',
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);',
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);',
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);',
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);',
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);',
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);',
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);',
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);',
423 /******************************************************************************************************/
424 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
426 g.summarize = function( copies ) {
427 /******************************************************************************************************/
430 JSAN.use('util.date'); JSAN.use('util.money');
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 );
437 /******************************************************************************************************/
438 /* Loop through the field names */
440 for (var i = 0; i < g.field_names.length; i++) {
442 var field_name = g.field_names[i][0];
443 var render = g.field_names[i][1].render;
444 g.summary[ field_name ] = {};
446 /******************************************************************************************************/
447 /* Loop through the copies */
449 for (var j = 0; j < copies.length; j++) {
452 var cmd = render || ('fm.' + field_name + '();');
455 /**********************************************************************************************/
456 /* Try to retrieve the value for this field for this copy */
461 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n');
463 if (typeof value == 'object' && value != null) {
464 alert('FIXME: field_name = ' + field_name + ' value = ' + js2JSON(value) + '\n');
467 /**********************************************************************************************/
468 /* Tally the count */
470 if (g.summary[ field_name ][ value ]) {
471 g.summary[ field_name ][ value ]++;
473 g.summary[ field_name ][ value ] = 1;
477 g.error.sdump('D_TRACE','summary = ' + js2JSON(g.summary) + '\n');
480 /******************************************************************************************************/
481 /* Display the summarized data and inputs for editing */
483 g.render = function() {
485 /******************************************************************************************************/
486 /* Library setup and clear any existing interface */
488 JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
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 );
497 /******************************************************************************************************/
498 /* Make the call number summary */
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);
512 /******************************************************************************************************/
513 /* List the copy barcodes */
515 for (var i in g.summary['Barcode']) {
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);
522 /******************************************************************************************************/
523 /* List the other non-editable fields in this pane */
525 var groupbox; var caption; var vbox; var grid; var rows;
526 for (var i = 0; i < g.left_pane_field_names.length; i++) {
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;
539 /**************************************************************************************/
540 /* Loop through each value for the field */
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 );
549 label1.setAttribute('value',value);
551 var label2 = document.createElement('label'); row.appendChild(label2);
552 var unit = count == 1 ? 'copy' : 'copies';
553 label2.setAttribute('value',count + ' ' + unit);
555 var hbox = document.createElement('hbox');
556 vbox.appendChild(hbox);
558 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
562 /******************************************************************************************************/
563 /* Prepare the right panel, which is different for 1-copy view and multi-copy view */
565 if (g.copies.length == 1) {
567 /******************************************************************************************************/
568 /* 1-copy mode has a single groupbox and each field is a row on a grid */
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;
579 /******************************************************************************************************/
580 /* Loop through the field names */
582 for (var i = 0; i < g.right_pane_field_names.length; i++) {
584 var f = g.right_pane_field_names[i]; var fn = f[0];
587 /**************************************************************************************/
588 /* Loop through each value for the field */
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 );
600 label1.setAttribute('value',value);
605 /**************************************************************************************/
606 /* Render the input widget */
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) {
613 var spacer = document.createElement('spacer'); hbox.appendChild(spacer);
614 spacer.setAttribute('flex','1');
615 var x; eval( f[1].input );
616 if (x) hbox.appendChild(x);
619 g.error.sdump('D_ERROR',E + '\n');
624 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
630 /******************************************************************************************************/
631 /* multi-copy mode has a groupbox for each field */
633 var groupbox; var caption; var vbox; var grid; var rows;
635 /******************************************************************************************************/
636 /* Loop through the field names */
638 for (var i = 0; i < g.right_pane_field_names.length; i++) {
640 var f = g.right_pane_field_names[i]; var fn = f[0];
641 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
642 caption = document.createElement('caption'); groupbox.appendChild(caption);
643 caption.setAttribute('label',fn);
644 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
645 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
646 grid.setAttribute('flex','1');
647 rows = grid.lastChild;
650 /**************************************************************************************/
651 /* Loop through each value for the field */
653 for (var j in g.summary[fn]) {
654 var value = j; var count = g.summary[fn][j];
655 row = document.createElement('row'); rows.appendChild(row);
656 var label1 = document.createElement('label'); row.appendChild(label1);
657 if (g.special_exception[ fn ]) {
658 g.special_exception[ fn ]( label1, value );
660 label1.setAttribute('value',value);
662 var label2 = document.createElement('label'); row.appendChild(label2);
663 var unit = count == 1 ? 'copy' : 'copies';
664 label2.setAttribute('value',count + ' ' + unit);
667 var hbox = document.createElement('hbox');
668 vbox.appendChild(hbox);
670 /**************************************************************************************/
671 /* Render the input widget */
673 if (f[1].input && g.edit) {
675 var spacer = document.createElement('spacer'); hbox.appendChild(spacer);
676 spacer.setAttribute('flex','1');
677 var x; eval( f[1].input );
678 if (x) hbox.appendChild(x);
681 g.error.sdump('D_ERROR',E + '\n');
685 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
691 /******************************************************************************************************/
692 /* store the copies in the global xpcom stash */
694 g.stash_and_close = function() {
695 g.data.temp = js2JSON( g.copies );
696 g.error.sdump('D_CAT','in modal window, g.data.temp = \n' + g.data.temp + '\n');
697 g.data.stash('temp');