@extends('layouts.admin')

@section('title')

Gestione categorie e gironi

@stop

@section('content')

	   <div class="row">

      <div class="col-xs-8">
        <a href="{{ route('categories.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">Raggruppamento</th>
                  <th width="50"></th>
                  <th width="50"></th>
                  <th width="50"></th>
                </tr>
                <tbody>
                @foreach($categories as $category)
                	<tr class="category_row" data-id="{{$category->id}}" >
                    <td>{{$category->name}}</td>
                    <td class="hidden-xs">{{$category->type == 'nation' ? 'Nazionale' : 'Regionale'}}</td>
                    <td>{{$category->grp}}</td>
                    <td>
                      <a href="{{ route('categories.groups.index', array($category->id)) }}" type="button" class="btn btn-w-m btn-primary">Gironi</a>
                    </td>
                    <td>
                        <a href="{{ route('categories.edit', array($category->id)) }}" type="button" class="btn btn-w-m btn-primary"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
                    </td>
                    <td>
                      {!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('categories.destroy', $category->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('categories.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 = '';
                $(".category_row").each(function()
                {
                  var id = $(this).attr("data-id");
                  ids += (ids != '' ? ',' : '') + id;
                });
                $.ajax('/admin/categories/sort/' + ids,
                    {
                      success: function (data, status, xhr) {// success callback function
                            $('p').append(data);
                      }
                });
            }
        });
        */

        });

    </script>
@stop
