<script>
$().ready(function () {

	$('.id_status').change(function(e) {
		var selected = $('#ajaxTabs').tabs("option", "selected");
		var value = $(this).val();
		value = value.split('#');
		
		$.ajax({
			url: '/solicitacao/tarefaajax/status',
			data: {
				id_status : value[1],
				id : value[0]
			},
			type: 'POST',
			dataType: 'json',
			success: function(response) {
				if (response.status) {
					$('#ajaxTabs').tabs("load", selected);
				} else {
					alert('Não foi possível delegar a tarefa.');
				}
			},
			error: function (xhr, desc, er) {
				alert('Não foi possível executar a operação. Vamos tentar corrigir isso o mais rapidamente possível.');
			}
		});
	});
	
});
</script>
<form id='frmFilter' action='/solicitacao/tarefaajax/finalizadas' class='formSearch' method='post'>
	<table class='grid' cellspacing='1' cellpadding='5' border='0' id='tablePagination' width="100%">
		<thead>
			<tr>
				<th width="1%">Status</th>
				<th width="1%">Código</th>
				<th width="10%">Início</th>
				<th width="10%">Fim</th>
				<th width="10%">Solicitante</th>
				<th width="10%">Executor</th>
				<th>Título</th>
				<th width="5%">Ações</th>
			</tr>
		</thead>
		<tbody>
			<? foreach ($this->paginator as $Row): ?>
				<? $Row->dados(); ?>
				
				<tr>
					<td align='center' width='1%' nowrap='nowrap'>
						<select class="id_status">
							<option></option>
							<? foreach ($this->status as $value => $text): ?>
								<?
								$selected = '';
								if($value == $Row->id_status){
									$selected = 'selected';
								}
								?>								
								<option value="<? echo $Row->id.'#'.$value?>" <?=$selected?>><? echo $text?></option>
							<? endforeach; ?>
						</select>
					</td>
					<td nowrap align="center"><? echo str_pad($Row->id, 5, '0', STR_PAD_LEFT); ?></td>
					<td nowrap align="center"><? echo Agro_Util::formatDate($Row->dt_criacao, Zend_Date::DATETIME_SHORT) ?></td>
					<td nowrap align="center"><? echo Agro_Util::formatDate($Row->data_termino, Zend_Date::DATETIME_SHORT) ?></td>
					<td nowrap align="center"><? echo $Row->solicitante['ds_nome_guerra']; ?></td>
					<td nowrap align="center"><? echo $Row->executor['ds_nome_guerra']; ?></td>
					<td nowrap><? echo Agro_Util::cortar($Row->ds_titulo, 100) ?></td>
					<td nowrap align="center">
						<a href="/solicitacao/tarefa/view/popup/1/id/<? echo $Row->id; ?>" class="popup" title="Visualizar Solicitação">
							<img src="/resources/imagens/mini/view.png" border="0" />
						</a>
						<a href="/solicitacao/tarefaajax/excluir/id/<? echo $Row->id; ?>" title="Visualizar Solicitação" class="excluir">
							<img src="/resources/imagens/mini/delete.png" border="0" />
						</a>
					</td>
				</tr>
			<? endforeach; ?>
		</tbody>
	</table>
</form>

<?=$this->paginationControl($this->paginator, 'Sliding'); ?>