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 (g.data.temp_copy_ids != 'undefined') 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( util.functional.map_list( g.data.hash.asc[' + sc.id()
138 + '].entries(), function(obj){ return [ obj.value(), obj.id() ]; } ).sort() ); '
139 + 'x.addEventListener("apply",function(f){ return function(ev) { f(ev.target.value); } }(c),false);',
143 dump('temp_array = ' + js2JSON(temp_array) + '\n');
145 g.panes_and_field_names.right_pane4.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 /******************************************************************************************************/
164 /* Backup copies :) */
166 g.original_copies = js2JSON( g.copies );
168 /******************************************************************************************************/
171 g.summarize( g.copies );
175 var err_msg = "!! This software has encountered an error. Please tell your friendly " +
176 "system administrator or software developer the following:\ncat/copy_editor.xul\n" + E + '\n';
177 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); dump(js2JSON(E)); }
182 /******************************************************************************************************/
183 /* Retrieve Templates */
185 g.retrieve_templates = function() {
187 JSAN.use('util.widgets'); JSAN.use('util.functional');
189 var robj = g.network.simple_request('FM_AUS_RETRIEVE',[ses(),g.data.list.au[0].id()]);
190 if (typeof robj['staff_client.copy_editor.templates'] != 'undefined') {
191 g.templates = robj['staff_client.copy_editor.templates'];
193 util.widgets.remove_children('template_placeholder');
194 var list = util.functional.map_object_to_list( g.templates, function(obj,i) { return [i, i]; } );
196 g.template_menu = util.widgets.make_menulist( list );
197 $('template_placeholder').appendChild(g.template_menu);
199 g.error.standard_unexpected_error_alert('Error retrieving templates',E);
203 /******************************************************************************************************/
206 g.apply_template = function() {
208 var name = g.template_menu.value;
209 if (g.templates[ name ] != 'undefined') {
210 var template = g.templates[ name ];
211 for (var i in template) {
212 g.changed[ i ] = template[ i ];
213 switch( template[i].type ) {
215 g.apply(template[i].field,template[i].value);
218 g.apply_stat_cat(template[i].field,template[i].value);
222 g.summarize( g.copies );
226 g.error.standard_unexpected_error_alert('Error applying template',E);
230 /******************************************************************************************************/
231 /* Save as Template */
233 g.save_template = function() {
235 var name = window.prompt('Enter template name:','','Save As Template');
237 g.templates[name] = g.changed;
238 var robj = g.network.simple_request(
239 'FM_AUS_UPDATE',[ses(),g.data.list.au[0].id(), { 'staff_client.copy_editor.templates' : g.templates }]
241 if (typeof robj.ilsevent != 'undefined') {
244 alert('Template "' + name + '" saved.');
248 g.retrieve_templates();
250 g.error.standard_unexpected_error_alert('Error saving template',E);
256 g.error.standard_unexpected_error_alert('Error saving template',E);
260 /******************************************************************************************************/
261 /* Delete Template */
263 g.delete_template = function() {
265 var name = g.template_menu.value;
267 if (! window.confirm('Delete template "' + name + '"?') ) return;
268 delete(g.templates[name]);
269 var robj = g.network.simple_request(
270 'FM_AUS_UPDATE',[ses(),g.data.list.au[0].id(), { 'staff_client.copy_editor.templates' : g.templates }]
272 if (typeof robj.ilsevent != 'undefined') {
275 alert('Template "' + name + '" deleted.');
279 g.retrieve_templates();
281 g.error.standard_unexpected_error_alert('Error deleting template',E);
287 g.error.standard_unexpected_error_alert('Error deleting template',E);
291 /******************************************************************************************************/
292 /* Restore backup copies */
294 g.reset = function() {
296 g.copies = JSON2js( g.original_copies );
297 g.summarize( g.copies );
301 /******************************************************************************************************/
302 /* Apply a value to a specific field on all the copies being edited */
304 g.apply = function(field,value) {
305 g.error.sdump('D_TRACE','field = ' + field + ' value = ' + value + '\n');
306 for (var i = 0; i < g.copies.length; i++) {
307 var copy = g.copies[i];
309 copy[field]( value ); copy.ischanged('1');
316 /******************************************************************************************************/
317 /* Apply a stat cat entry to all the copies being edited */
319 g.apply_stat_cat = function(sc_id,entry_id) {
320 g.error.sdump('D_TRACE','sc_id = ' + sc_id + ' entry_id = ' + entry_id + '\n');
321 for (var i = 0; i < g.copies.length; i++) {
322 var copy = g.copies[i];
325 var temp = copy.stat_cat_entries();
326 if (!temp) temp = [];
327 temp = util.functional.filter_list(
330 return (obj.stat_cat() != sc_id);
334 util.functional.find_id_object_in_list(
335 g.data.hash.asc[sc_id].entries(),
339 copy.stat_cat_entries( temp );
347 /******************************************************************************************************/
348 /* This keeps track of what fields have been edited for styling purposes */
352 /******************************************************************************************************/
353 /* These need data from the middle layer to render */
355 g.special_exception = {
356 'Call Number' : function(label,value) {
357 JSAN.use('util.widgets');
358 if (value>0) { /* an existing call number */
360 api.FM_ACN_RETRIEVE.app,
361 api.FM_ACN_RETRIEVE.method,
364 var cn = '??? id = ' + value;
366 cn = req.getResultObject().label();
368 g.error.sdump('D_ERROR','callnumber retrieve: ' + E);
370 util.widgets.set_text(label,cn);
373 } else { /* a yet to be created call number */
375 util.widgets.set_text(label,g.callnumbers[value]);
379 'Creator' : function(label,value) {
380 if (value == null || value == '' || value == 'null') return;
381 g.network.simple_request(
382 'FM_AU_RETRIEVE_VIA_ID',
385 var p = '??? id = ' + value;
387 p = req.getResultObject();
391 g.error.sdump('D_ERROR','patron retrieve: ' + E);
393 JSAN.use('util.widgets');
394 util.widgets.set_text(label,p);
398 'Last Editor' : function(label,value) {
399 if (value == null || value == '' || value == 'null') return;
400 g.network.simple_request(
401 'FM_AU_RETRIEVE_VIA_ID',
404 var p = '??? id = ' + value;
406 p = req.getResultObject();
410 g.error.sdump('D_ERROR','patron retrieve: ' + E);
412 util.widgets.set_text(label,p);
419 /******************************************************************************************************/
420 g.readonly_stat_cat_names = [];
421 g.editable_stat_cat_names = [];
423 /******************************************************************************************************/
424 /* These get show in the left panel */
426 g.panes_and_field_names = {
433 render: 'fm.barcode();',
439 render: 'util.date.formatted_date( fm.create_date(), "%F");',
445 render: 'fm.creator();',
451 render: 'util.date.formatted_date( fm.edit_date(), "%F");',
457 render: 'fm.editor();',
468 render: 'typeof fm.location() == "object" ? fm.location().name() : g.data.hash.acpl[ fm.location() ].name()',
469 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);',
474 "Circulation Library",
476 render: 'typeof fm.circ_lib() == "object" ? fm.circ_lib().shortname() : g.data.hash.aou[ fm.circ_lib() ].shortname()',
477 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);',
483 render: 'fm.call_number();',
489 render: 'fm.copy_number() == null ? "<Unset>" : fm.copy_number()',
490 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);',
502 render: 'fm.circulate() == null ? "<Unset>" : ( fm.circulate() == 1 ? "Yes" : "No" )',
503 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);',
509 render: 'fm.holdable() == null ? "<Unset>" : ( fm.holdable() == 1? "Yes" : "No" )',
510 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);',
517 render: 'switch(fm.loan_duration()){ case 1: case "1": "Short"; break; case 2: case "2": "Normal"; break; case 3:case "3": "Long"; break; }',
518 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);',
525 render: 'switch(fm.fine_level()){ case 1: case "1": "Low"; break; case 2: case "2": "Normal"; break; case 3: case "3": "High"; break; }',
526 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);',
533 render: 'fm.circ_as_type() == null ? "<Unset>" : g.data.hash.citm[ fm.circ_as_type() ].value()',
534 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);',
538 "Circulation Modifier",
540 render: 'fm.circ_modifier() == null ? "<Unset>" : fm.circ_modifier()',
541 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);',
550 render: 'fm.alert_message() == null ? "<Unset>" : fm.alert_message()',
551 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);',
558 render: 'fm.deposit() == null ? "<Unset>" : ( fm.deposit() == 1 ? "Yes" : "No" )',
559 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);',
565 render: 'util.money.sanitize( fm.deposit_amount() );',
566 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);',
572 render: 'util.money.sanitize( fm.price() );',
573 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);',
580 render: 'fm.opac_visible() == null ? "<Unset>" : ( fm.opac_visible() == 1 ? "Yes" : "No" )',
581 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);',
587 render: 'fm.ref() == null ? "<Unset>" : ( fm.ref() == 1 ? "Yes" : "No" )',
588 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);',
599 /******************************************************************************************************/
600 /* This loops through all our fieldnames and all the copies, tallying up counts for the different values */
602 g.summarize = function( copies ) {
603 /******************************************************************************************************/
606 JSAN.use('util.date'); JSAN.use('util.money');
609 for (var i in g.panes_and_field_names) {
610 g.field_names = g.field_names.concat( g.panes_and_field_names[i] );
612 g.field_names = g.field_names.concat( g.editable_stat_cat_names );
613 g.field_names = g.field_names.concat( g.readonly_stat_cat_names );
615 /******************************************************************************************************/
616 /* Loop through the field names */
618 for (var i = 0; i < g.field_names.length; i++) {
620 var field_name = g.field_names[i][0];
621 var render = g.field_names[i][1].render;
622 g.summary[ field_name ] = {};
624 /******************************************************************************************************/
625 /* Loop through the copies */
627 for (var j = 0; j < copies.length; j++) {
630 var cmd = render || ('fm.' + field_name + '();');
633 /**********************************************************************************************/
634 /* Try to retrieve the value for this field for this copy */
639 g.error.sdump('D_ERROR','Attempted ' + cmd + '\n' + E + '\n');
641 if (typeof value == 'object' && value != null) {
642 alert('FIXME: field_name = ' + field_name + ' value = ' + js2JSON(value) + '\n');
645 /**********************************************************************************************/
646 /* Tally the count */
648 if (g.summary[ field_name ][ value ]) {
649 g.summary[ field_name ][ value ]++;
651 g.summary[ field_name ][ value ] = 1;
655 g.error.sdump('D_TRACE','summary = ' + js2JSON(g.summary) + '\n');
658 /******************************************************************************************************/
659 /* Display the summarized data and inputs for editing */
661 g.render = function() {
663 /******************************************************************************************************/
664 /* Library setup and clear any existing interface */
666 JSAN.use('util.widgets'); JSAN.use('util.date'); JSAN.use('util.money'); JSAN.use('util.functional');
668 for (var i in g.panes_and_field_names) {
669 var p = document.getElementById(i);
670 if (p) util.widgets.remove_children(p);
673 /******************************************************************************************************/
674 /* Prepare the panes */
676 var groupbox; var caption; var vbox; var grid; var rows;
678 /******************************************************************************************************/
679 /* Loop through the field names */
681 for (h in g.panes_and_field_names) {
682 if (!document.getElementById(h)) continue;
683 for (var i = 0; i < g.panes_and_field_names[h].length; i++) {
685 var f = g.panes_and_field_names[h][i]; var fn = f[0];
686 groupbox = document.createElement('groupbox'); document.getElementById(h).appendChild(groupbox);
687 if (typeof g.changed[fn] != 'undefined') groupbox.setAttribute('class','copy_editor_field_changed');
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 groupbox.appendChild(hbox);
715 var hbox2 = document.createElement('hbox');
716 groupbox.appendChild(hbox2);
718 /**************************************************************************************/
719 /* Render the input widget */
721 if (f[1].input && g.edit) {
722 g.render_input(hbox,f[1]);
726 g.error.sdump('D_ERROR','copy editor: ' + E + '\n');
732 /******************************************************************************************************/
733 /* This actually draws the change button and input widget for a given field */
734 g.render_input = function(node,blob) {
736 // node = hbox ; groupbox -> hbox, hbox
738 var groupbox = node.parentNode;
739 var caption = groupbox.firstChild;
740 var vbox = node.previousSibling;
742 var hbox2 = node.nextSibling;
744 var input_cmd = blob.input;
745 var render_cmd = blob.render;
747 var block = false; var first = true;
749 function on_mouseover(ev) {
750 groupbox.setAttribute('style','background: white');
753 function on_mouseout(ev) {
754 groupbox.setAttribute('style','');
757 vbox.addEventListener('mouseover',on_mouseover,false);
758 vbox.addEventListener('mouseout',on_mouseout,false);
759 groupbox.addEventListener('mouseover',on_mouseover,false);
760 groupbox.addEventListener('mouseout',on_mouseout,false);
761 groupbox.firstChild.addEventListener('mouseover',on_mouseover,false);
762 groupbox.firstChild.addEventListener('mouseout',on_mouseout,false);
764 function on_click(ev){
766 if (block) return; block = true;
771 var t = input_cmd.match('apply_stat_cat') ? 'stat_cat' : 'attribute';
775 f = input_cmd.match(/apply\("(.+?)",/)[1];
778 f = input_cmd.match(/apply_stat_cat\((.+?),/)[1];
781 g.changed[ hbox.id ] = { 'type' : t, 'field' : f, 'value' : v };
785 g.summarize( g.copies );
790 g.error.standard_unexpected_error_alert('post_c',E);
793 var x; var c; eval( input_cmd );
795 util.widgets.remove_children(vbox);
796 util.widgets.remove_children(hbox);
797 util.widgets.remove_children(hbox2);
799 var apply = document.createElement('button');
800 apply.setAttribute('label','Apply');
801 apply.setAttribute('accesskey','A');
802 hbox2.appendChild(apply);
803 apply.addEventListener('command',function() { c(x.value); },false);
804 var cancel = document.createElement('button');
805 cancel.setAttribute('label','Cancel');
806 cancel.addEventListener('command',function() { setTimeout( function() { g.summarize( g.copies ); g.render(); }, 0); }, false);
807 hbox2.appendChild(cancel);
808 setTimeout( function() { x.focus(); }, 0 );
811 g.error.standard_unexpected_error_alert('render_input',E);
814 vbox.addEventListener('click',on_click, false);
815 hbox.addEventListener('click',on_click, false);
816 caption.addEventListener('click',on_click, false);
817 caption.addEventListener('keypress',function(ev) {
818 if (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* mac enter */) on_click();
820 caption.setAttribute('style','-moz-user-focus: normal');
821 caption.setAttribute('onfocus','this.setAttribute("class","outline_me")');
822 caption.setAttribute('onblur','this.setAttribute("class","")');
825 g.error.sdump('D_ERROR',E + '\n');
829 /******************************************************************************************************/
830 /* store the copies in the global xpcom stash */
832 g.stash_and_close = function() {
833 if (g.handle_update) {
835 var r = g.network.request(
836 api.FM_ACP_FLESHED_BATCH_UPDATE.app,
837 api.FM_ACP_FLESHED_BATCH_UPDATE.method,
840 if (typeof r.ilsevent != 'undefined') {
841 g.error.standard_unexpected_error_alert('copy update',r);
843 /* FIXME -- revisit the return value here */
845 alert('copy update error: ' + js2JSON(E));
848 g.data.temp_copies = js2JSON( g.copies );
849 g.data.stash('temp_copies');
850 g.error.sdump('D_CAT','in modal window, g.data.temp_copies = \n' + g.data.temp_copies + '\n');
854 /******************************************************************************************************/
855 /* spawn copy notes interface */
857 g.copy_notes = function() {
858 JSAN.use('util.window'); var win = new util.window();
859 win.open(urls.XUL_COPY_NOTES + '?copy_id=' + window.escape(g.copies[0].id()),'Copy Notes','chrome,resizable,modal');