Author:   Lars Michelsen <[email protected]>
Date:     Sun Jun  5 12:58:55 2011 +0200
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Sun Jun  5 12:58:55 2011 +0200

Labels of objects can now be moved again; The edit mode is affected by the 
objects lock/unlock state

---

 ChangeLog                                          |    1 +
 share/frontend/nagvis-js/js/NagVisObject.js        |    3 +
 .../frontend/nagvis-js/js/NagVisStatefulObject.js  |   93 +++++++++++++++++++-
 share/frontend/nagvis-js/js/edit.js                |   14 ++-
 share/frontend/nagvis-js/js/nagvis.js              |    2 +-
 5 files changed, 105 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b0e485f..677e982 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@ Core
   * Bugfix: Fixed redirects after map add/rename/delete
 
 Frontend
+  * Labels of objects can now be moved again; The edit mode is affected by the 
objects lock/unlock state
   * Bugfix: Added missing controls to services which are displayed as gadgets
   * Bugfix: Fixed parsing of label_type=14 lines (Thanks to Laurent Lebatard)
   * Bugfix: Label positioning in case of weathermap lines (Thanks to Laurent 
Lebatard)
diff --git a/share/frontend/nagvis-js/js/NagVisObject.js 
b/share/frontend/nagvis-js/js/NagVisObject.js
index 37e96a0..27c936d 100644
--- a/share/frontend/nagvis-js/js/NagVisObject.js
+++ b/share/frontend/nagvis-js/js/NagVisObject.js
@@ -392,6 +392,9 @@ var NagVisObject = Base.extend({
             this.bIsLocked = !this.bIsLocked;
 
         if(this.toggleObjControls()) {
+           if(typeof(this.toggleLabelLock) == 'function')
+               this.toggleLabelLock();
+
             if(!isset(lock)) {
                 if(oUserProperties.hasOwnProperty('unlocked-' + 
oPageProperties.map_name))
                 var unlocked = oUserProperties['unlocked-' + 
oPageProperties.map_name].split(',');
diff --git a/share/frontend/nagvis-js/js/NagVisStatefulObject.js 
b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
index e903a67..5a2a340 100644
--- a/share/frontend/nagvis-js/js/NagVisStatefulObject.js
+++ b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
@@ -264,8 +264,10 @@ var NagVisStatefulObject = NagVisObject.extend({
             this.drawLine();
 
         // Enable the controls when the object is not locked
-        if(!this.bIsLocked)
+        if(!this.bIsLocked) {
             this.parseControls();
+           this.unlockLabel();
+       }
     },
 
     /**
@@ -857,7 +859,7 @@ var NagVisStatefulObject = NagVisObject.extend({
     },
 
     /**
-     * Moves the label of the object
+     * Moves the label of the object after the objec thas been dragged
      *
      * @author Lars Michelsen <[email protected]>
      */
@@ -871,6 +873,60 @@ var NagVisStatefulObject = NagVisObject.extend({
     },
 
     /**
+     * Handles drag events of the label
+     *
+     * This needs to calculate the offset of the current position to the first 
position,
+     * then create a new coord (relative/absolue) and save them in label_x/y 
attributes
+     *
+     * @author Lars Michelsen <[email protected]>
+     */
+    dragLabel: function(obj) {
+        var arr        = obj.id.split('-');
+        var objId      = arr[0];
+        var anchorType = arr[1];
+
+        var viewType = getDomObjViewType(objId);
+
+        var jsObj = getMapObjByDomObjId(objId);
+
+        jsObj.conf.label_x = jsObj.calcNewLabelCoord(jsObj.conf.label_x, 
jsObj.conf.x, obj.x);
+        jsObj.conf.label_y = jsObj.calcNewLabelCoord(jsObj.conf.label_y, 
jsObj.conf.y, obj.y);
+
+        jsObj      = null;
+        objId      = null;
+        anchorType = null;
+        viewType   = null;
+    },
+
+    /**
+     * Calculates relative/absolute coords depending on the current configured 
type
+     */
+    calcNewLabelCoord: function (labelCoord, coord, newCoord) {
+       if(labelCoord.toString().match(/^(?:\+|\-)/)) {
+           var ret = newCoord - coord;
+           if(ret >= 0)
+               return '+' + ret;
+           return ret;
+       } else
+           return newCoord;
+    },
+
+    /**
+     * Handler for the drop event
+     *
+     * Important: This is called from an event handler
+     * the 'this.' keyword can not be used here.
+     */
+    saveLabel: function(obj, oParent) {
+        var arr        = obj.id.split('-');
+        var objId      = arr[0];
+        var jsObj      = getMapObjByDomObjId(objId);
+        saveObjectAttr(objId, { 'label_x': jsObj.conf.label_x, 'label_y': 
jsObj.conf.label_y});
+       jsObj = null;
+       arr   = null;
+    },
+
+    /**
      * Calculates and returns the positions of the objects label
      *
      * @author Lars Michelsen <[email protected]>
@@ -916,6 +972,39 @@ var NagVisStatefulObject = NagVisObject.extend({
                                  this.conf.label_style);
     },
 
+    unlockLabel: function () {
+       var o = document.getElementById(this.conf.object_id + '-label');
+       if(!o)
+           return;
+       o.onmouseover = function() {
+            document.body.style.cursor = 'move';
+        };
+        o.onmouseout = function() {
+            document.body.style.cursor = 'auto';
+        };
+
+       makeDragable([o], this.saveLabel, this.dragLabel);
+       o = null;
+    },
+
+    lockLabel: function () {
+       var o = document.getElementById(this.conf.object_id + '-label');
+       if(!o)
+           return;
+       // Clone the node to remove all attached event handlers
+       var n = o.cloneNode(true);
+       o.parentNode.replaceChild(n, o);
+       o = null;
+       n = null;
+    },
+
+    toggleLabelLock: function () {
+       if(this.bIsLocked)
+           this.lockLabel();
+       else
+           this.unlockLabel();
+    },
+
     getObjWidth: function () {
         return parseInt(document.getElementById(this.conf.object_id + 
'-icondiv').clientWidth);
     },
diff --git a/share/frontend/nagvis-js/js/edit.js 
b/share/frontend/nagvis-js/js/edit.js
index 3a49f39..6f8b97c 100644
--- a/share/frontend/nagvis-js/js/edit.js
+++ b/share/frontend/nagvis-js/js/edit.js
@@ -105,7 +105,11 @@ function makeDragable(objects, dragStopHandler, 
dragMoveHandler) {
         return false;
 
     for(var i = 0; i < len; i++) {
-        var o = document.getElementById(objects[i]);
+       if(typeof(objects[i]) === 'object')
+           var o = objects[i];
+       else
+            var o = document.getElementById(objects[i]);
+
         if(o) {
             addEvent(o, "mousedown", function(e) { dragStart(e, 
dragMoveHandler); });
             addEvent(o, "mouseup",   function(e) { dragStop(e,  
dragStopHandler); });
@@ -143,10 +147,10 @@ function dragStart(event, dragHandler) {
     draggingObject.x = draggingObject.offsetLeft;
     draggingObject.y = draggingObject.offsetTop;
 
-  // Save relative offset of the mouse
-  dragObjectOffset   = [ posy - draggingObject.offsetTop - getHeaderHeight(),
-                         posx - draggingObject.offsetLeft ];
-  dragObjectStartPos = [ draggingObject.offsetTop, draggingObject.offsetLeft ];
+    // Save relative offset of the mouse
+    dragObjectOffset   = [ posy - draggingObject.offsetTop - getHeaderHeight(),
+                           posx - draggingObject.offsetLeft ];
+    dragObjectStartPos = [ draggingObject.offsetTop, draggingObject.offsetLeft 
];
 
     // Assign the handler which is called during object movements
     dragObjectHandler = dragHandler;
diff --git a/share/frontend/nagvis-js/js/nagvis.js 
b/share/frontend/nagvis-js/js/nagvis.js
index 5ba5dde..51e6b19 100644
--- a/share/frontend/nagvis-js/js/nagvis.js
+++ b/share/frontend/nagvis-js/js/nagvis.js
@@ -1134,4 +1134,4 @@ function scaleView() {
         }
         header = null;
     }
-}
\ No newline at end of file
+}


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Discover what all the cheering's about.
Get your free trial download today. 
http://p.sf.net/sfu/quest-dev2dev2 
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to