Nio, great tutorial, even though I don't speak Chinese.
Unfortunately, I couldn't get it working the "right way". The sad thing
is that I have had it working long ago before I discovered Cake, and
that implementation (which uses the same technique of Nio and others)
works fine. But for whatever reason, I can't get Cake to accept the
output of Sortable.serialize properly.
I had to take Claudio's approach and write my own Sortable.serialize
equivalent. Unfortunately, Claudio's page has a couple bugs in it (I
tried to post a correction there Claudio, but don't have permissions).
Also, I have a couple additional requirements. I need to support
multiple lists per page, and I need mine to reorder the list as it's
being dragged and dropped, not as part of a form submit as Claudio's
does.
Also, my solution (like Claudio's) isn't as nice as the Scritpaculous
serialize in that instead of finding all the <li>'s within a <ul> with
a given id, I find all the <li>'s with a given class.
Here's what I came up with:
View
<style> .handle { cursor : move; } </style>
<ul id="task_list_<?php echo $task_list['TaskList']['id']?>"
class="sortable-list">
<?php
foreach ($task_list['Todo'] as $item) {
print '<li id="task_'.$item['id'].'"
class="tasks_in_'.$task_list['TaskList']['id'].'">';
print '<span class="handle">'.$item['name']."</span></li>\n";
}
?>
</ul>
<script type="text/javascript">
function getGroupOrder() {
var sections = document.getElementsByClassName('tasks_in_<?php echo
$task_list['TaskList']['id'] ?>');
var alerttext = '';
for(var i=0; i<sections.length; i++)
{
var sectionID = sections[i].id;
var pieces = sections[i].id.split('_');
var end = pieces[pieces.length-1];
if(i!=sections.length-1)
alerttext += i + '=' + end +'&';
else
alerttext += i + '=' + end;
}
var options = {
method : 'post',
parameters : alerttext
};
new Ajax.Request('<?php echo
$html->url('/task_lists/reorder/').$task_list['TaskList']['id']?>',
options);
};
Sortable.create(
'task_list_<?php echo $task_list['TaskList']['id']?>',
{
handle: 'handle',
onUpdate: getGroupOrder
}
);
</script>
Controller logic:
function reorder($id=null)
{
$tasks = $this->params['form'];
$i = 1;
foreach($tasks as $task)
{
if($task == '_')
continue;
$this->Task->id = $task;
$this->Task->saveField('ranking',$i++);
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---