bugfix for barcode renaming, local code and server code. Needs just a little more...
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 3 Oct 2007 22:48:25 +0000 (22:48 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 3 Oct 2007 22:48:25 +0000 (22:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@7867 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/main/menu.js
Open-ILS/xul/staff_client/server/cat/util.js

index f4a0585..b69ce7d 100644 (file)
@@ -101,28 +101,58 @@ main.menu.prototype = {
                                                JSAN.use('util.network');
                                                var network = new util.network();
 
-                                               var old_bc = window.prompt('Enter original barcode for the copy:','','Replace Barcode');
+                                               var old_bc = window.prompt('Enter original barcode for the item:','','Replace Barcode');
                                                if (!old_bc) return;
        
-                                               var copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
-                                               if (typeof copy.ilsevent != 'undefined') throw(copy); 
-                                               if (!copy) throw(copy);
+                                               var copy;
+                        try {
+                            copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
+                                               if (typeof copy.ilsevent != 'undefined') throw(copy); 
+                                               if (!copy) throw(copy);
+                        } catch(E) {
+                            alert('We were unable to retrieve an item with barcode "' + old_bc + '".\n');
+                            return;
+                        }
        
                                                // Why did I want to do this twice?  Because this copy is more fleshed?
-                                               copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
-                                               if (typeof copy.ilsevent != 'undefined') throw(copy);
-                                               if (!copy) throw(copy);
+                        try {
+                                               copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
+                                               if (typeof copy.ilsevent != 'undefined') throw(copy);
+                                               if (!copy) throw(copy);
+                        } catch(E) {
+                            try { alert('We were unable to retrieve an item with barcode "' + old_bc + '".\n' + (typeof E.ilsevent == 'undefined' ? '' : E.textcode + ' : ' + E.desc)); } catch(F) { alert(E + '\n' + F); }
+                            return;
+                        }
        
                                                var new_bc = window.prompt('Enter the replacement barcode for the copy:','','Replace Barcode');
+                                               new_bc = String( new_bc ).replace(/\s/g,'');
+                                               if (!new_bc) {
+                                                       alert('Rename aborted.  Blank for barcode not allowed.');
+                                                       return;
+                                               }
        
-                                               var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ ses(), new_bc ]);
+                                               var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
                                                if (typeof test.ilsevent == 'undefined') {
-                                                       alert('Rename aborted.  Another copy has that barcode');
+                                               alert('Rename aborted.  Another copy has barcode "' + new_bc + '".');
                                                        return;
+                                               } else {
+                                                       if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
+                                                       obj.error.standard_unexpected_error_alert('Error testing replacement barcode "' . new_bc . '".',test);
+                                                               return;
+                                                       }       
                                                }
+
                                                copy.barcode(new_bc); copy.ischanged('1');
                                                var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
-                                               if (typeof r.ilsevent != 'undefined') { if (r.ilsevent != 0) throw(r); }
+                                               if (typeof r.ilsevent != 'undefined') { 
+                            if (r.ilsevent != 0) {
+                                if (r.ilsevent == 5000 /* PERM_FAILURE */) {
+                                    alert('Renamed aborted.  Insufficient permission.');
+                                } else {
+                                    obj.error.standard_unexpected_error_alert('Error renaming item.',r);
+                                }
+                            }
+                        }
                                        } catch(E) {
                                                obj.error.standard_unexpected_error_alert('Rename did not likely occur.',copy);
                                        }
index 627e232..c8b4c49 100644 (file)
@@ -17,34 +17,63 @@ cat.util.replace_barcode = function(old_bc) {
                if (!old_bc) old_bc = window.prompt('Enter original barcode for the copy:','','Replace Barcode');
                if (!old_bc) return;
 
-               var copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
-               if (typeof copy.ilsevent != 'undefined') throw(copy); 
-               if (!copy) throw(copy);
-
+               var copy;
+        try {
+                       copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
+                       if (typeof copy.ilsevent != 'undefined') throw(copy); 
+                       if (!copy) throw(copy);
+               } catch(E) {
+                       alert('We were unable to retrieve an item with barcode "' + old_bc + '".\n');
+                       return old_bc;
+               }
+       
                // Why did I want to do this twice?  Because this copy is more fleshed?
-               copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
-               if (typeof copy.ilsevent != 'undefined') throw(copy);
-               if (!copy) throw(copy);
-
-               var new_bc = window.prompt('Enter the replacement barcode for the copy with barcode ' + old_bc + ':','','Replace Barcode');
+               try {
+                       copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
+                       if (typeof copy.ilsevent != 'undefined') throw(copy);
+                       if (!copy) throw(copy);
+               } catch(E) {
+                       try { alert('We were unable to retrieve an item with barcode "' + old_bc + '".\n' + (typeof E.ilsevent == 'undefined' ? '' : E.textcode + ' : ' + E.desc)); } catch(F) { alert(E + '\n' + F); }
+                       return old_bc;
+               }
+       
+               var new_bc = window.prompt('Enter the replacement barcode for the copy:','','Replace Barcode');
                new_bc = String( new_bc ).replace(/\s/g,'');
                if (!new_bc) {
                        alert('Rename aborted.  Blank for barcode not allowed.');
                        return old_bc;
                }
-
-               var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ ses(), new_bc ]);
+       
+               var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
                if (typeof test.ilsevent == 'undefined') {
-                       alert('Rename aborted.  Another copy has that barcode');
+                       alert('Rename aborted.  Another copy has barcode "' + new_bc + '".');
                        return old_bc;
+               } else {
+                       if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
+                               obj.error.standard_unexpected_error_alert('Error testing replacement barcode "' . new_bc . '".',test);
+                               return old_bc;
+                       }       
                }
+
                copy.barcode(new_bc); copy.ischanged('1');
                var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
-               if (typeof r.ilsevent != 'undefined') { if (r.ilsevent != 0) throw(r); }
+               if (typeof r.ilsevent != 'undefined') { 
+                       if (r.ilsevent != 0) {
+                               if (r.ilsevent == 5000 /* PERM_FAILURE */) {
+                                       alert('Renamed aborted.  Insufficient permission.');
+                                       return old_bc;
+                               } else {
+                                       obj.error.standard_unexpected_error_alert('Error renaming item.',r);
+                                       return old_bc;
+                               }
+                       }
+               }
+
                return new_bc;
        } catch(E) {
                JSAN.use('util.error'); var error = new util.error();
                error.standard_unexpected_error_alert('Rename did not likely occur.',E);
+               return old_bc;
        }
 }