[dojo-contributors] HOWTO: retrieve a 0.9 DnD object

Eugene Lazutkin eugene at lazutkin.com
Wed Aug 1 01:41:05 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jeff Chimene wrote:
>>> Is it possible to retrieve a value associated with a DnD node?
>> Yes. If you have a node and its source:
>>
>> - source.map[node.id].data --- gives you the access to the associated
>> data object, whatever it is.
>>
>> - source.map[node.id].type --- gives you an array of associated types
>> (strings) for this node.
> 
> Am I correct that these values aren't available once the drag operation
> starts?

No, they are available.

>> Example: you can have a full blown HR record (data) for every person but
>> represent them visually (node) only using their names. And you can
>> access the original object regardless of how it is represented.
> 
> Yes, I can see this. I didn't ask the question correctly: can I access
> the information once it's in flight, or dropped in a target?

Yes. The only caveat is when they moved to the target naturally they are
removed from the source.

>> Probably you should use a non-default creator --- that's why it is here
>> in the first place.
> 
> Right. I'm using the non-default creator. Am I correct in stating that I
> cannot get at the getWeight() method once the node has left the source
> container?

You can, if it is a method on your data item.

>>>           o The source map has already been updated to remove the
>>>             dragged item.
>> Yes, this is the case --- it is assumed that the data has meaning only
>> for the target and the source. It was not meant for 3rd parties to
>> expect the data transfer. 3rd-party listeners can use this topic as a
>> notification. If you have a good cause to change it, let me know.
> 
> Well, doesn't that pretty much eliminate using source.map[] during or at
> the end of the drag operation to get at information created by the
> custom creator function? I can see source.map[] using the debugger. The
> problem is that I can't see how to get at the target node's source.map
> during or after the node transfer operation.

"During" --- yes, you can use the source, up until the target moves
items to itself. After that they should be available on the target. The
target is not identified directly. But if you listen to
"/dnd/source/over", you can save it until the drop --- it's the last
non-null target, which is sent as a parameter. All dropped nodes are
selected by default, so you can just call getSelectedNodes() on the
target after the drop. In order to know when the drop, just
dojo.connect() to stopDrag() method of the manager.

In any case, DnD topics were not meant to be used as a way to control
all fine details of the DnD, they were meant mostly as a notification
that something happens, so you can update the UI, e.g., during the DnD
in progress, you can visually deemphasize the web page making all
compatible source to stick out, and revert back when the drop was done
(or canceled). If you want custom behavior --- subclass relevant
classes, augment relevant objects, and so on. Of course, if you give me
a good reason why "the topic way" is simpler, I am willing to support it.

> I'm already using the custom creator technique, so I guess this isn't an
> issue... I suppose the custom creator function was so intuitive that it
> didn't feel like I was overriding an important method to accomplish some
> obscure purpose or overcome a library design flaw.
> 
> Unless I'm wrong, source.map[] is only for nodes before the DnD
> operation starts? That negates its value in solving the problem at hand.

Like I explained before it can be used before, during, and after the
drop. Nevertheless, are you sure that topics is the right way to solve
your problem at hand?

> Of course, I'm not thinking outside the box; you answered the "howto" by
> overriding checkAcceptance(). I'm looking forward to trying that
> technique...
> 
> Thanks for your help!
> 
> BTW, this is for example three in "Life w/ Dojo"

What is it supposed to do? Where can I look at it?

Thanks,

Eugene

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGsBzxY214tZwSfCsRAm9XAJ0Z4KHR6vxelHQo4b2BmV5VTRew5wCcCvli
2/SViei+WgBathRbWlrLCfU=
=Wnot
-----END PGP SIGNATURE-----



More information about the dojo-contributors mailing list