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 (window.xulG && window.xulG.copy_ids) copy_ids = copy_ids.concat( window.xulG.copy_ids );
30 if (typeof g.data.temp_copy_ids != 'undefined' && g.data.temp_copy_ids != null) copy_ids = copy_ids.concat( JSON2js( g.data.temp_copy_ids ) );
31 if (!copy_ids) 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') ) );
45 if (g.data.temp_copies != 'undefined' && g.data.temp_copies) g.copies = g.copies.concat( JSON2js( g.data.temp_copies ) );
47 /******************************************************************************************************/
48 /* We try to retrieve callnumbers for existing copies, but for new copies, we rely on this */
50 if (window.xulG && window.xulG.callnumbers) g.callnumbers = window.xulG.callnumbers;
51 if (g.cgi.param('callnumbers')) g.callnumbers = JSON2js( g.cgi.param('callnumbers') );
52 if (g.data.temp_callnumbers != 'undefined') g.callnumbers = JSON2js( g.data.temp_callnumbers );
54 /******************************************************************************************************/
55 /* Is the interface an editor or a viewer, single or multi copy, existing copies or new copies? */
57 if (g.cgi.param('edit') == '1') {
59 document.getElementById('caption').setAttribute('label','Copy Editor');
60 document.getElementById('save').setAttribute('hidden','false');
61 g.retrieve_templates();
63 $('top_nav').setAttribute('hidden','true');
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 */);
69 $('save').setAttribute('label','Create Copies');
71 g.panes_and_field_names.left_pane =
76 render: 'typeof fm.status() == "object" ? fm.status().name() : g.data.hash.ccs[ fm.status() ].name()',
77 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);',
80 ].concat(g.panes_and_field_names.left_pane);
83 if (g.copies.length != 1) {
84 document.getElementById('copy_notes').setAttribute('hidden','true');
87 /******************************************************************************************************/
88 /* Show the Record Details? */
91 document.getElementById('brief_display').setAttribute(
93 urls.XUL_BIB_BRIEF + '?docid=' + g.docid
96 document.getElementById('brief_display').setAttribute('hidden','true');
99 /******************************************************************************************************/
100 /* Add stat cats to the panes_and_field_names.right_pane4 */
102 var stat_cat_seen = {};
104 function add_stat_cat(sc) {
106 if (typeof g.data.hash.asc == 'undefined') { g.data.hash.asc = {}; g.data.stash('hash'); }
110 if (typeof sc == 'object') {
115 if (typeof stat_cat_seen[sc_id] != 'undefined') { return; }
117 stat_cat_seen[ sc_id ] = 1;
119 if (typeof sc != 'object') {
121 sc = g.network.simple_request(
122 'FM_ASC_BATCH_RETRIEVE',
128 g.data.hash.asc[ sc.id() ] = sc; g.data.stash('hash');
130 var label_name = g.data.hash.aou[ sc.owner() ].shortname() + " : " + sc.name();
135 render: 'var l = util.functional.find_list( fm.stat_cat_entries(), function(e){ return e.stat_cat() == '
136 + sc.id() + '; } ); l ? l.value() : "<Unset>";',
137 input: 'c = function(v){ g.apply_stat_cat(' + sc.id() + ',v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "<Remove Stat Cat>", -1 ] ].concat( util.functional.map_list( g.data.hash.asc[' + sc.id()
138 + '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ) ).sort() ); '
139 //input: 'c = function(v){ g.apply_stat_cat(' + sc.id() + ',v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "<Remove Stat Cat>", null ] ].concat( util.functional.map_list( g.data.hash.asc[' + sc.id()
140 // + '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ).sort() ) ); '
141 + 'x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c),false);',
145 dump('temp_array = ' + js2JSON(temp_array) + '\n');
147 g.panes_and_field_names.right_pane4.push( temp_array );
150 /* The stat cats for the pertinent library */
151 for (var i = 0; i < g.data.list.my_asc.length; i++) {
152 add_stat_cat( g.data.list.my_asc[i] );
155 /* Other stat cats present on these copies */
156 for (var i = 0; i < g.copies.length; i++) {
157 var entries = g.copies[i].stat_cat_entries();
158 if (!entries) entries = [];
159 for (var j = 0; j < entries.length; j++) {
160 var sc_id = entries[j].stat_cat();
161 add_stat_cat( sc_id );
165 /******************************************************************************************************/
166 /* Backup copies :) */
168 g.original_copies = js2JSON( g.copies );
170 /******************************************************************************************************/
173 g.summarize( g.copies );
177 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
178 "system administrator or software developer the following:\ncat/copy_editor.xul\n" + E + '\n';
179 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
184 /******************************************************************************************************/
185 /* Retrieve Templates */
187 g.retrieve_templates = function() {
189 JSAN.use('util.widgets'); JSAN.use('util.functional');
191 var robj = g.network.simple_request('FM_AUS_RETRIEVE',[ses(),g.data.list.au[0].id()]);
192 if (typeof robj['staff_client.copy_editor.templates'] != 'undefined') {
193 g.templates = robj['staff_client.copy_editor.templates'];
195 util.widgets.remove_children('template_placeholder');
196 var list = util.functional.map_object_to_list( g.templates, function(obj,i) { return [i, i]; } );
198 g.template_menu = util.widgets.make_menulist( list );
199 $('template_placeholder').appendChild(g.template_menu);
201 g.error.standard_unexpected_error_alert('Error retrieving templates',E);
205 /******************************************************************************************************/
208 g.apply_template = function() {
210 var name = g.template_menu.value;
211 if (g.templates[ name ] != 'undefined') {
212 var template = g.templates[ name ];
213 for (var i in template) {
214 g.changed[ i ] = template[ i ];
215 switch( template[i].type ) {
217 g.apply(template[i].field,template[i].value);
220 g.apply_stat_cat(template[i].field,template[i].value);
224 g.summarize( g.copies );
228 g.error.standard_unexpected_error_alert('Error applying template',E);
232 /******************************************************************************************************/
233 /* Save as Template */
235 g.save_template = function() {
237 var name = window.prompt('Enter template name:','','Save As Template');
239 g.templates[name] = g.changed;
240 var robj = g.network.simple_request(
241 'FM_AUS_UPDATE',[ses(),g.data.list.au[0].id(), { 'staff_client.copy_editor.templates' : g.templates }]
243 if (typeof robj.ilsevent != 'undefined') {
246 alert('Template "' + name + '" saved.');
250 g.retrieve_templates();
252 g.error.standard_unexpected_error_alert('Error saving template',E);
258 g.error.standard_unexpected_error_alert('Error saving template',E);
262 /******************************************************************************************************/
263 /* Delete Template */
265 g.delete_template = function() {
267 var name = g.template_menu.value;
269 if (! window.confirm('Delete template "' + name + '"?') ) return;
270 delete(g.templates[name]);
271 var robj = g.network.simple_request(
272 'FM_AUS_UPDATE',[ses(),g.data.list.au[0].id(), { 'staff_client.copy_editor.templates' : g.templates }]
274 if (typeof robj.ilsevent != 'undefined') {
277 alert('Template "' + name + '" deleted.');
281 g.retrieve_templates();
283 g.error.standard_unexpected_error_alert('Error deleting template',E);
289 g.error.standard_unexpected_error_alert('Error deleting template',E);
293 /******************************************************************************************************/
294 /* Restore backup copies */
296 g.reset = function() {
298 g.copies = JSON2js( g.original_copies );
299 g.summarize( g.copies );
303 /******************************************************************************************************/
304 /* Apply a value to a specific field on all the copies being edited */
306 g.apply = function(field,value) {
307 g.error.sdump('D_TRACE','applying field = <' + field + '> value = <' + value + '>\n');
308 if (value == '<HACK:KLUDGE:NULL>') value = null;
309 for (var i = 0; i < g.copies.length; i++) {
310 var copy = g.copies[i];
312 copy[field]( value ); copy.ischanged('1');
319 /******************************************************************************************************/
320 /* Apply a stat cat entry to all the copies being edited. An entry_id of < 0 signifies the stat cat is being removed. */
322 g.apply_stat_cat = function(sc_id,entry_id) {
323 g.error.sdump('D_TRACE','sc_id = ' + sc_id + ' entry_id = ' + entry_id + '\n');
324 for (var i = 0; i < g.copies.length; i++) {
325 var copy = g.copies[i];
328 var temp = copy.stat_cat_entries();
329 if (!temp) temp = [];
330 temp = util.functional.filter_list(
333 return (obj.stat_cat() != sc_id);
336 if (entry_id > -1) temp.push(
337 util.functional.find_id_object_in_list(
338 g.data.hash.asc[sc_id].entries(),
342 copy.stat_cat_entries( temp );
345 g.error.standard_unexpected_error_alert('apply_stat_cat',E);
350 /******************************************************************************************************/
351 /* This concats and uniques all the alert messages for use as the default value for a new alert message */
353 g.populate_alert_message_input = function(tb) {
355 var seen = {}; var s = '';
356 for (var i = 0; i < g.copies.length; i++) {
357 var msg = g.copies[i].alert_message();
359 if (typeof seen[msg] == 'undefined') {
365 tb.setAttribute('value',s);
367 g.error.standard_unexpected_error_alert('populate_alert_message_input',E);
371 /******************************************************************************************************/
372 /* This returns a list of acpl's appropriate for the copies being edited */
374 g.get_acpl_list = function() {
377 function get(lib_id) {
378 g.data.stash_retrieve();
379 var label = 'acpl_list_for_lib_'+lib_id;
380 if (typeof g.data[label] == 'undefined') {
381 var robj = g.network.simple_request('FM_ACPL_RETRIEVE', [ lib_id ]);
382 if (typeof robj.ilsevent != 'undefined') throw(robj);
384 for (var j = 0; j < robj.length; j++) {
385 var my_acpl = robj[j];
386 if (typeof g.data.hash.acpl[ my_acpl.id() ] == 'undefined') {
387 g.data.hash.acpl[ my_acpl.id() ] = my_acpl;
388 g.data.list.acpl.push( my_acpl );
390 temp_list.push( my_acpl );
392 g.data[label] = temp_list; g.data.stash(label,'hash','list');
394 return g.data[label];
397 var seen = {}; seen[ g.data.list.au[0].ws_ou() ] = true;
398 var list = get( g.data.list.au[0].ws_ou() ); //g.data.list.acpl;
399 for (var i = 0; i < g.copies.length; i++) {
400 var cn_id = g.copies[i].call_number();
402 var my_acn = g.network.simple_request('FM_ACN_RETRIEVE',[ cn_id ]);
403 var lib = my_acn.owning_lib();
404 if ( typeof seen[lib] == 'undefined' ) {
406 var r = get(my_acn.owning_lib());
407 list = list.concat( r );
413 g.error.standard_unexpected_error_alert('get_acpl_list',E);
419 /******************************************************************************************************/
420 /* This keeps track of what fields have been edited for styling purposes */
424 /******************************************************************************************************/
425 /* These need data from the middle layer to render */
427 g.special_exception = {
428 'Owning Lib : Call Number' : function(label,value) {
429 JSAN.use('util.widgets');
430 if (value>0) { /* an existing call number */
432 api.FM_ACN_RETRIEVE.app,
433 api.FM_ACN_RETRIEVE.method,
436 var cn = '??? id = ' + value;
438 cn = req.getResultObject();
440 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
442 util.widgets.set_text(label,g.data.hash.aou[ cn.owning_lib() ].shortname() + ' : ' + cn.label());
445 } else { /* a yet to be created call number */
447 util.widgets.set_text(label,g.data.hash.aou[ g.callnumbers[value].owning_lib ].shortname() + ' : ' + g.callnumbers[value].label);
451 'Creator' : function(label,value) {
452 if (value == null || value == '' || value == 'null') return;
453 g.network.simple_request(
454 'FM_AU_RETRIEVE_VIA_ID',
457 var p = '??? id = ' + value;
459 p = req.getResultObject();
463 g.error.sdump('D_ERROR','patron retrieve: ' + E);
465 JSAN.use('util.widgets');
466 util.widgets.set_text(label,p);
470 'Last Editor' : function(label,value) {
471 if (value == null || value == '' || value == 'null') return;
472 g.network.simple_request(
473 'FM_AU_RETRIEVE_VIA_ID',
476 var p = '??? id = ' + value;
478 p = req.getResultObject();
482 g.error.sdump('D_ERROR','patron retrieve: ' + E);
484 util.widgets.set_text(label,p);
491 /******************************************************************************************************/
492 g.readonly_stat_cat_names = [];
493 g.editable_stat_cat_names = [];
495 /******************************************************************************************************/
496 /* These get show in the left panel */
498 g.panes_and_field_names = {
505 render: 'fm.barcode();',
511 render: 'util.date.formatted_date( fm.create_date(), "%F");',
517 render: 'fm.creator();',
523 render: 'util.date.formatted_date( fm.edit_date(), "%F");',
529 render: 'fm.editor();',
540 render: 'typeof fm.location() == "object" ? fm.location().name() : g.data.lookup("acpl",fm.location()).name()',
541 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.get_acpl_list(), function(obj) { return [ g.data.hash.aou[ obj.owning_lib() ].shortname() + " : " + obj.name(), obj.id() ]; }).sort()); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
546 "Circulation Library",
548 render: 'typeof fm.circ_lib() == "object" ? fm.circ_lib().shortname() : g.data.hash.aou[ fm.circ_lib() ].shortname()',
549 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);',
553 "Owning Lib : Call Number",
555 render: 'fm.call_number();',
561 render: 'fm.copy_number() == null ? "<Unset>" : fm.copy_number()',
562 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);',
574 render: 'fm.circulate() == null ? "<Unset>" : ( get_bool( fm.circulate() ) ? "Yes" : "No" )',
575 input: 'c = function(v){ g.apply("circulate",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", get_db_true() ], [ "No", get_db_false() ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
581 render: 'fm.holdable() == null ? "<Unset>" : ( get_bool( fm.holdable() ) ? "Yes" : "No" )',
582 input: 'c = function(v){ g.apply("holdable",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", get_db_true() ], [ "No", get_db_false() ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
588 render: 'fm.age_protect() == null ? "<Unset>" : ( typeof fm.age_protect() == "object" ? fm.age_protect().name() : g.data.hash.crahp[ fm.age_protect() ].name() )',
589 input: 'c = function(v){ g.apply("age_protect",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "<Remove Protection>", "<HACK:KLUDGE:NULL>" ] ].concat( util.functional.map_list( g.data.list.crahp, function(obj) { return [ obj.name(), obj.id() ]; }).sort() ) ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
596 render: 'switch(fm.loan_duration()){ case 1: case "1": "Short"; break; case 2: case "2": "Normal"; break; case 3:case "3": "Long"; break; }',
597 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);',
604 render: 'switch(fm.fine_level()){ case 1: case "1": "Low"; break; case 2: case "2": "Normal"; break; case 3: case "3": "High"; break; }',
605 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);',
612 render: 'fm.circ_as_type() == null ? "<Unset>" : g.data.hash.citm[ fm.circ_as_type() ].value()',
613 input: 'c = function(v){ g.apply("circ_as_type",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( util.functional.map_list( g.data.list.citm, function(n){return [ n.code() + " - " + n.value(), n.code()];} ).sort() ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
617 "Circulation Modifier",
619 render: 'fm.circ_modifier() == null ? "<Unset>" : fm.circ_modifier()',
620 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);',
629 render: 'fm.alert_message() == null ? "<Unset>" : fm.alert_message()',
630 input: 'c = function(v){ g.apply("alert_message",v); if (typeof post_c == "function") post_c(v); }; x = document.createElement("textbox"); x.setAttribute("multiline",true); g.populate_alert_message_input(x); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
637 render: 'fm.deposit() == null ? "<Unset>" : ( get_bool( fm.deposit() ) ? "Yes" : "No" )',
638 input: 'c = function(v){ g.apply("deposit",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", get_db_true() ], [ "No", get_db_false() ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
644 render: 'util.money.sanitize( fm.deposit_amount() );',
645 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);',
651 render: 'util.money.sanitize( fm.price() );',
652 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);',
659 render: 'fm.opac_visible() == null ? "<Unset>" : ( get_bool( fm.opac_visible() ) ? "Yes" : "No" )',
660 input: 'c = function(v){ g.apply("opac_visible",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", get_db_true() ], [ "No", get_db_false() ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
666 render: 'fm.ref() == null ? "<Unset>" : ( get_bool( fm.ref() ) ? "Yes" : "No" )',
667 input: 'c = function(v){ g.apply("ref",v); if (typeof post_c == "function") post_c(v); }; x = util.widgets.make_menulist( [ [ "Yes", get_db_true() ], [ "No", get_db_false() ] ] ); x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c), false);',
678 /******************************************************************************************************/
679 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
681 g.summarize = function( copies ) {
682 /******************************************************************************************************/
685 JSAN.use('util.date'); JSAN.use('util.money');
688 for (var i in g.panes_and_field_names) {
689 g.field_names = g.field_names.concat( g.panes_and_field_names[i] );
691 g.field_names = g.field_names.concat( g.editable_stat_cat_names );
692 g.field_names = g.field_names.concat( g.readonly_stat_cat_names );
694 /******************************************************************************************************/
695 /* Loop through the field names */
697 for (var i = 0; i < g.field_names.length; i++) {
699 var field_name = g.field_names[i][0];
700 var render = g.field_names[i][1].render;
701 g.summary[ field_name ] = {};
703 /******************************************************************************************************/
704 /* Loop through the copies */
706 for (var j = 0; j < copies.length; j++) {
709 var cmd = render || ('fm.' + field_name + '();');
712 /**********************************************************************************************/
713 /* Try to retrieve the value for this field for this copy */
718 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n');
720 if (typeof value == 'object' && value != null) {
721 alert('FIXME: field_name = <' + field_name + '> value = <' + js2JSON(value) + '>\n');
724 /**********************************************************************************************/
725 /* Tally the count */
727 if (g.summary[ field_name ][ value ]) {
728 g.summary[ field_name ][ value ]++;
730 g.summary[ field_name ][ value ] = 1;
734 g.error.sdump('D_TRACE','summary = ' + js2JSON(g.summary) + '\n');
737 /******************************************************************************************************/
738 /* Display the summarized data and inputs for editing */
740 g.render = function() {
742 /******************************************************************************************************/
743 /* Library setup and clear any existing interface */
745 JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
747 for (var i in g.panes_and_field_names) {
748 var p = document.getElementById(i);
749 if (p) util.widgets.remove_children(p);
752 /******************************************************************************************************/
753 /* Prepare the panes */
755 var groupbox; var caption; var vbox; var grid; var rows;
757 /******************************************************************************************************/
758 /* Loop through the field names */
760 for (h in g.panes_and_field_names) {
761 if (!document.getElementById(h)) continue;
762 for (var i = 0; i < g.panes_and_field_names[h].length; i++) {
764 var f = g.panes_and_field_names[h][i]; var fn = f[0];
765 groupbox = document.createElement('groupbox'); document.getElementById(h).appendChild(groupbox);
766 if (typeof g.changed[fn] != 'undefined') groupbox.setAttribute('class','copy_editor_field_changed');
767 caption = document.createElement('caption'); groupbox.appendChild(caption);
768 caption.setAttribute('label',fn);
769 vbox = document.createElement('vbox'); groupbox.appendChild(vbox);
770 grid = util.widgets.make_grid( [ { 'flex' : 1 }, {}, {} ] ); vbox.appendChild(grid);
771 grid.setAttribute('flex','1');
772 rows = grid.lastChild;
775 /**************************************************************************************/
776 /* Loop through each value for the field */
778 for (var j in g.summary[fn]) {
779 var value = j; var count = g.summary[fn][j];
780 row = document.createElement('row'); rows.appendChild(row);
781 var label1 = document.createElement('description'); row.appendChild(label1);
782 if (g.special_exception[ fn ]) {
783 g.special_exception[ fn ]( label1, value );
785 label1.appendChild( document.createTextNode(value) );
787 var label2 = document.createElement('description'); row.appendChild(label2);
788 var unit = count == 1 ? 'copy' : 'copies';
789 label2.appendChild( document.createTextNode(count + ' ' + unit) );
791 var hbox = document.createElement('hbox');
792 hbox.setAttribute('id',fn);
793 groupbox.appendChild(hbox);
794 var hbox2 = document.createElement('hbox');
795 groupbox.appendChild(hbox2);
797 /**************************************************************************************/
798 /* Render the input widget */
800 if (f[1].input && g.edit) {
801 g.render_input(hbox,f[1]);
805 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
811 /******************************************************************************************************/
812 /* This actually draws the change button and input widget for a given field */
813 g.render_input = function(node,blob) {
815 // node = hbox ; groupbox -> hbox, hbox
817 var groupbox = node.parentNode;
818 var caption = groupbox.firstChild;
819 var vbox = node.previousSibling;
821 var hbox2 = node.nextSibling;
823 var input_cmd = blob.input;
824 var render_cmd = blob.render;
826 var block = false; var first = true;
828 function on_mouseover(ev) {
829 groupbox.setAttribute('style','background: white');
832 function on_mouseout(ev) {
833 groupbox.setAttribute('style','');
836 vbox.addEventListener('mouseover',on_mouseover,false);
837 vbox.addEventListener('mouseout',on_mouseout,false);
838 groupbox.addEventListener('mouseover',on_mouseover,false);
839 groupbox.addEventListener('mouseout',on_mouseout,false);
840 groupbox.firstChild.addEventListener('mouseover',on_mouseover,false);
841 groupbox.firstChild.addEventListener('mouseout',on_mouseout,false);
843 function on_click(ev){
845 if (block) return; block = true;
850 var t = input_cmd.match('apply_stat_cat') ? 'stat_cat' : 'attribute';
854 f = input_cmd.match(/apply\("(.+?)",/)[1];
857 f = input_cmd.match(/apply_stat_cat\((.+?),/)[1];
860 g.changed[ hbox.id ] = { 'type' : t, 'field' : f, 'value' : v };
864 g.summarize( g.copies );
869 g.error.standard_unexpected_error_alert('post_c',E);
872 var x; var c; eval( input_cmd );
874 util.widgets.remove_children(vbox);
875 util.widgets.remove_children(hbox);
876 util.widgets.remove_children(hbox2);
878 var apply = document.createElement('button');
879 apply.setAttribute('label','Apply');
880 apply.setAttribute('accesskey','A');
881 hbox2.appendChild(apply);
882 apply.addEventListener('command',function() { c(x.value); },false);
883 var cancel = document.createElement('button');
884 cancel.setAttribute('label','Cancel');
885 cancel.addEventListener('command',function() { setTimeout( function() { g.summarize( g.copies ); g.render(); }, 0); }, false);
886 hbox2.appendChild(cancel);
887 setTimeout( function() { x.focus(); }, 0 );
890 g.error.standard_unexpected_error_alert('render_input',E);
893 vbox.addEventListener('click',on_click, false);
894 hbox.addEventListener('click',on_click, false);
895 caption.addEventListener('click',on_click, false);
896 caption.addEventListener('keypress',function(ev) {
897 if (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) on_click();
899 caption.setAttribute('style','-moz-user-focus: normal');
900 caption.setAttribute('onfocus','this.setAttribute("class","outline_me")');
901 caption.setAttribute('onblur','this.setAttribute("class","")');
904 g.error.sdump('D_ERROR',E + '\n');
908 /******************************************************************************************************/
909 /* store the copies in the global xpcom stash */
911 g.stash_and_close = function() {
912 if (g.handle_update) {
914 var r = g.network.request(
915 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
916 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
917 [ ses(), g.copies, true ]
920 if (typeof r.ilsevent != 'undefined') {
921 g.error.standard_unexpected_error_alert('copy update',r);
923 /* FIXME -- revisit the return value here */
925 alert('copy update error: ' + js2JSON(E));
928 g.data.temp_copies = js2JSON( g.copies );
929 g.data.stash('temp_copies');
930 g.error.sdump('D_CAT','in modal window, g.data.temp_copies = \n' + g.data.temp_copies + '\n');
934 /******************************************************************************************************/
935 /* spawn copy notes interface */
937 g.copy_notes = function() {
938 JSAN.use('util.window'); var win = new util.window();
939 win.open(urls.XUL_COPY_NOTES + '?copy_id=' + window.escape(g.copies[0].id()),'Copy Notes','chrome,resizable,modal');