I have a DnD Source that I have set to copy. This source can be dropped to a couple of different targets. One of the targets (which is defined as a Source b/c I need to drag items from this list as well) I want the node to actually be copied, but the other two (true Targets) I want it to act like a copy, but when it is dropped, I just want to extract the data from the dndData attribute, and I want the node that was copied to "disappear". How can I do this?
Also, I am having a problem where my DnD Source objects are being copied in their same list, which I do not want to do. How can I prevent this?
Current Search ResultsSearch Result 1Search Result 2Search Result 3Search Result 4
I have the following code, but I am not sure how exactly to "remove" the copied node.
dojo.subscribe("/dnd/drop", function(source, nodes, iscopy){
var t = dojo.dnd.manager().target;
if(t == source && iscopy) {
// I want to prevent the copy from occurring somehow
for (var i=0;i
function getData(target, nodes) {
// get data from dndData attribute
// throw node that was just copied/moved here away
}
Any help is greatly appreciated.

One way to do it is to
One way to do it is to override Source.onDndDrop() method — all actual work on copying/moving items is done there. For example, you can check conditions and change parameters before calling the original method. Simple example:
mysource.onDndDrop = function(source, nodes, copy){
oldOnDndDrop.call(this, source, nodes, source != this);
};
The snippet above forces the "move" semantics when transferring items within the same source, and the "copy" semantics, when transferring items between different sources. The same way you can add more functionality to your onDndDrop processor.
That saves me from having to
That saves me from having to do a check to prevent copying in the same source, but I still need a way to be able to identify the node that was copied. I have items in Source_1 that can only be copied to Source_2. Items in Source_2 are the only items that can be moved to Target_1. So when an item from Source_1 gets copied to Source_2, I want the newly copied item to also be able to be moved to Target_1. However, it can't be moved b/c the value for dndType is incorrect. I have tried just changing the value of the dndType attribute to be what I want, but I still am not able to move the new node to Target_1. Is there an easier way to do what i am asking? Am I doing something wrong?
This is my code:
dojo.subscribe("/dnd/drop", function(source, nodes, isCopy, target){ if (target == ws_id) { // add code to change the dndType="searchResult" to dndType="ws" var copiedNode = dojo.byId(target.anchor.id); console.log("copiedNode.getAttribute(\"dndType\"): " + copiedNode.getAttribute("dndType")); copiedNode.setAttribute("dndType", "ws"); console.log("copiedNode.getAttribute(\"dndType\") AFTER: " + copiedNode.getAttribute("dndType")); } });The log print outs verify the attribute was set successfully, viewing the generated source after the copy verifies the attribute was set successfully, however, when I drag the item over to Target_1, I am unable to move it to the new Target, even though it is set to accept the dndType that I have set on the copied node. Am I missing something?
You don't need to mess with
You don't need to mess with HTML nodes because they are a mere reflection of data items stored inside the container (⇒ selector ⇒ source). For example, if you do know that your node in question is referenced by target.anchor like you do in your snippet, you can do something like that:
if(target == ws_id) {
// add code to change the dndType="searchResult" to dndType="ws"
var item = target.getItem(target.anchor.id);
item.type = ["ws"];
target.setItem(target.anchor.id, item);
}
});
You can do it because "item.type" is the authoritative source for types. More universal (and less hacky) solution is to change the type on the fly in the custom creator function defined for your source.
Thanks. That worked fine.
Thanks. That worked fine. Do you have an example, or know of one I can look at, that deals with the custom creator function for the source? If there is a more universal way of doing this, I think I would rather use that than a "band-aid".
Look in dojo/tests/dnd/ for
Look in dojo/tests/dnd/ for tests. E.g., flickr_viewer.html uses custom creator functions to present the same data items (flickr-based images) differently in different situations. In your case you can keep visuals but manipulate types.
I forgot to ask in a
I forgot to ask in a previous post, but is there a better, more "standard" way of identifying the item that was just dropped, instead of my way using the
target.getItem(target.anchor.id)? Is the method different for a move vs. a copy?There are several ways to do
There are several ways to do it: you can override onDndDrop(), or catch parameters in the custom creator.
OTOH this functionality is a good candidate for addition to the Container class. E.g., it can broadcast what objects were added to it.
thanks
So when point from Source_1 be copied on Source_2, I want newly copied point to also be capable is moved on Target_1. However, this can is not moved by b/c value for dndType wrong. I have tried exact changing value of the attribute dndType to be that I want, but I still not capable to move the new node on Target_1.
buy movies