3
I have a list of tasks, it has the status part, which shows for example 'On test' and a button of Approve.
I’m trying with that button Approve when clicked take the task id and send an update to it to change its status.
But so far I don’t know how to do, I was trying to do via Ajax with onClick
, but I got nothing so far.
Someone can give me a way?
Knob
<a id="approved" class="flex-icon" data-toggle="tooltip" data-placement="top" title="Aprovar"><i class="fa fa-check-square-o fa-2x" aria-hidden="true"></i></a>
ID
<li class="list-group-item id-task" id="<?php echo $row['TasksId']; ?>">
Task Code
<div class="panel-body">
<ul id="sortable" class="list-group reorder-task-list">
<?php
$rows = $auth_task->select();
foreach($rows as $row): ?>
<li class="list-group-item id-task" id="<?php echo $row['TasksId']; ?>">
<span><i class="glyphicon glyphicon-retweet" aria-hidden="true"></i></span>
<h5 class="delivery-line">
<i class="glyphicon glyphicon-time" aria-hidden="true"></i>
<?php echo$row['Delivery'];?>
</h5>
<?php
if($row['Status'] == 'Em Processo'){
echo "<span class=\"badge\" style=\"background-color:#67A6DF\">Em Processo</span>";
}
elseif ($row['Status'] == 'Teste') {
echo "<span class=\"badge\" style=\"background-color:#FCB529\">Em Teste</span>";
}
elseif ($row['Status'] == 'Aprovada'){
echo "<span class=\"badge\" style=\"background-color:#43A995\">Aprovada</span>";
}
?>
<div>
<h4 class="line-center">
<strong><?php echo $row['Project'];?></strong>
</h4>
</div>
<h6 class="line-center" ><?php echo $row['Subject'];?></h6>
<hr>
<h4 class="company-line line-center">
<i class="glyphicon glyphicon-map-marker" aria-hidden="true"></i>
<?php echo $row['CompanyFantasy'];?>
</h4>
<?php if($userRow['Level'] == 'Admin'):?>
<div class="footer-li">
<a href="" class="flex-icon" data-toggle="tooltip" data-placement="top" title="Estatística"><i class="fa fa-bar-chart fa-2x" aria-hidden="true"></i></a>
<a href="" class="flex-icon" data-toggle="tooltip" data-placement="top" title="Abrir"><i class="fa fa-folder-open-o fa-2x" aria-hidden="true"></i></a>
<a href="" class="flex-icon" data-toggle="tooltip" data-placement="top" title="Enviar Para Teste"><i class="fa fa-flask fa-2x" aria-hidden="true"></i></a>
<a id="approved" class="flex-icon" data-toggle="tooltip" data-placement="top" title="Aprovar"><i class="fa fa-check-square-o fa-2x" aria-hidden="true"></i></a>
<a href="" class="flex-icon" data-toggle="tooltip" data-placement="top" title="Cancelar"><i class="fa fa-times-circle-o fa-2x" aria-hidden="true"></i></a>
</div><!-- <div class="footer-li"> -->
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div><!-- <div class="panel-body"> -->
You can post your Javascript?
– Allan Andrade
I find it easier to do this without ajax, in the form of link even passing by parameter the action and the id of the task.
– Fabiano Cacin Pinel
@Fabianocacinpinel has some documentation for me to give a read?
– Wagner Viana
@Allanandrade That’s all I was;
$('#approved').on('click',function(){
 var taskid=$(this).find('li').attr('id');
 
 $.ajax({
 url: './task.php',
 type: 'POST', 
 data: {},
 success: function(data) { 
 window.location.reload(); 
 } 
 });
 });
– Wagner Viana
Will you have a button just for all tasks? Explain better how you want it to work?
– Allan Andrade
@Allanandrade it mounts a button for each task, if I click the approve button it will change the value of the task within the bank, an update, to change its status. I got the ID
<a href=?action=approved&TasksId=<?php echo $row['TasksId']; ?> id="approved" class="flex-icon" data-toggle="tooltip" data-placement="top" title="Aprovar"><i class="fa fa-check-square-o fa-2x" aria-hidden="true"></i></a>
But my problem is that I am using Class and PDO.– Wagner Viana
I only read your previous comment now, so I think it’s like @Fabianocacinpinel said... can only have an ID, changes by class, picks up ID relative to the object that received the click and posted via AJAX.
– Allan Andrade