robustify (and klunkify) unified volume copy creator
authorJason Etheridge <jason@esilibrary.com>
Mon, 1 Aug 2011 05:40:22 +0000 (01:40 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 3 Aug 2011 17:40:46 +0000 (13:40 -0400)
Disable/style the Item Editor while changes in the volume/item pane are being
considered, and require an explicit press of a Ready Item Editor button to
enable the interface.  This reduces the chance of editing widgets in the item
editor from being ripped out from under you (for example, if you try to go
straight from editing a call number to editing an item attribute).

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/web/opac/locale/en-US/lang.dtd
Open-ILS/xul/staff_client/chrome/content/util/widgets.js
Open-ILS/xul/staff_client/server/cat/copy_editor.js
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.xul
Open-ILS/xul/staff_client/server/skin/global.css

index 1430b5d..aec871a 100644 (file)
 <!ENTITY staff.cat.volume_copy_creator.batch_bar.call_number.label.label "Call Number:">
 <!ENTITY staff.cat.volume_copy_creator.batch_bar.call_number.label.accesskey "L">
 <!ENTITY staff.cat.volume_copy_creator.batch_bar.call_number.suffix "Suffix:">
+<!ENTITY staff.cat.volume_copy_creator.ready_item_editor.label "Ready Item Editor">
+<!ENTITY staff.cat.volume_copy_creator.ready_item_editor.accesskey "R">
 <!ENTITY staff.cat.volume_editor.title "Volumes">
 <!ENTITY staff.cat.volume_editor.caption.label "Volume Editor">
 <!ENTITY staff.cat.volume_editor.modify.label "Modify">
index 2bad0b0..4867256 100644 (file)
@@ -232,7 +232,19 @@ util.widgets.apply_vertical_tab_on_enter_handler = function(node,onfailure,no_en
                     }
                 } else {
                     if (typeof no_enter_func == 'function') {
-                        no_enter_func(ev);
+                        if ([
+                                35 /* end */,
+                                36 /* home */,
+                                37 /* left */,
+                                38 /* up */,
+                                39 /* right */,
+                                40 /* down */,
+                                9 /* tab */
+                            ].indexOf(ev.keyCode) == -1
+                        ) {
+                            // really the no_enter, no_arrow_key, no_tab, etc. func :)
+                            no_enter_func(ev);
+                        }
                     }
                 }
             },
index b3155b7..749c689 100644 (file)
@@ -1,5 +1,5 @@
 // vim:et:sw=4:ts=4
-var g = {};
+var g = { 'disabled' : false };
 g.map_acn = {};
 
 function $(id) { return document.getElementById(id); }
@@ -164,8 +164,20 @@ function my_init() {
         g.check_for_unmet_required_fields();
 
         if (xulG.unified_interface) {
+            xulG.disable_copy_editor = function(c) {
+                addCSSClass(document.documentElement,'red_bg');
+                g.disabled = true;
+            }
+            xulG.enable_copy_editor = function(c) {
+                removeCSSClass(document.documentElement,'red_bg');
+                g.disabled = false;
+                xulG.refresh_copy_editor();
+            }
             xulG.refresh_copy_editor = function() {
+                dump('refresh_copy_editor\n');
+                addCSSClass(document.documentElement,'blue_bg');
                 try {
+                    xulG.clear_update_copy_editor_timeout();
                     g.copies = xulG.copies;
                     g.edit = g.copies.length > 0;
                     if (g.edit) {
@@ -179,6 +191,11 @@ function my_init() {
                     g.summarize( g.copies );
                     g.render();
                     g.check_for_unmet_required_fields();
+                    setTimeout(
+                        function() {
+                            removeCSSClass(document.documentElement,'blue_bg');
+                        }, 1000
+                    );
                 } catch(E) {
                     alert('Error in copy_editor.js, xulG.refresh_copy_editor(): ' + E);
                 }
@@ -1275,7 +1292,10 @@ g.render_input = function(node,blob) {
 
         function on_click(ev){
             try {
-                if (block) return; block = true;
+                if (block || g.disabled || !g.edit) {
+                    return;
+                }
+                block = true;
 
                 oils_lock_page();
 
index 303cea0..48b87c5 100644 (file)
@@ -62,8 +62,29 @@ function my_init() {
                 g.save_button_locked = false;
                 document.getElementById("Create").disabled = false;
             }
+            xulG.clear_update_copy_editor_timeout = function() {
+                if (g.update_copy_editor_timeoutID) {
+                    clearTimeout(g.update_copy_editor_timeoutID);
+                    g.gather_copies();
+                }
+            }
+            $('Sync').addEventListener(
+                'command',
+                function() {
+                    // give gather_copies_soon fired off directly/indirectly by
+                    // onchange a chance to go first
+                    setTimeout(
+                        function() {
+                            xulG.enable_copy_editor();
+                        },
+                        0
+                    );
+                },
+                false
+            );
         } else {
             $('Create').hidden = true;
+            $('Sync').hidden = true;
         }
 
         /***********************************************************************************************************/
@@ -268,8 +289,8 @@ g.render_volume_count_entry = function(row,ou_id) {
     }
     util.widgets.apply_vertical_tab_on_enter_handler(
         tb,
-        function() { render_copy_count_entry({'target':tb}); setTimeout(function(){util.widgets.vertical_tab(tb);},0); },
-        g.delay_gather_copies_soon
+        function() { render_copy_count_entry({'target':tb}); setTimeout(function(){util.widgets.vertical_tab(tb);},0); }
+        ,function() { $('Sync').disabled = true; }
     );
     tb.addEventListener( 'change', render_copy_count_entry, false);
     tb.addEventListener( 'change', g.gather_copies_soon, false);
@@ -460,11 +481,11 @@ g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
                                     util.widgets.vertical_tab(call_number_column_textbox);
                                 },0
                             );
-                        },
-                        g.delay_gather_copies_soon
+                        }
+                        ,function() { $('Sync').disabled = true; }
                     );
                     call_number_column_textbox.addEventListener( 'change', handle_change_to_callnumber_data, false);
-                    call_number_column_textbox.addEventListener( 'change', g.gather_copies_soon, false);
+                    //call_number_column_textbox.addEventListener( 'change', g.gather_copies_soon, false);
                     call_number_column_textbox.addEventListener( 'focus', function(ev) { g.last_focus = ev.target; }, false );
 
                     /**** CLASSIFICATION COLUMN revisited ****/
@@ -528,8 +549,8 @@ g.render_callnumber_copy_count_entry = function(row,ou_id,count) {
                                     util.widgets.vertical_tab(number_of_copies_column_textbox);
                                 },0
                             );
-                        },
-                        g.delay_gather_copies_soon
+                        }
+                        ,function() { $('Sync').disabled = true; }
                     );
                     number_of_copies_column_textbox.addEventListener( 'change', handle_change_number_of_copies_column_textbox, false);
                     number_of_copies_column_textbox.addEventListener( 'change', g.gather_copies_soon, false);
@@ -752,7 +773,7 @@ g.render_barcode_entry = function(node,callnumber_composite_key,count,ou_id) {
                         setTimeout( function() { ev.target.select(); ev.target.focus(); }, 0);
                     }
                 }, false);
-                tb.addEventListener('change', g.gather_copies_soon, false);
+                //tb.addEventListener('change', g.gather_copies_soon, false);
                 tb.addEventListener( 'focus', function(ev) { g.last_focus = ev.target; }, false );
             }
         }
@@ -815,6 +836,10 @@ g.gather_copies_soon = function(ev) {
     try {
         if (!xulG.unified_interface) { return; }
         dump('g.gather_copies_soon()\n');
+        if (typeof xulG.disable_copy_editor == 'function') {
+            xulG.disable_copy_editor();
+        }
+        $('Sync').disabled = true;
         if (g.update_copy_editor_timeoutID) {
             clearTimeout(g.update_copy_editor_timeoutID);
         }
@@ -824,6 +849,8 @@ g.gather_copies_soon = function(ev) {
             function() {
                 try {
                     g.gather_copies();
+                    //xulG.enable_copy_editor();
+                    $('Sync').disabled = false;
                     xulG.refresh_copy_editor();
                 } catch(E) {
                     dump('Error in volume_copy_editor.js with g.gather_copies_soon setTimeout func(): ' + E + '\n');
index 5cfc111..00a846f 100644 (file)
                 <button id="CreateWithDefaults" disabled="true" oncommand="g.stash_and_close('noedit');"/>
                 <button id="EditThenCreate" disabled="true" oncommand="g.stash_and_close('edit');"/>
             </hbox>
+            <button id="Sync"
+                label="&staff.cat.volume_copy_creator.ready_item_editor.label;"
+                accesskey="&staff.cat.volume_copy_creator.ready_item_editor.accesskey;"
+                disabled="true"
+                image="/xul/server/skin/media/images/down_arrow.gif"/>
             <button id="Create" disabled="true" oncommand="g.stash_and_close('unified_interface');"/>
         </hbox>
     </vbox>
index bca48dc..d089ced 100644 (file)
@@ -149,4 +149,5 @@ listitem { border-bottom: solid thin black; }
 
 .oils_event { color: red; }
 
-
+.blue_bg { background-color: blue; }
+.red_bg { background-color: red; }