<div class="tabbable">
	<ul class="nav nav-tabs" id="myTab">
		<li class="active"><a href="#tab0" data-toggle="tab"><i class="icon-tasks"></i> <?php echo __('admin.informations'); ?></a></li>
		<li><a href="#tab1" data-toggle="tab"><i class="icon-shopping-cart"></i> Détails</a></li>
	</ul>
	<div class="tab-content">
		<div class="tab-pane active" id="tab0">
			<table class="table table-striped">
				<tr <?php if($errors->first('customer_id')) echo 'class="error"'; ?>>
					<td style="width:300px">Client *</td>
					<td>
						<?php echo  Form::select('customer_id', $clients, Input::old('customer_id', ((isset($maintenance) && $maintenance->customer_id!='') ? $maintenance->customer_id : '')), array('style'=>'width:280px;')); ; ?>
						<?php echo  $errors->first('customer_id', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
				<tr <?php if($errors->first('date_debut')) echo 'class="error"'; ?>>
					<td>Date du contrat *</td>
					<td>
						<?php echo  Form::text('date_debut', Input::old('date_debut', str_replace('0000-00-00','',(isset($maintenance) ? substr($maintenance->date_debut,0,10) : NULL))), array('placeholder' => 'Date du contrat', 'class' => 'datepicker')); ; ?>
						<?php echo  $errors->first('date_debut', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
				<tr <?php if($errors->first('fin_engagement')) echo 'class="error"'; ?>>
					<td>Fin de l'engagement *</td>
					<td>
						<?php echo  Form::text('fin_engagement', Input::old('fin_engagement', str_replace('0000-00-00','',(isset($maintenance) ? substr($maintenance->fin_engagement,0,10) : NULL))), array('placeholder' => 'Fin de l\'engagement', 'class' => 'datepicker')); ; ?>
						<?php echo  $errors->first('fin_engagement', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
				<tr <?php if($errors->first('prix_fixe')) echo 'class="error"'; ?>>
					<td>Prix fixé *</td>
					<td>
						<div class="input-append">
							<?php echo  Form::text('prix_fixe', Input::old('prix_fixe', (isset($maintenance) ? $maintenance->prix_fixe : NULL)), array('placeholder'=>'50.00','style'=>'width:100px;')) ; ?>
							<span class="add-on">€ / mois</span>
						</div>
						<?php echo  $errors->first('prix_fixe', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
				<tr <?php if($errors->first('temps_initial')) echo 'class="error"'; ?>>
					<td>Travail mensuel *</td>
					<td>
						<div class="input-append">
							<?php echo  Form::text('temps_initial', Input::old('temps_initial', (isset($maintenance) ? $maintenance->temps_initial : NULL)), array('placeholder'=>'12.00','style'=>'width:100px;')) ; ?>
							<span class="add-on">h</span>
						</div>
						<?php echo  $errors->first('temps_initial', '<span class="help-inline">:message</span>') ; ?>
					</td>
				</tr>
			</table>
		</div>
		<div class="tab-pane" id="tab1">
			<style>
			#sortable { list-style-type: none; margin: 0; padding: 0; width: 100%; }
			#sortable li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; cursor: default; }
			</style>
			
			<ul id="sortable">
				<?php if($maintenance->details && count($maintenance->details)>=1): ?>
					<?php foreach($maintenance->details as $l): ?>
					<li class="ui-state-default">
						<?php echo  Form::text('tache_date[]', $l->date, array('placeholder'=>'Date (Y-m-d)','style'=>'width:10%;','class'=>'datepicker tache_date')) ; ?>  
						<?php echo  Form::text('tache_desc[]', $l->desc, array('placeholder'=>'Description de la tâche effectuée','style'=>'width:70%;','class'=>'tache_desc')) ; ?> 
						<?php echo  Form::text('tache_temps[]', $l->duree, array('placeholder'=>'Durée (0.00)','style'=>'width:11%;','class'=>'tache_temps')) ; ?>
						<a class="trashTask btn btn-small btn-danger" href="#" onclick="javascript:trashTask(this)"><i class="icon-trash" style="color:white;"></i></a>
					</li>
					<?php endforeach; ?>
				<?php else: ?>
					<li class="ui-state-default">
						<?php echo  Form::text('tache_date[]', '',array('placeholder'=>'Date (Y-m-d)','style'=>'width:10%;','class'=>'datepicker tache_date')) ; ?> 
						<?php echo  Form::text('tache_desc[]', '',array('placeholder'=>'Description de la tâche effectuée','style'=>'width:70%;','class'=>'tache_desc')) ; ?> 
						<?php echo  Form::text('tache_temps[]', '' ,array('placeholder'=>'Durée (0.00)','style'=>'width:11%;','class'=>'tache_temps')) ; ?>
						<a class="trashTask btn btn-small btn-danger" href="#" onclick="javascript:trashTask(this)"><i class="icon-trash" style="color:white;"></i></a>
					</li>
				<?php endif; ?>
			</ul>
			<div style="text-align:center;margin-top:10px;"><button class="btn btn-success" id="add_article"><i class="icon-plus"></i> Ajouter une tâche effectuée</button></div>
						
		</div>
	</div>
</div>
<script type="text/javascript">
function trashTask(e){
	if(confirm("<?php echo __('admin.etes_vous_sur'); ?>"))
		$(e).parent().remove();
	else
		return false;
}

$('.datepicker').datepicker({
	dateFormat: 'yy-mm-d'
});

$(function() {
	<?php if(Session::get('type') && Session::get('type')=='success_trash'): ?>
		$('#myTab a:last').tab('show');
	<?php endif; ?>
	
	$("#add_article").on('click',function(e){
    	e.preventDefault();
	    $("#sortable").append('<li class="ui-state-default"><?php echo  Form::text('tache_date[]', '',array("placeholder"=>"Date (Y-m-d)","style"=>"width:10%;","class"=>"datepickerbis tache_date")) ; ?> <?php echo  Form::text('tache_desc[]', '',array("placeholder"=>"Description de la tâche effectuée","style"=>"width:70%;","class"=>"tache_desc")) ; ?> <?php echo  Form::text('tache_temps[]', '' ,array("placeholder"=>"Durée (0.00)","style"=>"width:11%;","class"=>"tache_temps")) ; ?> <a class="trashTask btn btn-small btn-danger" href="#" onclick="javascript:trashTask(this)"><i class="icon-trash" style="color:white;"></i></a></li>');
	    $('.datepickerbis').datepicker({
			dateFormat: 'yy-mm-d'
		});
		return false;
    });
});
</script>

