Module: nagvis
Branch: nagvis-1.5
Commit: 8980b0d87470da843a02342627186d7f3afc17e7
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=8980b0d87470da843a02342627186d7f3afc17e7

Author: Lars Michelsen <[email protected]>
Date:   Sat Dec 11 12:49:21 2010 +0100

Preventing damaged map cfg due to textbox resizing in IE (which happens in some 
rare cases)

---

 ChangeLog                             |    4 +++
 share/frontend/nagvis-js/js/nagvis.js |   18 ++++++++++++++++
 share/frontend/wui/js/wui.js          |   36 +++++++++++++++++++-------------
 3 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1310c39..37a33a8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,10 @@ Core
 Automap
   * Hiding deprecated maxLayers param from automap modify dialog
 
+WUI
+  * Preventing damaged map cfg due to textbox resizing in IE (only happens in
+       some rare cases)
+
 1.5.6
 
 Core
diff --git a/share/frontend/nagvis-js/js/nagvis.js 
b/share/frontend/nagvis-js/js/nagvis.js
index 01b2712..5bf1d03 100644
--- a/share/frontend/nagvis-js/js/nagvis.js
+++ b/share/frontend/nagvis-js/js/nagvis.js
@@ -1017,3 +1017,21 @@ function lightenColor(code, rD, gD, bD) {
 function isset(v) {
        return typeof(v) !== 'undefined';
 }
+
+/**
+ * Checks if a variable is an integer
+ *
+ * @author  Lars Michelsen <[email protected]>
+ */
+function isInt(v) {
+  return parseFloat(v) == parseInt(v) && !isNaN(v);
+}
+
+/**
+ * Helper to parse px values from dom to numbers
+ *
+ * @author  Lars Michelsen <[email protected]>
+ */
+function pxToInt(v) {
+       return parseInt(v.replace('px', ''));
+}
diff --git a/share/frontend/wui/js/wui.js b/share/frontend/wui/js/wui.js
index 1c330ff..262bc3c 100644
--- a/share/frontend/wui/js/wui.js
+++ b/share/frontend/wui/js/wui.js
@@ -336,10 +336,15 @@ function saveObjectAfterResize(oObj) {
        var type = arr[1];
        var id = arr[2];
        
-       var objX = parseInt(oObj.style.left.replace('px', ''));
-       var objY = parseInt(oObj.style.top.replace('px', ''));
+       var objX = pxToInt(oObj.style.left);
+       var objY = pxToInt(oObj.style.top);
        var objW = parseInt(oObj.style.width);
        var objH = parseInt(oObj.style.height);
+
+       if(!isInt(objX) || !isInt(objY) || !isInt(objW) || !isInt(objH)) {
+               alert('ERROR: Invalid coords 
('+objX+'/'+objY+'/'+objW+'/'+objH+'). Terminating.');
+               return false;
+       }
        
        // Don't forget to substract height of header menu
        var url = 
oGeneralProperties.path_server+'?mod=Map&act=modifyObject&map='+mapname+'&type='+type+'&id='+id+'&x='+objX+'&y='+objY+'&w='+objW+'&h='+objH;
@@ -378,7 +383,7 @@ function saveObjectAfterMoveAndDrop(oObj) {
        }
        
        // Handle different ojects (Normal icons and labels)
-       var type, id , url;
+       var type, id, url = '';
        if(arr[1] === 'label') {
                var align = arr[0];
                type = arr[2];
@@ -388,8 +393,8 @@ function saveObjectAfterMoveAndDrop(oObj) {
                // Handle relative and absolute aligned labels
                if(align === 'rel') {
                        // Calculate relative coordinates
-                       var objX = 
parseInt(document.getElementById('box_'+type+'_'+id).style.left.replace('px', 
''));
-                       var objY = 
parseInt(document.getElementById('box_'+type+'_'+id).style.top.replace('px', 
''));
+                       var objX = 
pxToInt(document.getElementById('box_'+type+'_'+id).style.left);
+                       var objY = 
pxToInt(document.getElementById('box_'+type+'_'+id).style.top);
                        
                        // +3: Is the borderWidth of the object highlighting.
                        // The header menu height is not needed when 
calculating relative coords
@@ -398,17 +403,13 @@ function saveObjectAfterMoveAndDrop(oObj) {
                        
                        // Add + sign to mark relative positive coords (On 
negative relative coord
                        // the - sign is added automaticaly
-                       if(x >= 0) {
-                               // %2B is escaped +
+                       // %2B is escaped +
+                       if(x >= 0)
                                x = '%2B'+x;
-                       }
-                       if(y >= 0) {
-                               // %2B is escaped +
+                       if(y >= 0)
                                y = '%2B'+y;
-                       }
                } else {
                        x = oObj.x;
-                       // Substract height of header menu here
                        y = oObj.y;
                }
                
@@ -422,7 +423,12 @@ function saveObjectAfterMoveAndDrop(oObj) {
                y = oObj.y + borderWidth;
 
                // Don't forget to substract height of header menu
-               url = 
oGeneralProperties.path_server+'?mod=Map&act=modifyObject&map='+mapname+'&type='+type+'&id='+id+'&x='+x+'&y='+y;
+               if(isInt(x) && isInt(y)) {
+                       url = 
oGeneralProperties.path_server+'?mod=Map&act=modifyObject&map='+mapname+'&type='+type+'&id='+id+'&x='+x+'&y='+y;
+               } else {
+                       alert('ERROR: Invalid coords ('+x+'/'+y+'). 
Terminating.');
+                       return false;
+               }
        }
        
        // Sync ajax request
@@ -701,8 +707,8 @@ function toggleBorder(oObj, state){
        
        var oContainer = oObj.parentNode;
 
-       var top = parseInt(oContainer.style.top.replace('px', ''));
-       var left = parseInt(oContainer.style.left.replace('px', ''));
+       var top = pxToInt(oContainer.style.top);
+       var left = pxToInt(oContainer.style.left);
 
        var parts = oObj.id.split('_');
        var type  = parts[1];


------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to