Module: nagvis
Branch: master
Commit: 1ce517aaaf2137c7ad879622704cff75ccbbf2ac
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis/nagvis;a=commit;h=1ce517aaaf2137c7ad879622704cff75ccbbf2ac

Author: Lars Michelsen <[email protected]>
Date:   Thu Sep 24 18:15:10 2009 +0200

#121 Fixed ticket by removing the context menu explicit on object remove from 
map and only creating a new context div when there is no one existing

---

 share/frontend/nagvis-js/js/NagVisObject.js        |   15 ++++++++++-----
 .../frontend/nagvis-js/js/NagVisStatefulObject.js  |   16 ++++++++++++----
 share/frontend/nagvis-js/js/frontend.js            |    3 ++-
 share/frontend/nagvis-js/js/frontendContext.js     |    7 +++++++
 4 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/share/frontend/nagvis-js/js/NagVisObject.js 
b/share/frontend/nagvis-js/js/NagVisObject.js
index 89b866b..d5b9159 100755
--- a/share/frontend/nagvis-js/js/NagVisObject.js
+++ b/share/frontend/nagvis-js/js/NagVisObject.js
@@ -70,7 +70,7 @@ var NagVisObject = Base.extend({
         *
         * @author      Lars Michelsen <[email protected]>
         */
-       getContextMenu: function (sContainerId, sObjId) {
+       getContextMenu: function (sObjId) {
                // Only enable context menu when configured
                if(this.conf.context_menu && this.conf.context_menu == '1') {
                        // Writes template code to "this.context_template_code"
@@ -80,11 +80,16 @@ var NagVisObject = Base.extend({
                        this.replaceContextTemplateMacros();
                        
                        var oObj = document.getElementById(sObjId);
-                       var oContainer = document.getElementById(sContainerId);
+                       var oContainer = 
document.getElementById(this.conf.object_id);
+                       
+                       // Only create a new div when the context menu does not 
exist
+                       var contextMenu = 
document.getElementById(this.conf.object_id+'-context');
+                       if(!contextMenu) {
+                               // Create context menu div
+                               var contextMenu = document.createElement('div');
+                               contextMenu.setAttribute('id', 
this.conf.object_id+'-context');
+                       }
                        
-                       // Create context menu div
-                       var contextMenu = document.createElement('div');
-                       contextMenu.setAttribute('id', sObjId+'-context');
                        contextMenu.setAttribute('class', 'context');
                        contextMenu.setAttribute('className', 'context');
                        contextMenu.style.zIndex = '1000';
diff --git a/share/frontend/nagvis-js/js/NagVisStatefulObject.js 
b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
index 2d8cff5..70425d3 100755
--- a/share/frontend/nagvis-js/js/NagVisStatefulObject.js
+++ b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
@@ -193,8 +193,7 @@ var NagVisStatefulObject = NagVisObject.extend({
        remove: function () {
                if(this.parsedObject) {
                        var oMap = document.getElementById('map');
-                       
-                       // Remove event listeners
+
                        var oObj;
                        if(this.conf.view_type && this.conf.view_type === 
'line') {
                                oObj = 
document.getElementById(this.conf.object_id+'-linediv');
@@ -203,12 +202,21 @@ var NagVisStatefulObject = NagVisObject.extend({
                        }
                        
                        if(oObj) {
+                               // Remove event listeners
                                oObj.onmousedown = null;
                                oObj.oncontextmenu = null;
                                oObj.onmouseover = null;
                                oObj.onmouseout = null;
                                oObj = null;
                        }
+
+                       var oContext = 
document.getElementById(this.conf.object_id+'-context');
+                       // Remove context menu
+                       // Needs to be removed after unsetting the eventhandlers
+                       if(oContext) {
+                               this.parsedObject.removeChild(oContext);
+                               oContext = null;
+                       }
                        
                        // Remove object from DOM
                        oMap.removeChild(this.parsedObject);
@@ -258,9 +266,9 @@ var NagVisStatefulObject = NagVisObject.extend({
     // Add a context menu to the object when enabled
     if(this.conf.context_menu && this.conf.context_menu == '1') {
       if(this.conf.view_type && this.conf.view_type == 'line') {
-        this.getContextMenu(this.conf.object_id, this.conf.object_id+'-link');
+        this.getContextMenu(this.conf.object_id+'-link');
       } else {
-        this.getContextMenu(this.conf.object_id, this.conf.object_id+'-icon');
+        this.getContextMenu(this.conf.object_id+'-icon');
                        }
     }
        },
diff --git a/share/frontend/nagvis-js/js/frontend.js 
b/share/frontend/nagvis-js/js/frontend.js
index daca06e..42724fa 100755
--- a/share/frontend/nagvis-js/js/frontend.js
+++ b/share/frontend/nagvis-js/js/frontend.js
@@ -540,7 +540,8 @@ function updateObjects(aMapObjectInformations, aObjs, 
sType) {
                aObjs[intIndex].parseHoverMenu();
                
                // Reparse the context menu
-               // FIXME: Context menu is not available on the overview page
+               // The context menu only needs to be reparsed when the
+               // icon object has been reparsed
                if(sType === 'map') {
                        aObjs[intIndex].parseContextMenu();
                } else if(sType === 'overview') {
diff --git a/share/frontend/nagvis-js/js/frontendContext.js 
b/share/frontend/nagvis-js/js/frontendContext.js
index fb6c35b..7cbed1a 100644
--- a/share/frontend/nagvis-js/js/frontendContext.js
+++ b/share/frontend/nagvis-js/js/frontendContext.js
@@ -132,6 +132,13 @@ function contextShow(event) {
                        id = target.id;
                }
                
+               // Only the object id is interesing so remove the other contents
+               // like -icon or -line. Simply split the string by - and take 
the
+               // first element
+               var aId = id.split("-");
+               id = aId[0];
+               aId = null;
+               
                var contextMenu = document.getElementById(id+'-context');
                
                // hide the menu first to avoid an "up-then-over" visual effect


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to