Author:   Lars Michelsen <[email protected]>
Date:     Fri Aug 26 15:43:17 2011 +0200
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Fri Aug 26 15:43:17 2011 +0200

Bugfix: Fixed wrong positions of controls during page load (at least in firefox)

---

 ChangeLog                                          |    1 +
 share/frontend/nagvis-js/js/NagVisObject.js        |   15 +++--
 .../frontend/nagvis-js/js/NagVisStatefulObject.js  |   77 +++++---------------
 3 files changed, 29 insertions(+), 64 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bb1d73b..61a9d8f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,7 @@ Frontend
   * Bugfix: Fixed backendid showing up in host_name field of add/modify dialog
     in some rare cases
   * Bugfix: Object positions can never be floats (always integers)
+  * Bugfix: Fixed wrong positions of controls during page load (at least in 
firefox)
 
 Automap
   * Bugfix: Made the problem automap work again
diff --git a/share/frontend/nagvis-js/js/NagVisObject.js 
b/share/frontend/nagvis-js/js/NagVisObject.js
index 69bc4d7..62904e9 100644
--- a/share/frontend/nagvis-js/js/NagVisObject.js
+++ b/share/frontend/nagvis-js/js/NagVisObject.js
@@ -796,16 +796,19 @@ var NagVisObject = Base.extend({
             this.childs[i].reposition();
 
         // redraw the controls
-        if(!this.bIsLocked) {
-            if(typeof(this.removeControls) == 'function')
-                this.removeControls();
-            if(typeof(this.parseControls) == 'function')
-                this.parseControls();
-        }
+        if(!this.bIsLocked)
+            this.redrawControls();
     },
 
     /*** CONTROL FUNCTIONS ***/
 
+    redrawControls: function () {
+        if(typeof(this.removeControls) == 'function')
+            this.removeControls();
+        if(typeof(this.parseControls) == 'function')
+            this.parseControls();
+    },
+
     parseControls: function () {
         // Ensure the controls container exists
         var oControls = 
document.getElementById(this.conf.object_id+'-controls');
diff --git a/share/frontend/nagvis-js/js/NagVisStatefulObject.js 
b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
index 4e0b767..1a7d9de 100644
--- a/share/frontend/nagvis-js/js/NagVisStatefulObject.js
+++ b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
@@ -187,9 +187,7 @@ var NagVisStatefulObject = NagVisObject.extend({
         oContainerDiv.setAttribute('id', this.conf.object_id);
 
         // Parse icon on automap
-        var oIcon = this.parseAutomapIcon();
-        oContainerDiv.appendChild(oIcon);
-        oIcon = null;
+        oContainerDiv.appendChild(this.parseIcon());
 
         // Parse label when configured
         if(this.conf.label_show && this.conf.label_show == '1') {
@@ -302,6 +300,7 @@ var NagVisStatefulObject = NagVisObject.extend({
             oObj.oncontextmenu  = null;
             oObj.onmouseover    = null;
             oObj.onmouseout     = null;
+            oObj.onload         = null;
             oObj = null;
         }
 
@@ -799,57 +798,6 @@ var NagVisStatefulObject = NagVisObject.extend({
     },
 
     /**
-     * PUBLIC parseAutomapIcon()
-     *
-     * Parses the HTML-Code of an automap icon
-     *
-     * @return String          String with Html Code
-     * @author Lars Michelsen <[email protected]>
-     */
-    parseAutomapIcon: function () {
-        var alt = '';
-
-        if(this.type == 'service') {
-            alt = this.conf.name+'-'+this.conf.service_description;
-        } else {
-            alt = this.conf.name;
-        }
-
-        var doc = document;
-        var oIcon = doc.createElement('img');
-        oIcon.setAttribute('id', this.conf.object_id+'-icon');
-        oIcon.src = oGeneralProperties.path_iconsets + this.conf.icon;
-        oIcon.alt = this.conf.type + '-' + alt;
-
-        var oIconDiv = doc.createElement('div');
-        oIconDiv.setAttribute('id', this.conf.object_id+'-icondiv');
-        oIconDiv.setAttribute('class', 'icon');
-        oIconDiv.setAttribute('className', 'icon');
-        oIconDiv.style.position = 'absolute';
-        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
-        if(this.conf.url && this.conf.url !== '' && this.conf.url !== '#') {
-            var oIconLink = doc.createElement('a');
-            oIconLink.href = this.conf.url;
-            oIconLink.target = this.conf.url_target;
-            oIconLink.appendChild(oIcon);
-            oIcon = null;
-
-            oIconDiv.appendChild(oIconLink);
-            oIconLink = null;
-        } else {
-            oIconDiv.appendChild(oIcon);
-            oIcon = null;
-        }
-
-        doc = null;
-        return oIconDiv;
-    },
-
-    /**
      * PUBLIC parseIcon()
      *
      * Parses the HTML-Code of an icon
@@ -869,6 +817,21 @@ var NagVisStatefulObject = NagVisObject.extend({
         var doc = document;
         var oIcon = doc.createElement('img');
         oIcon.setAttribute('id', this.conf.object_id+'-icon');
+
+        // Register controls reposition handler to handle resizes during
+        // loading the image (from alt="" text to the real image
+        oIcon.onload = function() {
+            // In the event handler "this" points to the image object
+            var arr   = this.id.split('-');
+            var objId = arr[0];
+            var obj = getMapObjByDomObjId(objId);
+           if(!obj.bIsLocked)
+                obj.redrawControls();
+            obj = null;
+            objId = null;
+            arr = null;
+        };
+
         oIcon.src = oGeneralProperties.path_iconsets + this.conf.icon;
         oIcon.alt = this.conf.type + '-' + alt;
 
@@ -1112,10 +1075,8 @@ var NagVisStatefulObject = NagVisObject.extend({
         saveObjectAttr(this.conf.object_id, { 'x': this.conf.x, 'y': 
this.conf.y});
 
         // redraw the controls
-        if(!this.bIsLocked) {
-            this.removeControls();
-            this.parseControls();
-        }
+        if(!this.bIsLocked)
+            this.redrawControls();
 
         // redraw the line
         this.drawLine();


------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to