@extends('layouts.admin')

@section('title')

  Video Home Page
  

@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">  
            <div class="box-body table-responsive no-padding">
              <table class="table table-striped table-hover">
                <thead>
                <tr>
                  <th>Titolo</th>
                  <th>Piattaforma</th>
                  <th>Online</th>
                  <th>Data</th>
                  <th width="50"></th>
                  <th width="50"></th>
                </tr>
              </thead>
              <tbody>
                @foreach($videos as $video)
                  <tr class="video_row" data-id="{{$video->id}}" style="cursor:move">
                    <td><a href="{{ route('videos.edit', array($video->id)) }}" >{{$video->title}}</a></td>
                    <td>{{$video->type}}</td>
                    <td>{{$video->online ? 'Si' : 'No'}}</td>
                    <td>{{date("d/m/Y H:i", strtotime($video->date))}}</td>
                    <td>
                        <a href="{{ route('videos.edit', array($video->id)) }}" type="button" class="btn btn-w-m btn-primary">Modifica</a>
                    </td>
                    <td>
                      {!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('videos.destroy', $video->id))) !!}
                          <button type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')">Elimina</button>
                      {!! Form::close() !!}
                    </td>
                	</tr>
                @endforeach
              </table>
            </div>

          </div>

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


@section('extra_css')

  <link rel="stylesheet" href="/plugins/datatables/dataTables.bootstrap.css">
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css">

@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 = '';
                $(".video_row").each(function()
                {
                  var id = $(this).attr("data-id");
                  ids += (ids != '' ? ',' : '') + id;
                });
                $.ajax('/admin/videos/sort/' + ids,
                    {
                      success: function (data, status, xhr) {// success callback function
                            $('p').append(data);
                      }
                });
            }
        });
            
        });

    </script>
@stop