<script type="text/javascript">
$().ready(function () {

	$('.id_executor').change(function(e) {
		var selected = $('#ajaxTabs').tabs("option", "selected");
		var value = $(this).val();
		value = value.split('#');
		
		$.ajax({
			url: '/solicitacao/tarefaajax/assumir',
			data: {
				id_executor : 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!');
			}
		});
	});
	
});
</script>

<form id='frmFilter' action='/solicitacao/tarefaajax/criador' class='formSearch' method='post'>
	<table class='grid' cellspacing='1' cellpadding='5' border='0' id='tablePagination' width="100%">
		<thead>
			<tr>
				<th width="1%">&nbsp;</th>
				<th width="1%">Delegar</th>
				<th width="1%">Status</th>			
				<th width="1%">Código</th>
				<th width="10%">Prioridade</th>
				<th width="10%">Data</th>
				<th width="10%">Status</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 class="<? echo ($Row->fl_lido ? 'lido' : 'nao_lido'); ?>">
					<td align="center">
						<a href="/solicitacao/tarefaajax/executar/id/<? echo $Row->id; ?>" title="Executar" class="executar">
							<?
							switch ($Row->status){
								case 'EXECUTANDO':
									$imagem = 'stop.png';
									break;
								default:
									$imagem = 'start.png';
									break;
							}
							?>
							<img src="/resources/imagens/mini/<?php echo $imagem; ?>" border="0" id="imgStatus_<? echo $Row->id; ?>" />
						</a>
					</td>
					<td align='center' width='1%' nowrap='nowrap'>
						<select class="id_executor">
							<option></option>
							<? foreach ($this->departamento as $value => $text): ?>
								<?
								$selected = '';
								if($value == $Row->executor['id_usuario']){
									$selected = 'selected';
								}
								?>
								<option value="<? echo $Row->id.'#'.$value?>" <?=$selected?>><? echo $text?></option>
							<? endforeach; ?>
						</select>
					</td>
					<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 $Row->prioridade; ?></td>
					<td nowrap align="center"><? echo Agro_Util::formatDate($Row->dt_criacao, Zend_Date::DATETIME_SHORT) ?></td>
					<td nowrap align="center" id="tdStatus_<? echo $Row->id; ?>"><? echo $Row->label_status; ?></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'); ?>