Bug 6977: Follow-up patch : catch CloneSubfield errors
authorFrédérick Capovilla <frederick.capovilla@libeo.com>
Fri, 21 Oct 2011 16:04:03 +0000 (12:04 -0400)
committerPaul Poulain <paul.poulain@biblibre.com>
Fri, 18 Nov 2011 21:45:45 +0000 (22:45 +0100)
A javascript error could occur if the CloneSubfield function failed for
any reason. This would prevent the popup from disappearing.

Example : Importing informations of a UNIF_TITLE authority with multiple
$x subfields in the biblio's 440 field. 440$x isn't repeatable, so an
error occurs when trying to clone it.

http://bugs.koha-community.org/show_bug.cgi?id=6977
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
koha-tmpl/intranet-tmpl/prog/en/modules/authorities/blinddetail-biblio-search.tt

index 1697289..77a5d5f 100644 (file)
         }
 
         // Sets the good number of form fields for the specified subfield
+        // Returns false if the cloning failed
         function SetSubfieldNumber(subfield_name, nb) {
             // Nothing to do if we only have one value
             if(nb <= 1) {
-                return;
+                return true;
             }
             
             // Find the subfield we want to clone
                 return this.id.match(re);
             });
 
-            // Add as many clones as needed
-            for(var i=0; i<nb-subfields.length; i++) {
-                window.opener.opener.CloneSubfield(subfields[0].getAttribute('id'));
+            // Try to add as many clones as needed
+            try {
+                for(var i=0; i<nb-subfields.length; i++) {
+                    window.opener.opener.CloneSubfield(subfields[0].getAttribute('id'));
+                }
+            }
+            catch(err) {
+                return false;
             }
+            return true;
         }
 
         // Fills the subfield with the values entered in argument
@@ -61,6 +68,7 @@
             }
 
             // Create the correct number of form fields for all values
+            // If the field cloning failed, only the first value will be added to the form.
             SetSubfieldNumber(subfield_name, values.length);
             
             // Find the subfields where we will add the new values