PDA

View Full Version : Cancel drag of a panel



yopyop
3 Nov 2009, 12:37 PM
Hi,

I have a portal with some panels that I can move. When I drag a panel, under some conditions, I have to forbid the change and set the panel to this old position...

What is the best way to do that?

Thanks!

mitchellsimoens
3 Nov 2009, 11:14 PM
This is an example of a simple panel that if the x coord is 300 or greater then the panel will get sent back to the start of the drag. It can still move however as long as the x coord is less than 300. Of course all you have to do is change the if statement to meet whatever you need.


new Ext.Panel({
title: "Drag me",
x: 100,
y: 100,
renderTo: Ext.getBody(),
floating: true,
frame: true,
width: 400,
height: 200,
draggable: {
insertProxy: false,
onDrag : function(e){
var pel = this.proxy.getEl();
this.x = pel.getLeft();
this.y = pel.getTop();
var s = this.panel.getEl().shadow;
if (s) {
s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
}
},
endDrag : function(e) {
if (this.x < 300) {
this.panel.setPosition(this.x, this.y);
}
},
startDrag: function(x, y) {
var pos = this.panel.getPosition();
this.startX = pos[0];
this.startY = pos[1];
}
}
}).show();

yopyop
4 Nov 2009, 11:04 PM
Thanks for your answer.

It seems that your code doesn't work in the context of a portal... In the startDrag event, the positions of all panels are always [0,0]... So it is not possible to set the old position...

Or maybe there is something I don't undersand...

mitchellsimoens
5 Nov 2009, 9:20 PM
Don't know why the portal would change the drags to where this wouldn't work. It's pretty slimmed down.