Ângelo Rigo
Ângelo Rigo

Reputation: 2165

Cakephp Update a list set priority

I am new into cakephp.

I have a list of task itens and need to update using cakephp, after dragging and dropping, so this will set the priority of the task itens :

order view:

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>  
    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>

    <script>  
        $(function() {
            $( "#sortable" ).sortable({   
                placeholder: "ui-sortable-placeholder"   
            });  
        });  
    </script> 
 <ul id="sortable">  
    <?php foreach ($tasks as $task): ?>
        <li class="ui-state-default"  value="<?=$task['Task']['id']?>"><?=$task['Task']['title']?></li>
        <?php endforeach; ?>
    <?php unset($task); ?> 
</ul> 

How can i get the position and the id from the list to have it read on the priority method of the task Controller ?

task controller:

public function priority(){

        foreach($tasks as $task){
            $this->Task->query("UPDATE tasks SET priority = ? WHERE id = $id");
        }

    }

Thank´s in advance

Upvotes: 0

Views: 168

Answers (1)

Dave
Dave

Reputation: 29121

Use Ajax. When the order is changed, call your Ajax function that runs `/tasks/priority'.

Upvotes: 1

Related Questions