@extends('layouts.admin')

@section('title')

  Calendari

@stop

@section('content')

<p>Trascina le righe per ordinare gli elementi</p>
	   <div class="row">
        <div class="col-xs-12">
          <div class="box">

            <div class="box-body table-responsive no-padding">
              <table class="table table-striped table-hover">
                <tr>
                  <th>Tipologia</th>
                  <th>Categoria</th>
                  <th>Girone</th>
                  <th>Stagione</th>
                  <th width="50"></th>
                  <th width="50"></th>
                  <th width="50"></th>
                </tr>
                <tbody>
                  @foreach($calendars as $calendar)
                    <tr class="calendar_row" data-id="{{$calendar->id}}" style="cursor:move">
                      <td>{{$calendar->type == 'nation' ? 'Nazionale' : 'Regionale'}}</td>
                      <td>{{isset($calendar->category) ? $calendar->category->name : ''}}</td>
                      <td>{{isset($calendar->group) ? $calendar->group->name : ''}}</td>
                      <td>{{isset($calendar->season) ? $calendar->season->name : ''}}</td>
                      <td>
                        <a href="{{ route('calendars.games', array($calendar->id)) }}" type="button" class="btn btn-w-m btn-primary">Risultati</a>
                    </td>
                      <td>
                          <a href="{{ route('calendars.edit', array($calendar->id)) }}" type="button" class="btn btn-w-m btn-primary">Importa calendario</a>
                      </td>
                      <td>
                        @if($calendar->archived)
                            <a href="{{ route('calendars.restore', array($calendar->id)) }}" type="button" class="btn btn-w-m btn-success">Ripristina</a>
                        @else
                            <a href="{{ route('calendars.archive', array($calendar->id)) }}" type="button" class="btn btn-w-m btn-warning">Archivia</a>
                        @endif
                    </td>
                      <td>
                        {!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('calendars.destroy', $calendar->id))) !!}
                            <button type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')">Elimina</button>
                        {!! Form::close() !!}
                      </td>
                    </tr>
                  @endforeach
                </tbody>
              </table>
            </div>

          </div>

        </div>
        <div class="col-xs-2">
          <a href="{{ route('calendars.create') }}" class="btn btn-success">Aggiungi</a>
        </div>

      </div>
@stop

@section('extra_js')

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>


    <script>

        $(function () {

          $('tbody').sortable({
            cursor: "move",
            stop: function( ) {
                var ids = '';
                $(".calendar_row").each(function()
                {
                  var id = $(this).attr("data-id");
                  ids += (ids != '' ? ',' : '') + id;
                });
                $.ajax('/admin/calendars/sort/' + ids,
                    {
                      success: function (data, status, xhr) {// success callback function
                            $('p').append(data);
                      }
                });
            }
        });

        });

    </script>
@stop
