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.docid = g.cgi.param('docid');
22 g.handle_update = g.cgi.param('handle_update');
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, single or multi copy, existing copies or new copies? */
54 if (g.cgi.param('edit') == '1') {
56 document.getElementById('caption').setAttribute('label','Copy Editor');
57 document.getElementById('save').setAttribute('hidden','false');
60 if (g.cgi.param('single_edit') == '1') {
62 document.getElementById('caption').setAttribute('label','Copy Editor');
63 document.getElementById('save').setAttribute('hidden','false');
66 if (g.copies.length > 0 && g.copies[0].id() < 0) {
67 document.getElementById('copy_notes').setAttribute('hidden','true');
68 g.apply("status",5 /* In Process */);
70 g.panes_and_field_names.left_pane =
75 render: 'typeof fm.status() == "object" ? fm.status().name() : g.data.hash.ccs[ fm.status() ].name()',
76 input: 'c = function(v){ g.apply("status",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( util.functional.map_list( g.data.list.ccs, function(obj) { return [ obj.name(), obj.id() ]; } ).sort() ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
79 ].concat(g.panes_and_field_names.left_pane);
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 panes_and_field_names.right_pane4 */
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',
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() : "<Unset>";',
136 input: 'c = function(v){ g.apply_stat_cat(' + sc.id() + ',v); if (typeof post_c == "function") post_c(v); }; 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("apply",function(f){ return function(ev) { f(ev.target.value); } }(c),false);',
142 dump('temp_array = ' + js2JSON(temp_array) + '\n');
144 g.panes_and_field_names.right_pane4.push( temp_array );
147 /* The stat cats for the pertinent library */
148 for (var i = 0; i < g.data.list.my_asc.length; i++) {
149 add_stat_cat( g.data.list.my_asc[i] );
152 /* Other stat cats present on these copies */
153 for (var i = 0; i < g.copies.length; i++) {
154 var entries = g.copies[i].stat_cat_entries();
155 if (!entries) entries = [];
156 for (var j = 0; j < entries.length; j++) {
157 var sc_id = entries[j].stat_cat();
158 add_stat_cat( sc_id );
162 /******************************************************************************************************/
165 g.summarize( g.copies );
169 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
170 "system administrator or software developer the following:\ncat/copy_editor.xul\n" + E + '\n';
171 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
176 /******************************************************************************************************/
177 /* Apply a value to a specific field on all the copies being edited */
179 g.apply = function(field,value) {
180 g.error.sdump('D_TRACE','field = ' + field + ' value = ' + value + '\n');
181 for (var i = 0; i < g.copies.length; i++) {
182 var copy = g.copies[i];
184 copy[field]( value ); copy.ischanged('1');
191 /******************************************************************************************************/
192 /* Apply a stat cat entry to all the copies being edited */
194 g.apply_stat_cat = function(sc_id,entry_id) {
195 g.error.sdump('D_TRACE','sc_id = ' + sc_id + ' entry_id = ' + entry_id + '\n');
196 for (var i = 0; i < g.copies.length; i++) {
197 var copy = g.copies[i];
200 var temp = copy.stat_cat_entries();
201 if (!temp) temp = [];
202 temp = util.functional.filter_list(
205 return (obj.stat_cat() != sc_id);
209 util.functional.find_id_object_in_list(
210 g.data.hash.asc[sc_id].entries(),
214 copy.stat_cat_entries( temp );
222 /******************************************************************************************************/
223 /* This keeps track of what fields have been edited for styling purposes */
227 /******************************************************************************************************/
228 /* These need data from the middle layer to render */
230 g.special_exception = {
231 'Call Number' : function(label,value) {
232 if (value>0) { /* an existing call number */
234 api.FM_ACN_RETRIEVE.app,
235 api.FM_ACN_RETRIEVE.method,
238 var cn = '??? id = ' + value;
240 cn = req.getResultObject().label();
242 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
244 label.setAttribute('value',cn);
247 } else { /* a yet to be created call number */
249 label.setAttribute('value',g.callnumbers[value]);
253 'Creator' : function(label,value) {
254 if (value == null || value == '' || value == 'null') return;
255 g.network.simple_request(
256 'FM_AU_RETRIEVE_VIA_ID',
259 var p = '??? id = ' + value;
261 p = req.getResultObject();
265 g.error.sdump('D_ERROR','patron retrieve: ' + E);
267 label.setAttribute('value',p);
271 'Last Editor' : function(label,value) {
272 if (value == null || value == '' || value == 'null') return;
273 g.network.simple_request(
274 'FM_AU_RETRIEVE_VIA_ID',
277 var p = '??? id = ' + value;
279 p = req.getResultObject();
283 g.error.sdump('D_ERROR','patron retrieve: ' + E);
285 label.setAttribute('value',p);
292 /******************************************************************************************************/
293 g.readonly_stat_cat_names = [];
294 g.editable_stat_cat_names = [];
296 /******************************************************************************************************/
297 /* These get show in the left panel */
299 g.panes_and_field_names = {
306 render: 'fm.barcode();',
312 render: 'util.date.formatted_date( fm.create_date(), "%F");',
318 render: 'fm.creator();',
324 render: 'util.date.formatted_date( fm.edit_date(), "%F");',
330 render: 'fm.editor();',
341 render: 'typeof fm.location() == "object" ? fm.location().name() : g.data.hash.acpl[ fm.location() ].name()',
342 input: 'c = function(v){ g.apply("location",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( util.functional.map_list( g.data.list.acpl, function(obj) { return [ obj.name(), obj.id() ]; }).sort()); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
347 "Circulation Library",
349 render: 'typeof fm.circ_lib() == "object" ? fm.circ_lib().shortname() : g.data.hash.aou[ fm.circ_lib() ].shortname()',
350 input: 'c = function(v){ g.apply("circ_lib",v); if (typeof post_c == "function") post_c(v); }; 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("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
356 render: 'fm.call_number();',
362 render: 'fm.copy_number() == null ? "<Unset>" : fm.copy_number()',
363 input: 'c = function(v){ g.apply("copy_number",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
375 render: 'fm.circulate() == null ? "<Unset>" : ( fm.circulate() == 1 ? "Yes" : "No" )',
376 input: 'c = function(v){ g.apply("circulate",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
382 render: 'fm.holdable() == null ? "<Unset>" : ( fm.holdable() == 1? "Yes" : "No" )',
383 input: 'c = function(v){ g.apply("holdable",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
390 render: 'switch(fm.loan_duration()){ case 1: case "1": "Short"; break; case 2: case "2": "Normal"; break; case 3:case "3": "Long"; break; }',
391 input: 'c = function(v){ g.apply("loan_duration",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Short", "1" ], [ "Normal", "2" ], [ "Long", "3" ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
398 render: 'switch(fm.fine_level()){ case 1: case "1": "Low"; break; case 2: case "2": "Normal"; break; case 3: case "3": "High"; break; }',
399 input: 'c = function(v){ g.apply("fine_level",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Low", "1" ], [ "Normal", "2" ], [ "High", "3" ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
406 render: 'fm.circ_as_type() == null ? "<Unset>" : fm.circ_as_type()',
407 input: 'c = function(v){ g.apply("circ_as_type",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
411 "Circulation Modifier",
413 render: 'fm.circ_modifier() == null ? "<Unset>" : fm.circ_modifier()',
414 input: 'c = function(v){ g.apply("circ_modifier",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
423 render: 'fm.alert_message() == null ? "<Unset>" : fm.alert_message()',
424 input: 'c = function(v){ g.apply("alert_message",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
431 render: 'fm.deposit() == null ? "<Unset>" : ( fm.deposit() == 1 ? "Yes" : "No" )',
432 input: 'c = function(v){ g.apply("deposit",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
438 render: 'util.money.sanitize( fm.deposit_amount() );',
439 input: 'c = function(v){ g.apply("deposit_amount",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
445 render: 'util.money.sanitize( fm.price() );',
446 input: 'c = function(v){ g.apply("price",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
453 render: 'fm.opac_visible() == null ? "<Unset>" : ( fm.opac_visible() == 1 ? "Yes" : "No" )',
454 input: 'c = function(v){ g.apply("opac_visible",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
460 render: 'fm.ref() == null ? "<Unset>" : ( fm.ref() == 1 ? "Yes" : "No" )',
461 input: 'c = function(v){ g.apply("ref",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
472 /******************************************************************************************************/
473 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
475 g.summarize = function( copies ) {
476 /******************************************************************************************************/
479 JSAN.use('util.date'); JSAN.use('util.money');
482 for (var i in g.panes_and_field_names) {
483 g.field_names = g.field_names.concat( g.panes_and_field_names[i] );
485 g.field_names = g.field_names.concat( g.editable_stat_cat_names );
486 g.field_names = g.field_names.concat( g.readonly_stat_cat_names );
488 /******************************************************************************************************/
489 /* Loop through the field names */
491 for (var i = 0; i < g.field_names.length; i++) {
493 var field_name = g.field_names[i][0];
494 var render = g.field_names[i][1].render;
495 g.summary[ field_name ] = {};
497 /******************************************************************************************************/
498 /* Loop through the copies */
500 for (var j = 0; j < copies.length; j++) {
503 var cmd = render || ('fm.' + field_name + '();');
506 /**********************************************************************************************/
507 /* Try to retrieve the value for this field for this copy */
512 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n');
514 if (typeof value == 'object' && value != null) {
515 alert('FIXME: field_name = ' + field_name + ' value = ' + js2JSON(value) + '\n');
518 /**********************************************************************************************/
519 /* Tally the count */
521 if (g.summary[ field_name ][ value ]) {
522 g.summary[ field_name ][ value ]++;
524 g.summary[ field_name ][ value ] = 1;
528 g.error.sdump('D_TRACE','summary = ' + js2JSON(g.summary) + '\n');
531 /******************************************************************************************************/
532 /* Display the summarized data and inputs for editing */
534 g.render = function() {
536 /******************************************************************************************************/
537 /* Library setup and clear any existing interface */
539 JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
541 for (var i in g.panes_and_field_names) {
542 var p = document.getElementById(i);
543 if (p) util.widgets.remove_children(p);
546 /******************************************************************************************************/
547 /* Prepare the panes */
549 var groupbox; var caption; var vbox; var grid; var rows;
551 /******************************************************************************************************/
552 /* Loop through the field names */
554 for (h in g.panes_and_field_names) {
555 if (!document.getElementById(h)) continue;
556 for (var i = 0; i < g.panes_and_field_names[h].length; i++) {
558 var f = g.panes_and_field_names[h][i]; var fn = f[0];
559 groupbox = document.createElement('groupbox'); document.getElementById(h).appendChild(groupbox);
560 if (typeof g.changed[fn] != 'undefined') groupbox.setAttribute('class',g.changed[fn]);
561 caption = document.createElement('caption'); groupbox.appendChild(caption);
562 caption.setAttribute('label',fn);
563 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
564 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
565 grid.setAttribute('flex','1');
566 rows = grid.lastChild;
569 /**************************************************************************************/
570 /* Loop through each value for the field */
572 for (var j in g.summary[fn]) {
573 var value = j; var count = g.summary[fn][j];
574 row = document.createElement('row'); rows.appendChild(row);
575 var label1 = document.createElement('description'); row.appendChild(label1);
576 if (g.special_exception[ fn ]) {
577 g.special_exception[ fn ]( label1, value );
579 label1.appendChild( document.createTextNode(value) );
581 var label2 = document.createElement('description'); row.appendChild(label2);
582 var unit = count == 1 ? 'copy' : 'copies';
583 label2.appendChild( document.createTextNode(count + ' ' + unit) );
585 var hbox = document.createElement('hbox');
586 hbox.setAttribute('id',fn);
587 groupbox.appendChild(hbox);
588 var hbox2 = document.createElement('hbox');
589 groupbox.appendChild(hbox2);
591 /**************************************************************************************/
592 /* Render the input widget */
594 if (f[1].input && g.edit) {
595 g.render_input(hbox,f[1]);
599 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
605 /******************************************************************************************************/
606 /* This actually draws the change button and input widget for a given field */
607 g.render_input = function(node,blob) {
609 // node = hbox ; groupbox -> hbox, hbox
611 var groupbox = node.parentNode;
612 var vbox = node.previousSibling;
614 var hbox2 = node.nextSibling;
616 var input_cmd = blob.input;
617 var render_cmd = blob.render;
619 var block = false; var first = true;
621 function on_mouseover(ev) {
622 groupbox.setAttribute('style','background: white');
625 function on_mouseout(ev) {
626 groupbox.setAttribute('style','');
629 vbox.addEventListener('mouseover',on_mouseover,false);
630 vbox.addEventListener('mouseout',on_mouseout,false);
631 groupbox.addEventListener('mouseover',on_mouseover,false);
632 groupbox.addEventListener('mouseout',on_mouseout,false);
633 groupbox.firstChild.addEventListener('mouseover',on_mouseover,false);
634 groupbox.firstChild.addEventListener('mouseout',on_mouseout,false);
636 function on_click(ev){
638 if (block) return; block = true;
641 g.changed[ hbox.id ] = 'copy_editor_field_changed';
645 g.summarize( g.copies );
650 var x; var c; eval( input_cmd );
652 util.widgets.remove_children(vbox);
653 util.widgets.remove_children(hbox);
654 util.widgets.remove_children(hbox2);
656 var apply = document.createElement('button');
657 apply.setAttribute('label','Apply');
658 apply.setAttribute('accesskey','A');
659 hbox2.appendChild(apply);
660 apply.addEventListener('command',function() { c(x.value); },false);
661 var cancel = document.createElement('button');
662 cancel.setAttribute('label','Cancel');
663 cancel.addEventListener('command',function() { setTimeout( function() { g.summarize( g.copies ); g.render(); }, 0); }, false);
664 hbox2.appendChild(cancel);
665 setTimeout( function() { x.focus(); }, 0 );
668 g.error.standard_unexpected_error_alert('render_input',E);
671 vbox.addEventListener('click',on_click, false);
672 hbox.addEventListener('click',on_click, false);
673 groupbox.firstChild.addEventListener('click',on_click, false);
676 g.error.sdump('D_ERROR',E + '\n');
680 /******************************************************************************************************/
681 /* store the copies in the global xpcom stash */
683 g.stash_and_close = function() {
684 if (g.handle_update) {
686 var r = g.network.request(
687 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
688 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
691 if (typeof r.ilsevent != 'undefined') {
692 g.error.standard_unexpected_error_alert('copy update',r);
694 /* FIXME -- revisit the return value here */
696 alert('copy update error: ' + js2JSON(E));
699 g.data.temp_copies = js2JSON( g.copies );
700 g.data.stash('temp_copies');
701 g.error.sdump('D_CAT','in modal window, g.data.temp_copies = \n' + g.data.temp_copies + '\n');
705 /******************************************************************************************************/
706 /* spawn copy notes interface */
708 g.copy_notes = function() {
709 JSAN.use('util.window'); var win = new util.window();
710 win.open(urls.XUL_COPY_NOTES + '?copy_id=' + window.escape(g.copies[0].id()),'Copy Notes','chrome,resizable,modal');