Module: nagvis Branch: master Commit: f92f01872289b11b51c19709da1ae426a33c5679 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=f92f01872289b11b51c19709da1ae426a33c5679
Author: Lars Michelsen <[email protected]> Date: Sat Dec 11 12:53:24 2010 +0100 Preventing damaged map cfg due to textbox resizing in IE (which happens in some rare cases) Conflicts: ChangeLog share/frontend/nagvis-js/js/nagvis.js --- ChangeLog | 2 + share/frontend/nagvis-js/js/nagvis.js | 18 ++++++++++++++++ share/frontend/wui/js/wui.js | 36 +++++++++++++++++++------------- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index de2c60e..040126c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -57,3 +57,5 @@ WUI * Bugfix: Inconsistency between textbox style attribute usage in frontend and WUI * Bugfix: Relative label coordinates were calculated wrong when moving objects * The textbox height is now set correctly when creating a new textbox + * Preventing damaged map cfg due to textbox resizing in IE (only happens in + some rare cases) diff --git a/share/frontend/nagvis-js/js/nagvis.js b/share/frontend/nagvis-js/js/nagvis.js index 3e73056..565128c 100644 --- a/share/frontend/nagvis-js/js/nagvis.js +++ b/share/frontend/nagvis-js/js/nagvis.js @@ -1198,3 +1198,21 @@ if (window.addEventListener) { return false; }; } + +/** + * 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 223b564..7d2430c 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
