This part is duplicating built-in functionality. Read up on  
Sortable.serialize (with a z) in the Wiki. It's very powerful and  
configurable.

var foo = Sortable.serialize('chunksList',{}) //no need to tell it  
tag:li -- it's the default

...time passes...

var fooOrder = foo.serialize();

The result will be an array where the index equals the list position,  
and the value equals the numerical id of the element. Elements must be  
ID'd in the following manner:

someString_1
someString_2
someString_3

...

one underscore per ID, followed by a number -- which does not need to  
be incremental, that's just an artifact of my example (but it must be  
locally unique, naturally).

If you sorted this into 2,3,1 order, you would get back [2,3,1] from  
the serialize method, post that to your server as 'order', and on your  
server side, you would use something like this:

//php
foreach($_POST['order'] as $k=>$v){
        if($item = ActiveRecord::FindById('items',$v){
                $v->position = $k+1;
                $v->save();
        }
}

and you're done.

Walter

On Feb 23, 2009, at 8:12 AM, vanq69 wrote:

> function serialise(listID)
> {
>       var length = document.getElementById(listID).childNodes.length;
>       var serialised = "";
>       for (i = 0; i < length; i++)
>       {
>               var li = document.getElementById(listID).childNodes[i];
>               var id = li.getAttribute("id");
>               // add number to serialised array
>               serialised += encodeURIComponent(id) + "_";
>       }
>       // returns array (with last "_" removed
>       return serialised.substring(0, serialised.length - 1);
> }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to