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');
23 g.handle_update = g.cgi.param('handle_update');
25 /******************************************************************************************************/
26 /* Get the copy ids from various sources and flesh them */
29 if (g.cgi.param('copy_ids')) copy_ids = JSON2js( g.cgi.param('copy_ids') );
30 if (!copy_ids) copy_ids = [];
31 if (window.xulG && window.xulG.copy_ids) copy_ids = copy_ids.concat( window.xulG.copy_ids );
33 if (copy_ids.length > 0) g.copies = g.network.request(
34 api.FM_ACP_FLESHED_BATCH_RETRIEVE.app,
35 api.FM_ACP_FLESHED_BATCH_RETRIEVE.method,
39 /******************************************************************************************************/
40 /* And other fleshed copies if any */
42 if (!g.copies) g.copies = [];
43 if (window.xulG && window.xulG.copies) g.copies = g.copies.concat( window.xulG.copies );
44 if (g.cgi.param('copies')) g.copies = g.copies.concat( JSON2js( g.cgi.param('copies') ) );
46 /******************************************************************************************************/
47 /* We try to retrieve callnumbers for existing copies, but for new copies, we rely on this */
49 if (window.xulG && window.xulG.callnumbers) g.callnumbers = window.xulG.callnumbers;
50 if (g.cgi.param('callnumbers')) g.callnumbers = JSON2js( g.cgi.param('callnumbers') );
52 /******************************************************************************************************/
53 /* Is the interface an editor or a viewer, single or multi copy, existing copies or new copies? */
55 if (g.cgi.param('edit') == '1') {
57 document.getElementById('caption').setAttribute('label','Copy Editor');
58 document.getElementById('save').setAttribute('hidden','false');
61 if (g.cgi.param('single_edit') == '1') {
63 document.getElementById('caption').setAttribute('label','Copy Editor');
64 document.getElementById('save').setAttribute('hidden','false');
67 if (g.copies[0].id() < 0) {
68 document.getElementById('copy_notes').setAttribute('hidden','true');
69 g.apply("status",5 /* In Process */);
71 g.right_pane_field_names.push(
75 render: 'fm.status().name();',
76 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);',
82 if (g.copies.length != 1) {
83 document.getElementById('copy_notes').setAttribute('hidden','true');
86 /******************************************************************************************************/
87 /* Show the Record Details? */
90 document.getElementById('brief_display').setAttribute(
92 urls.XUL_BIB_BRIEF + '?docid=' + g.docid
95 document.getElementById('brief_display').setAttribute('hidden','true');
98 /******************************************************************************************************/
99 /* Add stat cats to the right_pane_field_names */
101 var stat_cat_seen = {};
103 function add_stat_cat(sc) {
105 if (typeof g.data.hash.asc == 'undefined') { g.data.hash.asc = {}; g.data.stash('hash'); }
109 if (typeof sc == 'object') {
114 if (typeof stat_cat_seen[sc_id] != 'undefined') { return; }
116 stat_cat_seen[ sc_id ] = 1;
118 if (typeof sc != 'object') {
120 sc = g.network.simple_request(
121 'FM_ASC_BATCH_RETRIEVE',
122 [ g.session, [ sc_id ] ]
127 g.data.hash.asc[ sc.id() ] = sc; g.data.stash('hash');
129 var label_name = g.data.hash.aou[ sc.owner() ].shortname() + " : " + sc.name();
134 render: 'var l = util.functional.find_list( fm.stat_cat_entries(), function(e){ return e.stat_cat() == '
135 + sc.id() + '; } ); l ? l.value() : null;',
136 input: 'x = util.widgets.make_menulist( util.functional.map_list( g.data.hash.asc[' + sc.id()
137 + '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ).sort() ); '
138 + 'x.addEventListener("command",function(ev) { g.apply_stat_cat(' + sc.id()
139 + ', ev.target.value); } ,false);',
143 dump('temp_array = ' + js2JSON(temp_array) + '\n');
145 g.right_pane_field_names.push( temp_array );
148 /* The stat cats for the pertinent library */
149 for (var i = 0; i < g.data.list.my_asc.length; i++) {
150 add_stat_cat( g.data.list.my_asc[i] );
153 /* Other stat cats present on these copies */
154 for (var i = 0; i < g.copies.length; i++) {
155 var entries = g.copies[i].stat_cat_entries();
156 if (!entries) entries = [];
157 for (var j = 0; j < entries.length; j++) {
158 var sc_id = entries[j].stat_cat();
159 add_stat_cat( sc_id );
163 /******************************************************************************************************/
166 g.summarize( g.copies );
170 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
171 "system administrator or software developer the following:\ncat/copy_editor.xul\n" + E + '\n';
172 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
177 /******************************************************************************************************/
178 /* Apply a value to a specific field on all the copies being edited */
180 g.apply = function(field,value) {
181 g.error.sdump('D_TRACE','field = ' + field + ' value = ' + value + '\n');
182 for (var i = 0; i < g.copies.length; i++) {
183 var copy = g.copies[i];
185 copy[field]( value ); copy.ischanged('1');
192 /******************************************************************************************************/
193 /* Apply a stat cat entry to all the copies being edited */
195 g.apply_stat_cat = function(sc_id,entry_id) {
196 g.error.sdump('D_TRACE','sc_id = ' + sc_id + ' entry_id = ' + entry_id + '\n');
197 for (var i = 0; i < g.copies.length; i++) {
198 var copy = g.copies[i];
201 var temp = copy.stat_cat_entries();
202 if (!temp) temp = [];
203 temp = util.functional.filter_list(
206 return (obj.stat_cat() != sc_id);
210 util.functional.find_id_object_in_list(
211 g.data.hash.asc[sc_id].entries(),
215 copy.stat_cat_entries( temp );
224 /******************************************************************************************************/
225 /* These need data from the middle layer to render */
227 g.special_exception = {
228 'Call Number' : function(label,value) {
229 if (value>0) { /* an existing call number */
231 api.FM_ACN_RETRIEVE.app,
232 api.FM_ACN_RETRIEVE.method,
235 var cn = '??? id = ' + value;
237 cn = req.getResultObject().label();
239 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
241 label.setAttribute('value',cn);
244 } else { /* a yet to be created call number */
246 label.setAttribute('value',g.callnumbers[value]);
250 'Creator' : function(label,value) {
251 if (value == null || value == '' || value == 'null') return;
252 g.network.simple_request(
253 'FM_AU_RETRIEVE_VIA_ID',
254 [ g.session, value ],
256 var p = '??? id = ' + value;
258 p = req.getResultObject();
259 p = p.usrname() + ' : ' + p.family_name() + ', ' + p.first_given_name();
262 g.error.sdump('D_ERROR','patron retrieve: ' + E);
264 label.setAttribute('value',p);
268 'Last Editor' : function(label,value) {
269 if (value == null || value == '' || value == 'null') return;
270 g.network.simple_request(
271 'FM_AU_RETRIEVE_VIA_ID',
272 [ g.session, value ],
274 var p = '??? id = ' + value;
276 p = req.getResultObject();
277 p = p.usrname() + ' : ' + p.family_name() + ', ' + p.first_given_name();
280 g.error.sdump('D_ERROR','patron retrieve: ' + E);
282 label.setAttribute('value',p);
289 /******************************************************************************************************/
290 g.readonly_stat_cat_names = [];
291 g.editable_stat_cat_names = [];
293 /******************************************************************************************************/
294 /* These get show in the left panel */
296 g.left_pane_field_names = [
300 render: 'fm.barcode();',
306 render: 'fm.call_number();',
312 render: 'util.date.formatted_date( fm.create_date(), "%F");',
318 render: 'util.date.formatted_date( fm.edit_date(), "%F");',
324 /******************************************************************************************************/
325 /* These get shown in the right panel */
327 g.right_pane_field_names = [
331 render: 'fm.creator();',
337 render: 'fm.editor();',
343 render: 'fm.alert_message();',
344 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("alert_message",ev.target.value); }, false);',
350 render: 'fm.circ_as_type();',
351 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_as_type",ev.target.value); }, false);',
355 "Circulation Library",
357 render: 'fm.circ_lib().shortname();',
358 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);',
362 "Circulation Modifier",
364 render: 'fm.circ_modifier();',
365 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_modifier",ev.target.value); }, false);',
371 render: 'fm.circulate() ? "Yes" : "No";',
372 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("circulate",ev.target.value); }, false);',
378 render: 'fm.copy_number();',
379 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("copy_number",ev.target.value); }, false);',
385 render: 'fm.deposit() ? "Yes" : "No";',
386 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("deposit",ev.target.value); }, false);',
392 render: 'util.money.sanitize( fm.deposit_amount() );',
393 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("deposit_amount",ev.target.value); }, false);',
399 render: 'switch(fm.fine_level()){ case 1: "Low"; break; case 2: "Normal"; break; case 3: "High"; break; }',
400 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);',
406 render: 'fm.holdable() ? "Yes" : "No";',
407 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("holdable",ev.target.value); }, false);',
413 render: 'switch(fm.loan_duration()){ case 1: "Short"; break; case 2: "Normal"; break; case 3: "Long"; break; }',
414 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);',
421 render: 'fm.location().name();',
422 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);',
429 render: 'fm.opac_visible() ? "Yes" : "No";',
430 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("opac_visible",ev.target.value); }, false);',
436 render: 'util.money.sanitize( fm.price() );',
437 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("deposit_amount",ev.target.value); }, false);',
443 render: 'fm.ref() ? "Yes" : "No";',
444 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("ref",ev.target.value); }, false);',
449 /******************************************************************************************************/
450 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
452 g.summarize = function( copies ) {
453 /******************************************************************************************************/
456 JSAN.use('util.date'); JSAN.use('util.money');
458 g.field_names = g.left_pane_field_names;
459 g.field_names = g.field_names.concat( g.right_pane_field_names );
460 g.field_names = g.field_names.concat( g.editable_stat_cat_names );
461 g.field_names = g.field_names.concat( g.readonly_stat_cat_names );
463 /******************************************************************************************************/
464 /* Loop through the field names */
466 for (var i = 0; i < g.field_names.length; i++) {
468 var field_name = g.field_names[i][0];
469 var render = g.field_names[i][1].render;
470 g.summary[ field_name ] = {};
472 /******************************************************************************************************/
473 /* Loop through the copies */
475 for (var j = 0; j < copies.length; j++) {
478 var cmd = render || ('fm.' + field_name + '();');
481 /**********************************************************************************************/
482 /* Try to retrieve the value for this field for this copy */
487 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n');
489 if (typeof value == 'object' && value != null) {
490 alert('FIXME: field_name = ' + field_name + ' value = ' + js2JSON(value) + '\n');
493 /**********************************************************************************************/
494 /* Tally the count */
496 if (g.summary[ field_name ][ value ]) {
497 g.summary[ field_name ][ value ]++;
499 g.summary[ field_name ][ value ] = 1;
503 g.error.sdump('D_TRACE','summary = ' + js2JSON(g.summary) + '\n');
506 /******************************************************************************************************/
507 /* Display the summarized data and inputs for editing */
509 g.render = function() {
511 /******************************************************************************************************/
512 /* Library setup and clear any existing interface */
514 JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
516 var cns = document.getElementById('call_number_summary');
517 util.widgets.remove_children( cns );
518 var bcs = document.getElementById('barcode_summary');
519 util.widgets.remove_children( bcs );
520 var rp = document.getElementById('right_pane');
521 util.widgets.remove_children( rp );
523 /******************************************************************************************************/
524 /* Make the call number summary */
526 var grid = util.widgets.make_grid( [ { 'flex' : '1' } ] );
527 cns.appendChild(grid);
528 for (var i in g.summary['Call Number']) {
529 var cn_id = i; var count = g.summary['Call Number'][i];
530 var row = document.createElement('row'); grid.lastChild.appendChild(row);
531 var cn_label = document.createElement('description'); row.appendChild(cn_label);
532 g.special_exception['Call Number']( cn_label, cn_id );
533 var count_label = document.createElement('description'); row.appendChild(count_label);
534 var unit = count == 1 ? 'copy' : 'copies';
535 count_label.appendChild( document.createTextNode(count + ' ' + unit) );
538 /******************************************************************************************************/
539 /* List the copy barcodes */
541 for (var i in g.summary['Barcode']) {
543 var hbox = document.createElement('hbox'); bcs.appendChild(hbox);
544 var bc_label = document.createElement('description'); hbox.appendChild(bc_label);
545 bc_label.appendChild( document.createTextNode(bc) );
548 /******************************************************************************************************/
549 /* List the other non-editable fields in this pane */
551 var groupbox; var caption; var vbox; var grid; var rows;
552 for (var i = 0; i < g.left_pane_field_names.length; i++) {
554 var f = g.left_pane_field_names[i]; var fn = f[0];
555 if (fn == 'Call Number' || fn == 'Barcode') continue;
556 groupbox = document.createElement('groupbox'); bcs.parentNode.parentNode.appendChild(groupbox);
557 caption = document.createElement('caption'); groupbox.appendChild(caption);
558 caption.setAttribute('label',fn);
559 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
560 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
561 grid.setAttribute('flex','1');
562 rows = grid.lastChild;
565 /**************************************************************************************/
566 /* Loop through each value for the field */
568 for (var j in g.summary[fn]) {
569 var value = j; var count = g.summary[fn][j];
570 row = document.createElement('row'); rows.appendChild(row);
571 var label1 = document.createElement('description'); row.appendChild(label1);
572 if (g.special_exception[ fn ]) {
573 g.special_exception[ fn ]( label1, value );
575 label1.appendChild( document.createTextNode(value) );
577 var label2 = document.createElement('description'); row.appendChild(label2);
578 var unit = count == 1 ? 'copy' : 'copies';
579 label2.appendChild( document.createTextNode(count + ' ' + unit) );
581 var hbox = document.createElement('hbox');
582 vbox.appendChild(hbox);
584 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
588 /******************************************************************************************************/
589 /* Prepare the right panel, which is different for 1-copy view and multi-copy view */
593 /******************************************************************************************************/
594 /* For a less dangerous batch edit, choose one field here */
596 var gb = document.createElement('groupbox'); rp.appendChild(gb);
597 var c = document.createElement('caption'); gb.appendChild(c);
598 c.setAttribute('label','Choose a field to edit');
599 JSAN.use('util.widgets'); JSAN.use('util.functional');
600 var ml = util.widgets.make_menulist(
601 util.functional.map_list(
602 g.right_pane_field_names,
603 function(o,i) { return [ o[0], i ]; }
610 g.render_input(gb, g.right_pane_field_names[ ev.target.value ][1].input);
618 if (g.copies.length == 1) {
620 /******************************************************************************************************/
621 /* 1-copy mode has a single groupbox and each field is a row on a grid */
623 var groupbox; var caption; var vbox; var grid; var rows;
624 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
625 caption = document.createElement('caption'); groupbox.appendChild(caption);
626 caption.setAttribute('label','Fields');
627 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
628 grid = util.widgets.make_grid( [ {}, { 'flex' : 1 } ] ); vbox.appendChild(grid);
629 grid.setAttribute('flex','1');
630 rows = grid.lastChild;
632 /******************************************************************************************************/
633 /* Loop through the field names */
635 for (var i = 0; i < g.right_pane_field_names.length; i++) {
637 var f = g.right_pane_field_names[i]; var fn = f[0];
640 /**************************************************************************************/
641 /* Loop through each value for the field */
643 for (var j in g.summary[fn]) {
644 var value = j; var count = g.summary[fn][j];
645 row = document.createElement('row'); rows.appendChild(row);
646 var label0 = document.createElement('description'); row.appendChild(label0);
647 label0.appendChild( document.createTextNode(fn) );
648 label0.setAttribute('style','font-weight: bold');
649 var label1 = document.createElement('description'); row.appendChild(label1);
650 if (g.special_exception[ fn ]) {
651 g.special_exception[ fn ]( label1, value );
653 label1.appendChild( document.createTextNode(value) );
658 /**************************************************************************************/
659 /* Render the input widget */
661 var hbox = document.createElement('hbox');
662 hbox.setAttribute('id',fn);
663 row.setAttribute('style','border-bottom: dotted black thin');
664 row.appendChild(hbox);
665 if (f[1].input && g.edit) {
666 g.render_input(hbox,f[1].input);
670 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
676 /******************************************************************************************************/
677 /* multi-copy mode has a groupbox for each field */
679 var groupbox; var caption; var vbox; var grid; var rows;
681 /******************************************************************************************************/
682 /* Loop through the field names */
684 for (var i = 0; i < g.right_pane_field_names.length; i++) {
686 var f = g.right_pane_field_names[i]; var fn = f[0];
687 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
688 caption = document.createElement('caption'); groupbox.appendChild(caption);
689 caption.setAttribute('label',fn);
690 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
691 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
692 grid.setAttribute('flex','1');
693 rows = grid.lastChild;
696 /**************************************************************************************/
697 /* Loop through each value for the field */
699 for (var j in g.summary[fn]) {
700 var value = j; var count = g.summary[fn][j];
701 row = document.createElement('row'); rows.appendChild(row);
702 var label1 = document.createElement('description'); row.appendChild(label1);
703 if (g.special_exception[ fn ]) {
704 g.special_exception[ fn ]( label1, value );
706 label1.appendChild( document.createTextNode(value) );
708 var label2 = document.createElement('description'); row.appendChild(label2);
709 var unit = count == 1 ? 'copy' : 'copies';
710 label2.appendChild( document.createTextNode(count + ' ' + unit) );
712 var hbox = document.createElement('hbox');
713 hbox.setAttribute('id',fn);
714 vbox.appendChild(hbox);
716 /**************************************************************************************/
717 /* Render the input widget */
719 if (f[1].input && g.edit) {
720 g.render_input(hbox,f[1].input);
723 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
729 /******************************************************************************************************/
730 /* This actually draws the change button and input widget for a given field */
731 g.render_input = function(node,input_cmd) {
733 var spacer = document.createElement('spacer'); node.appendChild(spacer);
734 spacer.setAttribute('flex','1');
735 var deck = document.createElement('deck'); node.appendChild(deck);
736 var btn = document.createElement('button'); deck.appendChild(btn);
737 deck.setAttribute('style','width: 200px; min-width: 200px;');
738 btn.setAttribute('label','Change');
739 btn.setAttribute('oncommand','this.parentNode.selectedIndex = 1;');
740 var x; eval( input_cmd );
741 if (x) deck.appendChild(x);
744 g.error.sdump('D_ERROR',E + '\n');
748 /******************************************************************************************************/
749 /* store the copies in the global xpcom stash */
751 g.stash_and_close = function() {
752 if (g.handle_update) {
754 var r = g.network.request(
755 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
756 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
757 [ g.session, g.copies ]
759 /* FIXME -- revisit the return value here */
761 alert('copy update error: ' + js2JSON(E));
764 g.data.temp = js2JSON( g.copies );
765 g.error.sdump('D_CAT','in modal window, g.data.temp = \n' + g.data.temp + '\n');
766 g.data.stash('temp');
770 /******************************************************************************************************/
771 /* spawn copy notes interface */
773 g.copy_notes = function() {
774 JSAN.use('util.window'); var win = new util.window();
775 win.open(urls.XUL_COPY_NOTES + '?copy_id=' + window.escape(g.copies[0].id()),'Copy Notes','chrome,resizable,modal');