Module: nagvis Branch: master Commit: f72b5a94b9ff5d652ec11ba546a3e78518fa0740 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=f72b5a94b9ff5d652ec11ba546a3e78518fa0740
Author: Lars Michelsen <[email protected]> Date: Wed Jan 19 17:14:24 2011 +0100 Prep for relative coords --- share/frontend/nagvis-js/js/NagVisObject.js | 44 ++++++++++++++++++++ .../frontend/nagvis-js/js/NagVisStatefulObject.js | 32 +++++++------- share/server/core/classes/GlobalMapCfg.php | 12 +++--- share/server/core/defines/matches.php | 4 +- 4 files changed, 68 insertions(+), 24 deletions(-) diff --git a/share/frontend/nagvis-js/js/NagVisObject.js b/share/frontend/nagvis-js/js/NagVisObject.js index 13e2533..0871d25 100644 --- a/share/frontend/nagvis-js/js/NagVisObject.js +++ b/share/frontend/nagvis-js/js/NagVisObject.js @@ -383,5 +383,49 @@ var NagVisObject = Base.extend({ } } return false; + }, + + /** + * This method parses a given coordinate which can be a simple integer + * which is simply returned or a reference to another object and/or + * a specified anchor of the object. + * + * @author Lars Michelsen <[email protected]> + */ + parseCoord: function(val, dir) { + if(isInt(val)) { + return parseInt(val); + } else { + // This must be an object id. Is there an anchor given? + if(val.search('%') !== -1) { + var parts = val.split('%'); + var objectId = parts[0]; + var anchor = parts[1]; + var refObj = getMapObjByDomObjId(objectId); + } else { + alert(val); + // Only an object id. Get the coordinate and return it + var refObj = getMapObjByDomObjId(val); + if(refObj !== -1) + return refObj.conf[dir]; + else + return val; + } + } + }, + + /** + * Wrapper for the parseCoord method to parse multiple coords at once + * e.g. for lines. + * + * @author Lars Michelsen <[email protected]> + */ + parseCoords: function(val, dir) { + var l = val.split(','); + + for(var i = 0, len = l.length; i < len; i++) + l[i] = this.parseCoord(l[i], dir); + + return l; } }); diff --git a/share/frontend/nagvis-js/js/NagVisStatefulObject.js b/share/frontend/nagvis-js/js/NagVisStatefulObject.js index ab521d1..c7caf7d 100644 --- a/share/frontend/nagvis-js/js/NagVisStatefulObject.js +++ b/share/frontend/nagvis-js/js/NagVisStatefulObject.js @@ -470,8 +470,8 @@ var NagVisStatefulObject = NagVisObject.extend({ * @author Lars Michelsen <[email protected]> */ drawLine: function() { - var x = this.conf.x.split(','); - var y = this.conf.y.split(','); + var x = this.parseCoords(this.conf.x, 'x'); + var y = this.parseCoords(this.conf.y, 'y'); var width = this.conf.line_width; @@ -793,8 +793,8 @@ var NagVisStatefulObject = NagVisObject.extend({ oIconDiv.setAttribute('class', 'icon'); oIconDiv.setAttribute('className', 'icon'); oIconDiv.style.position = 'absolute'; - oIconDiv.style.top = this.conf.y+'px'; - oIconDiv.style.left = this.conf.x+'px'; + oIconDiv.style.top = this.parseCoord(this.conf.y, 'y')+'px'; + oIconDiv.style.left = this.parseCoord(this.conf.x, 'x')+'px'; oIconDiv.style.zIndex = this.conf.z; // Parse link only when set @@ -823,8 +823,8 @@ var NagVisStatefulObject = NagVisObject.extend({ */ moveIcon: function () { var container = document.getElementById(this.conf.object_id + '-icondiv'); - container.style.top = this.conf.y + 'px'; - container.style.left = this.conf.x + 'px'; + container.style.top = this.parseCoord(this.conf.y, 'y') + 'px'; + container.style.left = this.parseCoord(this.conf.x, 'x') + 'px'; container = null; }, @@ -876,7 +876,7 @@ var NagVisStatefulObject = NagVisObject.extend({ this.parseIconControls(); }, - parseControlDrag: function (num, x, y, size) { + parseControlDrag: function (num, objX, objY, offX, offY, size) { var drag = document.createElement('div'); drag.setAttribute('id', this.conf.object_id+'-drag-' + num); drag.setAttribute('class', 'control drag' + size); @@ -884,10 +884,10 @@ var NagVisStatefulObject = NagVisObject.extend({ drag.style.zIndex = parseInt(this.conf.z)+1; drag.style.width = size + 'px'; drag.style.height = size + 'px'; - drag.style.left = x + 'px'; - drag.style.top = y + 'px'; - drag.objOffsetX = x - this.conf.x; - drag.objOffsetY = y - this.conf.y; + drag.style.left = (objX + offX) + 'px'; + drag.style.top = (objY + offY) + 'px'; + drag.objOffsetX = offX; + drag.objOffsetY = offY; // Add to DOM document.getElementById(this.conf.object_id+'-controls').appendChild(drag); @@ -907,8 +907,8 @@ var NagVisStatefulObject = NagVisObject.extend({ parseIconControls: function () { this.getObjWidth(); var size = 10; - this.parseControlDrag(0, parseInt(this.conf.x) + this.getObjWidth() + 5, - parseInt(this.conf.y) - size/2, size); + this.parseControlDrag(0, this.parseCoord(this.conf.x, 'x'), this.parseCoord(this.conf.y, 'y'), + this.getObjWidth() + 5, - size / 2, size); size = null; // Simply make it dragable. Maybe will be extended in the future... @@ -916,12 +916,12 @@ var NagVisStatefulObject = NagVisObject.extend({ }, parseLineControls: function () { - var x = this.conf.x.split(','); - var y = this.conf.y.split(','); + var x = this.parseCoords(this.conf.x, 'x'); + var y = this.parseCoords(this.conf.y, 'y'); var size = 20; for(var i = 0, l = x.length; i < l; i++) { - this.parseControlDrag(i, x[i] - size/2, y[i] - size/2, size); + this.parseControlDrag(i, x[i], y[i], - size / 2, - size / 2, size); makeDragable([this.conf.object_id+'-drag-'+i], this.saveObject, this.moveObject); } size = null; diff --git a/share/server/core/classes/GlobalMapCfg.php b/share/server/core/classes/GlobalMapCfg.php index c212d6e..4211d2d 100644 --- a/share/server/core/classes/GlobalMapCfg.php +++ b/share/server/core/classes/GlobalMapCfg.php @@ -1292,12 +1292,12 @@ class GlobalMapCfg { 'text' => Array('must' => 1, 'match' => MATCH_ALL), 'x' => Array('must' => 1, - 'match' => MATCH_INTEGER), + 'match' => MATCH_COORDS), 'y' => Array('must' => 1, - 'match' => MATCH_INTEGER), + 'match' => MATCH_COORDS), 'z' => Array('must' => 0, 'default' => 5, - 'match' => MATCH_INTEGER), + 'match' => MATCH_COORDS), 'background_color' => Array('must' => 0, 'default' => '#C0C0C0', 'match' => MATCH_COLOR), @@ -1325,12 +1325,12 @@ class GlobalMapCfg { 'match' => MATCH_PNG_GIF_JPG_FILE_OR_URL, 'field_type' => 'dropdown'), 'x' => Array('must' => 1, - 'match' => MATCH_INTEGER), + 'match' => MATCH_COORDS), 'y' => Array('must' => 1, - 'match' => MATCH_INTEGER), + 'match' => MATCH_COORDS), 'z' => Array('must' => 0, 'default' => 1, - 'match' => MATCH_INTEGER), + 'match' => MATCH_COORDS), 'enable_refresh' => Array('must' => 0, 'default' => 0, 'match' => MATCH_BOOLEAN, diff --git a/share/server/core/defines/matches.php b/share/server/core/defines/matches.php index 37d8dcf..b3489fa 100644 --- a/share/server/core/defines/matches.php +++ b/share/server/core/defines/matches.php @@ -38,8 +38,8 @@ define('MATCH_STRING_URL', '/^[0-9a-z\s\:\+\[\]\(\)\=\%\?\&\_\,\.\-\#\@\=\/\\\]+ define('MATCH_STRING_URL_EMPTY', '/^[0-9a-z\s\:\+\[\]\(\)\=\%\?\&\_\,\.\-\#\@\=\/\\\]*$/i'); define('MATCH_GADGET_OPT', '/^[0-9a-z\s\:\+\[\]\(\)\_\.\,\-\&\?\!\#\@\=\/\\\%]+$/i'); define('MATCH_STRING_STYLE', '/^[0-9a-z\:\;\-\+\%]*$/i'); -define('MATCH_COORDS', '/^(?:(?:[0-9]+)|([a-z0-9]+%[0-9]+))$/'); -define('MATCH_COORDS_MULTI', '/^(?:(?:(?:[0-9]+)|([a-z0-9]+%[0-9]+))[\.\,]?)+$/'); +define('MATCH_COORDS', '/^(?:(?:[0-9]+)|([a-z0-9]+(?:%[0-9]+)?))$/'); +define('MATCH_COORDS_MULTI', '/^(?:(?:(?:[0-9]+)|([a-z0-9]+(?:%[0-9]+)?))[\.\,]?)+$/'); define('MATCH_INTEGER', '/^[0-9]+$/'); define('MATCH_INTEGER_EMPTY', '/^[0-9]*$/'); ------------------------------------------------------------------------------ Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
