Reorder lists only after clicking link

Yo,

I have created the usual list that uses drag and drop to reorder stuff
and it all works fine. But I don’t want the list to be draggable until
someone clicks a button (or link) to enable the reordering.

My only idea so far is to have the drag handles hidden with javascript
and the show them onclick, but this is messy. Is there not a clean way
to do this?

Is there a way to uncreate a sortables list? (the opposite of the
method that creates them. that would solve the problem I think.)

://
Nathan H.

Nathan H. wrote:

Yo,

I have created the usual list that uses drag and drop to reorder stuff
and it all works fine. But I don’t want the list to be draggable until
someone clicks a button (or link) to enable the reordering.

My only idea so far is to have the drag handles hidden with javascript
and the show them onclick, but this is messy. Is there not a clean way
to do this?

Is there a way to uncreate a sortables list? (the opposite of the
method that creates them. that would solve the problem I think.)

://
Nathan H.

<%= link_to_function(‘enable sorting’,
“#{sortable(…)} $(‘mylist’).className=‘sortable’”) %>

Then hide the handles via CSS so they have a “display:hidden” without
the class “sortable” on the parent container, and a “display:inline”
when the class is defined. This way you dont need to iterate though
each handle and show it.

To uncreate the sortable I think you have to overwrite it with a fresh
copy. So in the RJS response for disabling the sorting you can replace
the list with a partial. I’m mostly sure that will remove the sorting
until sortable is called again.

On 2006-07-26 17:27:14 -0400, Alex W.
[email protected] said:

the list with a partial. I’m mostly sure that will remove the sorting
until sortable is called again.

I like the idea of doing the class name thing to hide the sortables.

The Sortable.destroy() method works, but I have to create a toggle
function to test to see if it needs destroying. I like this better than
reloading the content, just because it doesn’t hit the server.

Is there a way to write RJS code that can just be loaded in with the
:defaults set of javascript files and not after a call to a controller?

://
Nathan H.

On 2006-07-26 10:19:11 -0400, Nathan H.
[email protected] said:

Is there a way to uncreate a sortables list? (the opposite of the
method that creates them. that would solve the problem I think.)

There is a javascript way to do it, Sortable.destroy, but I loose all
the rails goodness by declairing the oncomplete myself.

In RJS, I can use page.sortable, but it does not behave like it is
documented. Script.aculo.us says that if you create a sortable on an
already existing one, it destroys it. This does not happen.

What I really need is a way to do if statements in RJS.

I want to say:

if page[‘thing’].innerHTML == ‘something’
page.sortable ‘things_owner’
page.replace_html ‘thing’, ‘not something’
else
page << "Sortable.destroy(‘things_owner’)
page.replace_html ‘thing’, ‘something’
end

I wish it was that easy…or easier.

I just wrote the whole crap thing in javascript for now, which is not
pretty at all.

Please, any ideas?

://
Nathan H.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs