<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Helvetica, Arial, sans-serif">Hello
John-Paul,<br>
<br>
&nbsp;&nbsp;&nbsp; I've done this in a recent project.&nbsp; Basically the way I do it is
check to see what order the a selected item in a list is in, and then
move that item before/after a child node in the target parent based off
this information.&nbsp; It's a bit complicated, but it's doable. I monkey
patched the module SymetrieCom::Acts::NestedSet to include the
following method to help me with this scenario:<br>
<br>
</font></font>
<hr size="2" width="100%"><font size="-1"><font
 face="Helvetica, Arial, sans-serif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def
move_to_parent_location(parent, location)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent = nil if parent == 0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parent = parent === self.class ? parent :
self.class.find(parent) if parent<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; children = parent ? parent.children : self.class.roots<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if children.length &gt; 0<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ord = location.to_i<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ord &gt; children.length<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.move_to(children.last, :right)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elsif children[ord] != self<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.move_to(children[ord], :left)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elsif parent<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.move_to(parent, :child)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>
</font></font>
<hr size="2" width="100%"><font size="-1"><font
 face="Helvetica, Arial, sans-serif"><br>
<br>
</font></font>
<div class="moz-signature">
<div style="line-height: 125%;"> <img
 src="cid:part1.09070503.03060706@gnexp.com" height="49" width="136"><br>
<span style="font-family: Arial,Helvetica,sans-serif; font-size: 9pt;"><b>Jeremy
Nicoll</b><br>
<a href="http://www.gnexp.com">www.gnexp.com</a><br>
(801) 783-3831 </span>
</div>
</div>
<br>
<br>
John-Paul Bader wrote:
<blockquote
 cite="mid:9B3FAD14-7316-43A6-A318-1B45B250CFD8@medienhaus.udk-berlin.de"
 type="cite">
  <pre wrap="">Hey there,

I just subscribed so i hope this question isn't redundant.

I'm trying to implement a sortable nested set.

I've already got an application with better_nested_set in place. I  
also got a nice nested &lt;ul&gt; rendering for my tree. No I'd be able to  
drag an drop / sort elements across the set.

I found this Wiki entry which says that it wouldn't be a good idea in  
general to use sortable.create with :tree =&gt; true

<a class="moz-txt-link-freetext" href="http://whynotwiki.com/Rails_/_Sortable_trees">http://whynotwiki.com/Rails_/_Sortable_trees</a>

On the same page there is a link to the rubyonrails wiki stating that  
there is a fix expecially for better_nested_set. <a class="moz-txt-link-freetext" href="http://dev.rubyonrails.org/ticket/7807">http://dev.rubyonrails.org/ticket/7807</a>

My question would be what your experiences are. Is there a good way to  
implement a sortable / draggable better_nested_set ? If not do you  
have any suggestions, thoughs on this ?

Thanks and kind regards,

John (Berlin / Germany)
_______________________________________________
Betternestedset-talk mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Betternestedset-talk@rubyforge.org">Betternestedset-talk@rubyforge.org</a>
<a class="moz-txt-link-freetext" href="http://rubyforge.org/mailman/listinfo/betternestedset-talk">http://rubyforge.org/mailman/listinfo/betternestedset-talk</a>

  </pre>
</blockquote>
</body>
</html>