@extends('layouts.admin')

@section('title')

Gestione layout, news e banner

@stop

@section('content')
<p>Trascina le righe per ordinare gli elementi</p>
	   <div class="row">

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

      </div>

        <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>Nome</th>
                  <th class="hidden-xs">Tipo</th>
                  <th class="hidden-xs">Layout</th>
                  <th width="50"></th>
                  <th width="50"></th>
                  <th width="50"></th>
                  <th width="50"></th>
                  <th width="50"></th>
                </tr>
                <tbody>
                @foreach($sections as $section)
                	<tr class="section_row" data-id="{{$section->id}}" style="cursor:move">
                    <td>{{$section->name}}</td>
                    <td class="hidden-xs">{{$section->type == 'section' ? 'Nazionale' : 'Regionale'}}</td>
                    <td class="hidden-xs"><img src="/images/{{$section->layout}}.png" style="width:150px"></td>
                    <td>
                      <a href="#" onclick="if (confirm('Sei sicuro di voler convertire questa sezione in un evento?')) document.location.href='{{ route('sections.to_event', array($section->id)) }}';" type="button" class="btn btn-w-m btn-primary">Trasforma in evento</a>
                    </td>
                    <td>
                      <a href="{{ route('sections.advs.index', array($section->id)) }}" type="button" class="btn btn-w-m btn-primary">Pubblicità</a>
                    </td>
                    <td>
                      <a href="{{ route('sections.layout', array($section->id)) }}" type="button" class="btn btn-w-m btn-primary">News</a>
                    </td>
                    <td>
                        <a href="{{ route('sections.edit', array($section->id)) }}" type="button" class="btn btn-w-m btn-primary"><i class="fa fa-pencil" aria-hidden="true"></i></a>
                    </td>
                    <td>
                      {!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('sections.destroy', $section->id))) !!}
                          <button type="submit" class="btn btn-w-m btn-danger" onclick="return confirm('Sei sicuro?')"><i class="fa fa-trash" aria-hidden="true"></i></button>
                      {!! Form::close() !!}
                    </td>
                	</tr>
                @endforeach
                </tbody>
              </table>
            </div>

          </div>

        </div>

        <div class="col-xs-8">
          <a href="{{ route('sections.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",
            scroll: true,
            stop: function( ) {
                var ids = '';
                $(".section_row").each(function()
                {
                  var id = $(this).attr("data-id");
                  ids += (ids != '' ? ',' : '') + id;
                });
                $.ajax('/admin/sections/sort/' + ids,
                    {
                      success: function (data, status, xhr) {// success callback function
                            $('p').append(data);
                      }
                });
            }
        });

        });

    </script>
@stop
