Small fix to avoid ajax hangups after nonexistent element update.
[fa-stable.git] / js / utils.js
index 9380db34c6bdb3adf35d3bf38c17891d391c89d5..877af9ad60cc4eab67c98fe540724e2d56512538 100644 (file)
@@ -9,10 +9,13 @@
 //             request is directed to current location 
 // 
     JsHttpRequest.request= function(trigger, form) {
+               var mark = document.getElementById('ajaxmark');
+               if(mark) mark.style.visibility = 'visible';
                if (trigger.tagName=='A') {
                        var content = {};
                        var upload = 0;
                        var url = trigger.href;
+                       if (trigger.id) content[trigger.id] = 1;
                } else {
                var submitObj = typeof(trigger) == "string" ? 
                        document.getElementsByName(trigger)[0] : trigger;
@@ -41,6 +44,7 @@
             // Function is called when an answer arrives. 
            function(result, errors) {
                 // Write the answer.
+                       var newwin = 0;
                if (result) {
                          for(var i in result ) { 
                          atom = result[i];
@@ -52,6 +56,7 @@
 //                             debug(cmd+':'+property+':'+type+':'+id);
                        // seek element by id if there is no elemnt with given name
                          objElement = document.getElementsByName(id)[0] || document.getElementById(id);
+                         if(!objElement) continue;
                  if(cmd=='as') {
                                  eval("objElement.setAttribute('"+property+"',"+data+");");
                          } else if(cmd=='up') {
@@ -69,6 +74,7 @@
                          } else if(cmd=='rd') {        // client-side redirection
                                  window.location = data;
                          } else if(cmd=='pu') {        // pop-up
+                                 newwin = 1;
                                  window.open(data,'REP_WINDOW','toolbar=no,scrollbar=no,resizable=yes,menubar=no');
                          } else {
                                  errors = errors+'<br>Unknown ajax function: '+cmd;
 
         // Write errors to the debug div.
                  document.getElementById('msgbox').innerHTML = errors;
+                 var mark = document.getElementById('ajaxmark');
+                 if(mark) mark.style.visibility = 'hidden';
 
                  Behaviour.apply();
+
                  if (errors.length>0)
                        window.scrollTo(0,0);
                        //document.getElementById('msgbox').scrollIntoView(true);
          // Restore focus if we've just lost focus because of DOM element refresh
-                 setFocus();
+                       if(!newwin) { 
+                               setFocus();
+                       }
                }
             },
             false  // do not disable caching