Author: Lars Michelsen <[email protected]>
Date: Thu Sep 8 12:44:53 2011 +0200
Committer: Lars Michelsen <[email protected]>
Commit-Date: Thu Sep 8 12:44:53 2011 +0200
Making objects undragable when locked again
---
share/frontend/nagvis-js/js/NagVisLine.js | 6 ++-
share/frontend/nagvis-js/js/NagVisObject.js | 12 ++++-
share/frontend/nagvis-js/js/NagVisShape.js | 29 +++++++++++-
.../frontend/nagvis-js/js/NagVisStatefulObject.js | 4 ++
share/frontend/nagvis-js/js/edit.js | 51 ++++++++++++++------
share/frontend/nagvis-js/js/nagvis.js | 11 ++++
6 files changed, 92 insertions(+), 21 deletions(-)
diff --git a/share/frontend/nagvis-js/js/NagVisLine.js
b/share/frontend/nagvis-js/js/NagVisLine.js
index 0cdc158..64da02e 100644
--- a/share/frontend/nagvis-js/js/NagVisLine.js
+++ b/share/frontend/nagvis-js/js/NagVisLine.js
@@ -63,8 +63,10 @@ var NagVisLine = NagVisStatelessObject.extend({
this.drawLine();
// Enable the controls when the object is not locked
- if(!this.bIsLocked)
+ if(!this.bIsLocked) {
this.parseControls();
+ this.toggleObjectActions(this.bIsLocked);
+ }
},
/**
@@ -147,4 +149,4 @@ var NagVisLine = NagVisStatelessObject.extend({
parseHoverMenu: function () {
this.getHoverMenu(this.conf.object_id+'-icon');
}
-});
\ No newline at end of file
+});
diff --git a/share/frontend/nagvis-js/js/NagVisObject.js
b/share/frontend/nagvis-js/js/NagVisObject.js
index 574aebc..4a159a4 100644
--- a/share/frontend/nagvis-js/js/NagVisObject.js
+++ b/share/frontend/nagvis-js/js/NagVisObject.js
@@ -354,9 +354,11 @@ var NagVisObject = Base.extend({
oObj.onmouseout = function() { hoverHide(); };
}
- // Disable the hover menu by object lock when unlocked
+ // Is already done during map rendering before. But the hover menu
+ // is rendered after the map rendering and can not be disabled
during
+ // map rendering. So simply repeat that action here
if(typeof(this.toggleObjectActions) == 'function')
- this.toggleObjectActions(this.bIsLocked);
+ this.toggleObjectActions(this.bIsLocked);
}
justCreated = null;
@@ -889,8 +891,12 @@ var NagVisObject = Base.extend({
this.objControls = [];
oControls = null;
- if(this.conf.type === 'textbox')
+ if(this.conf.type === 'textbox') {
this.removeBoxControls();
+ makeUndragable([this.conf.object_id+'-label']);
+ } else {
+ makeUndragable([this.conf.object_id+'-icondiv']);
+ }
},
parseControlDrag: function (num, objX, objY, offX, offY, size) {
diff --git a/share/frontend/nagvis-js/js/NagVisShape.js
b/share/frontend/nagvis-js/js/NagVisShape.js
index b185a87..46ce2de 100644
--- a/share/frontend/nagvis-js/js/NagVisShape.js
+++ b/share/frontend/nagvis-js/js/NagVisShape.js
@@ -60,8 +60,10 @@ var NagVisShape = NagVisStatelessObject.extend({
oContainerDiv = null;
// Enable the controls when the object is not locked
- if(!this.bIsLocked)
+ if(!this.bIsLocked) {
this.parseControls();
+ this.toggleObjectActions(this.bIsLocked);
+ }
},
/**
@@ -129,5 +131,30 @@ var NagVisShape = NagVisStatelessObject.extend({
// Simply make it dragable. Maybe will be extended in the future...
makeDragable([this.conf.object_id+'-icondiv'], this.saveObject,
this.moveObject);
+ },
+
+ /**
+ * PUBLIC toggleObjectActions()
+ *
+ * This enables/disables the icon link temporary. e.g. in unlocked
+ * mode the hover menu shal be suppressed.
+ *
+ * @author Lars Michelsen <[email protected]>
+ */
+ toggleObjectActions: function(enable) {
+ var o = document.getElementById(this.conf.object_id+'-icon');
+ if(o) {
+ if(enable) {
+ // Link (Left mouse action)
+ if(o.parentNode.tagName == 'A')
+ o.parentNode.onclick = null;
+ } else if(!enable) {
+ // Link (Left mouse action)
+ if(o.parentNode.tagName == 'A')
+ o.parentNode.onclick = function() {return false};
+ }
+ o = null;
+ o = null;
+ }
}
});
diff --git a/share/frontend/nagvis-js/js/NagVisStatefulObject.js
b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
index 7e8ff46..01e87e6 100644
--- a/share/frontend/nagvis-js/js/NagVisStatefulObject.js
+++ b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
@@ -265,6 +265,9 @@ var NagVisStatefulObject = NagVisObject.extend({
if(!this.bIsLocked) {
this.parseControls();
this.unlockLabel();
+
+ if(typeof(this.toggleObjectActions) == 'function')
+ this.toggleObjectActions(this.bIsLocked);
}
},
@@ -999,6 +1002,7 @@ var NagVisStatefulObject = NagVisObject.extend({
// Clone the node to remove all attached event handlers
var n = o.cloneNode(true);
o.parentNode.replaceChild(n, o);
+ makeUndragable([o]);
o = null;
n = null;
},
diff --git a/share/frontend/nagvis-js/js/edit.js
b/share/frontend/nagvis-js/js/edit.js
index 84eb78e..94a380a 100644
--- a/share/frontend/nagvis-js/js/edit.js
+++ b/share/frontend/nagvis-js/js/edit.js
@@ -80,8 +80,8 @@ var dragObjectOffset = null;
var dragObjectPos = null;
var dragObjectStartPos = null;
var dragObjectChilds = {};
-var dragObjectHandler = null;
var dragStopHandlers = {};
+var dragMoveHandlers = {};
function getTarget(event, ignoreType) {
if(typeof(ignoreType) === 'undefined')
@@ -105,7 +105,7 @@ function getButton(event) {
return (event.which < 2) ? "LEFT" : ((event.which == 2) ? "MIDDLE" :
"RIGHT");
}
-function makeDragable(objects, dragStopHandler, dragMoveHandler) {
+function makeUndragable(objects) {
var len = objects.length;
if(len == 0)
return false;
@@ -116,22 +116,47 @@ function makeDragable(objects, dragStopHandler,
dragMoveHandler) {
else
var o = document.getElementById(objects[i]);
- // Register the drag stop handler
- dragStopHandlers[o.id] = dragStopHandler;
+ if(o) {
+ // Remove the handlers
+ delete dragStopHandlers[o.id];
+ delete dragMoveHandlers[o.id];
+
+ removeEvent(o, 'mousedown', dragStart);
+ removeEvent(o, 'mouseup', dragStop);
+
+ o = null;
+ }
+ }
+}
+
+function makeDragable(objects, dragStopHandler, dragMoveHandler) {
+ var len = objects.length;
+ if(len == 0)
+ return false;
+
+ for(var i = 0; i < len; 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); });
+ // Register the handlers
+ dragStopHandlers[o.id] = dragStopHandler;
+ dragMoveHandlers[o.id] = dragMoveHandler;
+
+ addEvent(o, "mousedown", dragStart);
// The drag stop event is registered globally on the whole
document to prevent
// problems with too fast mouse movement which might lead to lag
the dragging
// object behind the mouse and make it impossible to stop dragging.
- addEvent(document, "mouseup", function(e) { dragStop(e); });
+ addEvent(document, "mouseup", dragStop);
o = null;
}
}
len = null;
}
-function dragStart(event, dragHandler) {
+function dragStart(event) {
if(!event)
event = window.event;
@@ -164,9 +189,6 @@ function dragStart(event, dragHandler) {
posx - draggingObject.offsetLeft ];
dragObjectStartPos = [ draggingObject.offsetTop, draggingObject.offsetLeft
];
- // Assign the handler which is called during object movements
- dragObjectHandler = dragHandler;
-
// Save diff coords of relative objects
var sLabelName = target.id.replace('box_', 'rel_label_');
var oLabel = document.getElementById(sLabelName);
@@ -229,8 +251,8 @@ function dragObject(event) {
}
// Call the dragging handler when one is set
- if(dragObjectHandler)
- dragObjectHandler(draggingObject);
+ if(dragMoveHandlers[draggingObject.id])
+ dragMoveHandlers[draggingObject.id](draggingObject);
oParent = null;
}
@@ -295,8 +317,8 @@ function dragStop(event) {
moveRelativeObject(draggingObject.id, dragObjectStartPos[0],
dragObjectStartPos[1]);
// Call the dragging handler when one is set
- if(dragObjectHandler)
- dragObjectHandler(draggingObject);
+ if(dragMoveHandlers[draggingObject.id])
+ dragMoveHandlers[draggingObject.id](draggingObject);
draggingObject = null;
return;
@@ -324,7 +346,6 @@ function dragStop(event) {
dragStopHandlers[draggingObject.id](draggingObject, oParent);
oParent = null;
- dragObjectHandler = null;
draggingObject = null;
}
diff --git a/share/frontend/nagvis-js/js/nagvis.js
b/share/frontend/nagvis-js/js/nagvis.js
index 806aa15..b4fb189 100644
--- a/share/frontend/nagvis-js/js/nagvis.js
+++ b/share/frontend/nagvis-js/js/nagvis.js
@@ -840,6 +840,17 @@ function addEvent(obj, type, fn) {
}
}
+// Same as above but inverse. Removes registered events
+function removeEvent(obj, type, fn) {
+ if(obj.removeEventListener) {
+ obj.removeEventListener(type, fn, false);
+ } else if (obj.detachEvent) {
+ obj.detachEvent("on"+type, obj[type+fn]);
+ delete obj["e"+type+fn];
+ delete obj[type+fn];
+ }
+}
+
/**
* Displays a system status message
*
------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops? How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins