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('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
16 JSAN.use('util.network'); g.network = new util.network();
20 g.session = g.cgi.param('session') || g.cgi.param('ses');
22 /******************************************************************************************************/
23 /* Get the copy ids from various sources */
26 if (g.cgi.param('copy_ids')) copy_ids = JSON2js( g.cgi.param('copy_ids') );
27 if (!copy_ids) copy_ids = [];
28 if (window.xulG && window.xulG.copy_ids) copy_ids = copy_ids.concat( window.xulG.copy_ids );
30 if (copy_ids.length > 0) g.copies = g.network.request(
31 api.FM_ACP_FLESHED_BATCH_RETRIEVE.app,
32 api.FM_ACP_FLESHED_BATCH_RETRIEVE.method,
36 /******************************************************************************************************/
37 /* And fleshed copies if any */
39 if (!g.copies) g.copies = [];
40 if (window.xulG && window.xulG.copies) g.copies = g.copies.concat( window.xulG.copies );
41 if (g.cgi.param('copies')) g.copies = g.copies.concat( JSON2js( g.cgi.param('copies') ) );
43 /******************************************************************************************************/
44 /* We try to retrieve callnumbers for existing copies, but for new copies, we rely on this */
46 if (window.xulG && window.xulG.callnumbers) g.callnumbers = window.xulG.callnumbers;
47 if (g.cgi.param('callnumbers')) g.callnumbers = JSON2js( g.cgi.param('callnumbers') );
49 /******************************************************************************************************/
50 /* Is the interface an editor or a viewer? */
52 if (g.cgi.param('edit') == '1') {
54 document.getElementById('caption').setAttribute('label','Copy Editor');
55 document.getElementById('nav').setAttribute('hidden','false');
58 /******************************************************************************************************/
61 g.summarize( g.copies );
65 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
66 "system administrator or software developer the following:\ncat/copy_editor.xul\n" + E + '\n';
67 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
72 /******************************************************************************************************/
73 /* Apply a value to a specific field on all the copies being edited */
75 g.apply = function(field,value) {
76 g.error.sdump('D_TRACE','field = ' + field + ' value = ' + value + '\n');
77 for (var i = 0; i < g.copies.length; i++) {
78 var copy = g.copies[i];
80 copy[field]( value ); copy.ischanged('1');
87 /******************************************************************************************************/
88 /* These need data from the middle layer to render */
90 g.special_exception = {
91 'Call Number' : function(label,value) {
92 if (value>0) { /* an existing call number */
94 api.FM_ACN_RETRIEVE.app,
95 api.FM_ACN_RETRIEVE.method,
98 var cn = '??? id = ' + value;
100 cn = req.getResultObject().label();
102 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
104 label.setAttribute('value',cn);
107 } else { /* a yet to be created call number */
109 label.setAttribute('value',g.callnumbers[value]);
113 'Creator' : function(label,value) {
115 api.FM_AU_RETRIEVE_VIA_ID.app,
116 api.FM_AU_RETRIEVE_VIA_ID.method,
117 [ g.session, value ],
119 var p = '??? id = ' + value;
121 p = req.getResultObject();
122 p = p.card().barcode() + ' : ' + p.family_name();
125 g.error.sdump('D_ERROR','patron retrieve: ' + E);
127 label.setAttribute('value',p);
131 'Last Editor' : function(label,value) {
133 api.FM_AU_RETRIEVE_VIA_ID.app,
134 api.FM_AU_RETRIEVE_VIA_ID.method,
135 [ g.session, value ],
137 var p = '??? id = ' + value;
139 p = req.getResultObject();
140 p = p.card().barcode() + ' : ' + p.family_name();
143 g.error.sdump('D_ERROR','patron retrieve: ' + E);
145 label.setAttribute('value',p);
152 /******************************************************************************************************/
153 g.readonly_stat_cat_names = [];
154 g.editable_stat_cat_names = [];
156 /******************************************************************************************************/
157 /* These get show in the left panel */
159 g.left_pane_field_names = [
163 render: 'fm.barcode();',
169 render: 'fm.call_number();',
175 render: 'util.date.formatted_date( fm.create_date(), "%F");',
181 render: 'util.date.formatted_date( fm.edit_date(), "%F");',
187 /******************************************************************************************************/
188 /* These get shown in the right panel */
190 g.right_pane_field_names = [
194 render: 'fm.creator();',
200 render: 'fm.editor();',
206 render: 'fm.circ_as_type();',
207 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_as_type",ev.target.value); }, false);',
211 "Circulation Library",
213 render: 'fm.circ_lib().shortname();',
214 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);',
218 "Circulation Modifier",
220 render: 'fm.circ_modifier();',
221 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("circ_modifier",ev.target.value); }, false);',
227 render: 'fm.circulate() ? "Yes" : "No";',
228 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("circulate",ev.target.value); }, false);',
234 render: 'fm.copy_number();',
235 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("copy_number",ev.target.value); }, false);',
241 render: 'fm.deposit() ? "Yes" : "No";',
242 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("deposit",ev.target.value); }, false);',
248 render: 'util.money.sanitize( fm.deposit_amount() );',
249 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("deposit_amount",ev.target.value); }, false);',
255 render: 'switch(fm.fine_level()){ case 1: "Low"; break; case 2: "Normal"; break; case 3: "High"; break; }',
256 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);',
262 render: 'fm.holdable() ? "Yes" : "No";',
263 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("holdable",ev.target.value); }, false);',
269 render: 'switch(fm.loan_duration()){ case 1: "Short"; break; case 2: "Normal"; break; case 3: "Long"; break; }',
270 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);',
277 render: 'fm.location().name();',
278 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);',
285 render: 'fm.opac_visible() ? "Yes" : "No";',
286 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("opac_visible",ev.target.value); }, false);',
292 render: 'util.money.sanitize( fm.price() );',
293 input: 'x = document.createElement("textbox"); x.addEventListener("change",function(ev) { g.apply("deposit_amount",ev.target.value); }, false);',
299 render: 'fm.ref() ? "Yes" : "No";',
300 input: 'x = util.widgets.make_menulist( [ [ "Yes", "1" ], [ "No", "0" ] ] ); x.addEventListener("command",function(ev) { g.apply("ref",ev.target.value); }, false);',
306 render: 'fm.status().name();',
307 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);',
314 /******************************************************************************************************/
315 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
317 g.summarize = function( copies ) {
318 /******************************************************************************************************/
321 JSAN.use('util.date'); JSAN.use('util.money');
323 g.field_names = g.left_pane_field_names;
324 g.field_names = g.field_names.concat( g.right_pane_field_names );
325 g.field_names = g.field_names.concat( g.editable_stat_cat_names );
326 g.field_names = g.field_names.concat( g.readonly_stat_cat_names );
328 /******************************************************************************************************/
329 /* Loop through the field names */
331 for (var i = 0; i < g.field_names.length; i++) {
333 var field_name = g.field_names[i][0];
334 var render = g.field_names[i][1].render;
335 g.summary[ field_name ] = {};
337 /******************************************************************************************************/
338 /* Loop through the copies */
340 for (var j = 0; j < copies.length; j++) {
343 var cmd = render || ('fm.' + field_name + '();');
346 /**********************************************************************************************/
347 /* Try to retrieve the value for this field for this copy */
352 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n');
354 if (typeof value == 'object' && value != null) {
355 alert('FIXME: field_name = ' + field_name + ' value = ' + js2JSON(value) + '\n');
358 /**********************************************************************************************/
359 /* Tally the count */
361 if (g.summary[ field_name ][ value ]) {
362 g.summary[ field_name ][ value ]++;
364 g.summary[ field_name ][ value ] = 1;
368 g.error.sdump('D_ERROR','summary = ' + js2JSON(g.summary) + '\n');
371 /******************************************************************************************************/
372 /* Display the summarized data and inputs for editing */
374 g.render = function() {
376 /******************************************************************************************************/
377 /* Library setup and clear any existing interface */
379 JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
381 var cns = document.getElementById('call_number_summary');
382 util.widgets.remove_children( cns );
383 var bcs = document.getElementById('barcode_summary');
384 util.widgets.remove_children( bcs );
385 var rp = document.getElementById('right_pane');
386 util.widgets.remove_children( rp );
388 /******************************************************************************************************/
389 /* Make the call number summary */
391 var grid = util.widgets.make_grid( [ { 'flex' : '1' } ] );
392 cns.appendChild(grid);
393 for (var i in g.summary['Call Number']) {
394 var cn_id = i; var count = g.summary['Call Number'][i];
395 var row = document.createElement('row'); grid.lastChild.appendChild(row);
396 var cn_label = document.createElement('label'); row.appendChild(cn_label);
397 g.special_exception['Call Number']( cn_label, cn_id );
398 var count_label = document.createElement('label'); row.appendChild(count_label);
399 var unit = count == 1 ? 'copy' : 'copies';
400 count_label.setAttribute('value',count + ' ' + unit);
403 /******************************************************************************************************/
404 /* List the copy barcodes */
406 for (var i in g.summary['Barcode']) {
408 var hbox = document.createElement('hbox'); bcs.appendChild(hbox);
409 var bc_label = document.createElement('label'); hbox.appendChild(bc_label);
410 bc_label.setAttribute('value',bc);
413 /******************************************************************************************************/
414 /* List the other non-editable fields in this pane */
416 var groupbox; var caption; var vbox; var grid; var rows;
417 for (var i = 0; i < g.left_pane_field_names.length; i++) {
419 var f = g.left_pane_field_names[i]; var fn = f[0];
420 if (fn == 'Call Number' || fn == 'Barcode') continue;
421 groupbox = document.createElement('groupbox'); bcs.parentNode.parentNode.appendChild(groupbox);
422 caption = document.createElement('caption'); groupbox.appendChild(caption);
423 caption.setAttribute('label',fn);
424 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
425 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
426 grid.setAttribute('flex','1');
427 rows = grid.lastChild;
430 /**************************************************************************************/
431 /* Loop through each value for the field */
433 for (var j in g.summary[fn]) {
434 var value = j; var count = g.summary[fn][j];
435 row = document.createElement('row'); rows.appendChild(row);
436 var label1 = document.createElement('label'); row.appendChild(label1);
437 if (g.special_exception[ fn ]) {
438 g.special_exception[ fn ]( label1, value );
440 label1.setAttribute('value',value);
442 var label2 = document.createElement('label'); row.appendChild(label2);
443 var unit = count == 1 ? 'copy' : 'copies';
444 label2.setAttribute('value',count + ' ' + unit);
446 var hbox = document.createElement('hbox');
447 vbox.appendChild(hbox);
449 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
453 /******************************************************************************************************/
454 /* Prepare the right panel, which is different for 1-copy view and multi-copy view */
456 if (g.copies.length == 1) {
458 /******************************************************************************************************/
459 /* 1-copy mode has a single groupbox and each field is a row on a grid */
461 var groupbox; var caption; var vbox; var grid; var rows;
462 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
463 caption = document.createElement('caption'); groupbox.appendChild(caption);
464 caption.setAttribute('label','Fields');
465 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
466 grid = util.widgets.make_grid( [ {}, { 'flex' : 1 } ] ); vbox.appendChild(grid);
467 grid.setAttribute('flex','1');
468 rows = grid.lastChild;
470 /******************************************************************************************************/
471 /* Loop through the field names */
473 for (var i = 0; i < g.right_pane_field_names.length; i++) {
475 var f = g.right_pane_field_names[i]; var fn = f[0];
478 /**************************************************************************************/
479 /* Loop through each value for the field */
481 for (var j in g.summary[fn]) {
482 var value = j; var count = g.summary[fn][j];
483 row = document.createElement('row'); rows.appendChild(row);
484 var label0 = document.createElement('label'); row.appendChild(label0);
485 label0.setAttribute('value',fn);
486 label0.setAttribute('style','font-weight: bold');
487 var label1 = document.createElement('label'); row.appendChild(label1);
488 if (g.special_exception[ fn ]) {
489 g.special_exception[ fn ]( label1, value );
491 label1.setAttribute('value',value);
496 /**************************************************************************************/
497 /* Render the input widget */
499 var hbox = document.createElement('hbox');
500 row.setAttribute('style','border-bottom: dotted black thin');
501 row.appendChild(hbox);
502 if (f[1].input && g.edit) {
504 var spacer = document.createElement('spacer'); hbox.appendChild(spacer);
505 spacer.setAttribute('flex','1');
506 var x; eval( f[1].input );
507 if (x) hbox.appendChild(x);
510 g.error.sdump('D_ERROR',E + '\n');
515 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
521 /******************************************************************************************************/
522 /* multi-copy mode has a groupbox for each field */
524 var groupbox; var caption; var vbox; var grid; var rows;
526 /******************************************************************************************************/
527 /* Loop through the field names */
529 for (var i = 0; i < g.right_pane_field_names.length; i++) {
531 var f = g.right_pane_field_names[i]; var fn = f[0];
532 groupbox = document.createElement('groupbox'); rp.appendChild(groupbox);
533 caption = document.createElement('caption'); groupbox.appendChild(caption);
534 caption.setAttribute('label',fn);
535 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
536 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
537 grid.setAttribute('flex','1');
538 rows = grid.lastChild;
541 /**************************************************************************************/
542 /* Loop through each value for the field */
544 for (var j in g.summary[fn]) {
545 var value = j; var count = g.summary[fn][j];
546 row = document.createElement('row'); rows.appendChild(row);
547 var label1 = document.createElement('label'); row.appendChild(label1);
548 if (g.special_exception[ fn ]) {
549 g.special_exception[ fn ]( label1, value );
551 label1.setAttribute('value',value);
553 var label2 = document.createElement('label'); row.appendChild(label2);
554 var unit = count == 1 ? 'copy' : 'copies';
555 label2.setAttribute('value',count + ' ' + unit);
558 var hbox = document.createElement('hbox');
559 vbox.appendChild(hbox);
561 /**************************************************************************************/
562 /* Render the input widget */
564 if (f[1].input && g.edit) {
566 var spacer = document.createElement('spacer'); hbox.appendChild(spacer);
567 spacer.setAttribute('flex','1');
568 var x; eval( f[1].input );
569 if (x) hbox.appendChild(x);
572 g.error.sdump('D_ERROR',E + '\n');
576 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
582 /******************************************************************************************************/
583 /* store the copies in the global xpcom stash */
585 g.stash_and_close = function() {
586 g.data.temp = js2JSON( g.copies );
587 g.error.sdump('D_CAT','in modal window, g.data.temp = \n' + g.data.temp + '\n');
588 g.data.stash('temp');