@extends('layouts.default')

@section('title')
	@parent
	Проверка звонков
@stop

@section('breadcrumbs')
	{{ Breadcrumbs::render('checkcalls') }}
@stop

@section('modals')
	<div id="confirmModal" class="modal fade">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title">Подтвердите действие</h4>
				</div>
				<div class="modal-body">
				</div>
				<div class="modal-footer">
					<button id="confirmSbmtBtn" type="submit" class="btn btn-primary ladda-button" data-style="zoom-out" data-modal-id="confirmModal"><span class="ladda-label">Да</span></button>
					<button type="button" class="btn btn-default" data-dismiss="modal">Нет</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal-dialog -->
	</div><!-- /.modal -->
@stop

@section('css')
  <link rel="stylesheet" href="{{asset('css/360player.css')}}">
@stop

@section('js')
	<script>
		$(document).ready(function(){
			$('.callcheckForm').submit(function(){
				$('#confirmModal .modal-body').html('<h4>Сохранить информацию по звонку?</h4>');
				$('#confirmSbmtBtn').data('action', $(this).attr('action'));
				$('#confirmSbmtBtn').data('formId', $(this).attr('id'));
				$('#confirmModal').modal('show');
				return false;
			});

			$('#confirmSbmtBtn, .btn-delete').click(function(){
				var l = Ladda.create(this);
				l.start();
				var btn = $(this);
				$.post(
								$(this).data('action'),
								$('#'+$(this).data('formId')).serializeArray(),
								function(data) {
									if (data.status === 'success') {
										$('#'+btn.data('formId')).parent().parent().fadeOut();
									}
									$('#confirmModal').modal('hide');
									if (btn.data('reload')) {
										location.reload();
									}
								},
								'json'
								).always(function() { l.stop(); });
				return false;
			});
		});
	</script>
@stop

@section('content')
	@foreach ($pageProjects as $project)
		<div class="panel panel-default">
			<div class="panel-heading">
				<h4>{{ $project->name }}</h4>
			</div>
			<div class="panel-body">
				@if(!$project->checkcalls->count())
					Нет звонков для проверки
				@else
				<table class="table">
						<thead>
							<tr>
								<th>Менеджер / Время</th>
								<th>Звонок</th>
								<th>Контрольные вопросы</th>
							</tr>
						</thead>
						<tbody>
							@foreach($project->checkcalls()->whereStatus(0)->get() as $checkcall)
								<tr>
									<td>
										{{ $checkcall->user->first_name }} {{ $checkcall->user->last_name }}<br/><span class="date-to-humanize" data-date="{{ $checkcall->mlsitcall->call_date }}">{{ $checkcall->mlsitcall->call_date }}</span>
									</td>
									<td>
										@if(!$checkcall->mlsitcall->call_state)
										<?php
											$checkcall->mlsitcall->checkStatus();
										?>
										@endif
										({{ $checkcall->mlsitcall->getStatusName() }})
										@if($checkcall->mlsitcall->call_state == Mlsitcall::STATUS_ANSWERED)
											<div class="ui360">
												<a href="{{ action('PartnerController@getCallFile', array($checkcall->mlsitcall->id)) }}"></a>
											</div>
											<a target="_blank" href="{{ action('PartnerController@downloadCallFile', array($checkcall->mlsitcall->id, $checkcall->mlsitcall->filename)) }}">скачать</a>
										@endif
									</td>
									<td>
										{{ Form::open(array('action' => array('CheckcallsController@update', $checkcall->id), 'class' => 'form-horizontal callcheckForm', 'id' => $checkcall->id)) }}
											@foreach ($project->checkquestions as $checkquestion)
												<label class="checkbox-inline">
													<input type="checkbox" name="checkquestions[{{ $checkquestion->id }}]" /> {{ $checkquestion->name }}
												</label>
												<br/>
											@endforeach
											<br/>
											{{ Form::submit('Сохранить', array('class' => 'btn btn-primary'))}}
											<button type="button" class="btn btn-danger btn-delete ladda-button" data-style="zoom-out" data-reload="1" data-action="{{ action('CheckcallsController@delete', $checkcall->id) }}">Заменить звонок</button>
										{{ Form::close() }}
									</td>
								</tr>
							@endforeach
						</tbody>
					</table>
				@endif
			</div>
		</div>
	@endforeach
@stop
