Forum: Rails Spinoffs (closed, excessive spam) Draggables and Droppables script.aculo.us problem

98861a9cc71a5b4976b8a6523a1613c9?d=identicon&s=25 PROM (Guest)
on 2008-07-06 21:26
(Received via mailing list)
Hi, I'm new around and I have been trying to achieve a certain effect
using script.aculo.us, but it seems I can't handle it alone due to the
fact that I've never used prototype before. I can't even say that I'm
a good javascript coder ... so I'd highly appreciate any help

Here is my problem: I have a list of draggable divs, variable number
of them. I also have a fixed number of droppables. I want the user to
be able to distribute a specified amount (less than the number of
droppables) of the draggables into droppables of his choise (only one
draggable per droppable). Nothing difficult so far (except that I
don't know how to limit the user to place only one draggable into a
droppable, but that would not be a problem if the following
functionality could be implemented).
Now what I could not make by my own is: While the user makes the
distribution of the draggables he may decide that he wants to place a
draggable in a non-empty droppable. I want him to be able to do that -
and when he drops it into the full droppable the one that is in the
droppable should return either back to it's original place as it was
dropped to a non-droppable area or go to the droppable (no claims to
be moving to there, just appearing there is enough) from which the
other droppable was dragged (if it was not dragged form its original
place but from another droppable).

So could you please help me with this? If it's not possible a brief
"not possible" will do either :)

Thanks in advance!
0c18b91df2be866982c3c43773071b8c?d=identicon&s=25 ColinFine (Guest)
on 2008-07-07 13:01
(Received via mailing list)
On Jul 6, 8:25 pm, PROM <lubomir.varba...@gmail.com> wrote:
> Hi, I'm new around and I have been trying to achieve a certain effect
> using script.aculo.us, but it seems I can't handle it alone due to the
> fact that I've never used prototype before. I can't even say that I'm
> a good javascript coder ... so I'd highly appreciate any help
>
Welcome. It does take some getting used to!
Note that there is a brand-new google group
http://groups.google.com/group/prototype-scriptaculous
for prototype and script.aculo.us. Existing queries like yours will
get answered here for the moment, but people are encouraged to post
them to the new group.

> draggable in a non-empty droppable. I want him to be able to do that -
> and when he drops it into the full droppable the one that is in the
> droppable should return either back to it's original place as it was
> dropped to a non-droppable area or go to the droppable (no claims to
> be moving to there, just appearing there is enough) from which the
> other droppable was dragged (if it was not dragged form its original
> place but from another droppable).
>
All that script.aculo.us gives you is the code to do the drop. Your
own 'onDrop'  function must do this.

If you want to return it to where the dragged element came from, you
can get that from the dragged element: something like

function onDrop(dragged, dropsite, event)
{
 ...
  var origin = dragged.up('...')

where you give some suitable selector in the 'up' - for example if you
gave all your containers class 'container', it would be
"dragged.up('.container')".

If you want to return the bumped element to where IT originally came
from, you will have to remember that information yourself somehow -
perhaps in a Javascript hash, or setting a custom attribute in the
element; and then retrieve that origin when you want to send it back.

I don't think there's a 'move' function provided in script.aculo.us -
you could look at the source code for Draggables and see how it does
the 'revert'.

Colin
This topic is locked and can not be replied to.