PDA

View Full Version : How to cancel tree dragdrop includin Ajax request



reignman
6 Jan 2007, 11:18 AM
Hey Guys,

I don't know how to write it in a right way but this is what i want:

I use the onbeforedrag event of the tree to call an ajax request. if the request answers false the drag event should be cancelled. but i don't know how to use the onsuccess/failure functions to cancel the drag.

what i got is this


tree.on('beforenodedrop', function(e){
if(e.target.attributes.cls == 'folder' && e.point == 'append'){
//Ajax Request
var buf = [];
buf.push('target=', encodeURIComponent(e.target.id), '&');
buf.push('node=', encodeURIComponent(e.data.id));
var params = buf.join('');
var cb = {
success: handleResponseDrag,
failure: handleFailureDrag,
scope: this,
argument: {node: e.data, target: e.target}
};
YAHOO.util.Connect.asyncRequest('POST','ajax.php?folder=admin&m=structuremove', cb, params);
// end request

//How to include here the answer of handleResponseDrag to return true/false ????
//return false;
}
});


thanks for answering :)

jack.slocum
6 Jan 2007, 3:33 PM
For drag drop, that's not really an option. A drag drop takes place from mousedown to mouseup, so an async request isn't really an option. You wouldn't want the user sitting there will the drag proxy stuck to the mouse icon while a server request takes place anyway, it would look very odd. :)

What you may want to do is make your asyncRequest passing the "e" as an argument and return true.
If your response arrives and it's invalid you have the data in the e object to undo the drop and tell the user.

Another way (and probably easier/better) is to provide the information you require in your node attributes when loading the node through XHR. Then it's always available (node.attributes.yourAttr) when you make a drop.

reignman
7 Jan 2007, 2:14 AM
thanks jack :)

i knew this would be the answer .

so ... i'll build the cleanupfunction..

but I still have another idea...
i haven't worked with the statemanager yet...

would it be possible to implement save tree states in there an restore them on the fly?

jack.slocum
8 Jan 2007, 10:55 AM
It's definitely possible. The events are there for you. I would recommend saving them somewhere else though because that cookie could get huge. If you are using json to load the tree, you could return the expanded state in the json data (expanded:true).

reignman
8 Jan 2007, 11:24 AM
thats really great...
tree with state restore :) i like that idea...

i'll try my best

ambs
22 Jan 2007, 11:51 AM
Hi,

I have the same issue... revert a node position if a update was not successful.
I understand the posted code, however how can I manually revert a "moved node"?


Thanks,

doubleforte
3 Aug 2007, 3:03 PM
Hi,

I have the same issue... revert a node position if a update was not successful.
I understand the posted code, however how can I manually revert a "moved node"?


Thanks,

I need this as well...any ideas?

Basically, I have files in folders, and I only want to allow dropping ON the other folders in the tree, but not IN the folders. Does that make sense?

thanks
brian

evant
3 Aug 2007, 3:09 PM
Do you mean you only want to be able to drop on the top level but nowhere further down?

This kind of thing can be handled in the client logic, what are you trying to do exactly?

doubleforte
3 Aug 2007, 3:33 PM
I figured out how to do what I needed for now... in the TreePanel... { ddAppendOnly:true }

That doesn't really solve the problem of undoing a drop. At some point, I'd like to be able to drop a node, do some check, and if it check fails, undo the drop and send the node back to where it came.

thanks
brian