From 32edfd12e83ef70e24f43dbbd7bd61ce02fd6335 Mon Sep 17 00:00:00 2001 From: hadeshyp Date: Sun, 4 Nov 2012 22:05:39 +0000 Subject: [PATCH] Error in delay computation when entering pulser frequency. Added error message, when connection error occurs --- cts/htdocs/scripts/base.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cts/htdocs/scripts/base.js b/cts/htdocs/scripts/base.js index 54c7a40..9a0b146 100644 --- a/cts/htdocs/scripts/base.js +++ b/cts/htdocs/scripts/base.js @@ -95,7 +95,7 @@ var CTS = new Class({ }, readRegisters: function(regs, callback, formated) { - var opts = {'url': 'cts.pl?' + (formated ? "format" : "read") + ',' + Array.from(regs).join(",")}; + var opts = {'onFailure':xhrFailure, 'url': 'cts.pl?' + (formated ? "format" : "read") + ',' + Array.from(regs).join(",")}; if (callback) { opts['onSuccess'] = callback; return (new Request.JSON(opts)).send(); @@ -118,11 +118,7 @@ var CTS = new Class({ else alert("An unknown error occured while writing register"); } }, - onFailure: function(xhr){ - var m = xhr.responseText.match(/
([\s\S]*)<\/pre>/im);
-               if (m) alert("Server send error response:\n"+m[1].trim());
-               else  alert("An unknown error occured while writing register");
-         }
+         onFailure: xhrFailure
       })).send();
    },
    
@@ -187,11 +183,12 @@ var CTS = new Class({
             this.autoCommitInhibit = false;
          }.bind(this),
             
-         onFailure:    function() {
+         onFailure:    function(xhr) {
             window.clearTimeout(manualTimeout);
             this.dataUpdate.delay(1000, this);
             dup.addClass('error').set('text', 'Update failed').setStyle('display', 'block');
             $('status-indicator').set('class', 'error');
+            xhrFailure(xhr);
          }.bind(this)
       }).send();
    },
@@ -298,7 +295,7 @@ var CTS = new Class({
             value = (e.get('checked') != "" ? '1' : '0');
             
          if (e.interpret || e.get('interpret')) {
-            value = parseCallback(e, 'interpret')(value, e);
+            value = parseInt(Math.round( parseCallback(e, 'interpret')(value, e) ));
             
             if (e.format || e.get('format')) {
                if (e.get('type') == 'checkbox') 
@@ -669,10 +666,17 @@ var CTS = new Class({
    }
 });
 
+function xhrFailure(xhr){
+   var m = xhr.responseText.match(/
([\s\S]*)<\/pre>/im);
+   if (m) alert("Server send error response:\n"+m[1].trim());
+   else  alert("An unknown error while contacting the sever. Did you open this file locally? Did the connection crash?");
+}
+
+
 var cts;
 (new Request.JSON({'url': 'cts.pl?init',
                    'onSuccess': function(json) {cts = new CTS(json)},
-                   'onError': function() {alert("Error while fetching CTS definitions. Did you open this file locally???");}})).send();
+                   'onFailure': xhrFailure})).send();
    
 function countToTime(val) {return (1.0*val / cts.defs.properties.cts_clock_frq * 1e9).toFixed(0);}
 function countToFreq(val) {return formatFreq (1 / (val / cts.defs.properties.cts_clock_frq)); }
-- 
2.43.0