@extends('layouts.admin')

@section('title')

  Pubblicità Pagina {{$page->name}}

@stop

@section('content')

    @foreach($aDatas as $idx => $data)
    <div class="row"> 
    <div class="col-xs-2">
      <h2>{{$idx}}</h2>
     </div>
     <div class="col-xs-10 text-right">
      <br><a href="{{ route('pages.advs.create', $page) }}?position={{$idx}}" class="btn btn-success">Aggiungi</a>
     </div>
    </div>
    <div class="row">
     <div class="col-xs-2">
       <img src="/images/{{str_replace(" ", "", $idx)}}.png" style="max-width:180px">
     </div>
     <div class="col-xs-10">
	      <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>Google</th>
                  <th>Immagine</th>
                  <th>Online</th>
                  <th width="50"></th>
                  <th width="50"></th>
                </tr>
                <tbody>
                @foreach($data as $adv)
                  <tr class="adv_row" data-id="{{$adv->id}}" style="cursor:move">
                    <td>{{$adv->name}}</td>
                    <td>{{$adv->google_code}}</td>
                    <td>
                      @if($adv->image != '')
                        <img src="/files/adv/{{$adv->image}}" style="max-width:250px" />
                      @endif
                    </td>
                    <td>{{$adv->online ? 'Si' : 'No'}}</td>
                    <td>
                        <a href="{{ route('pages.advs.edit', array($page, $adv->id)) }}" type="button" class="btn btn-w-m btn-primary">Modifica</a>
                    </td>
                    <td>
                      {!! Form::open(array('class' => 'form-inline', 'method' => 'DELETE', 'route' => array('pages.advs.destroy', array($page, $adv)))) !!}
                          <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>
     </div>
        @endforeach

        
        
      

        <div class="col-xs-2" style="margin-top:50px">
          
        <a href="{{ route('pages.index') }}" class="btn btn-info">Elenco pagine</a>
      </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 = '';
                $(".adv_row").each(function()
                {
                  var id = $(this).attr("data-id");
                  ids += (ids != '' ? ',' : '') + id;
                });
                $.ajax('/admin/adv/sort/' + ids,
                    {
                      success: function (data, status, xhr) {// success callback function
                            $('p').append(data);
                      }
                });
            }
        });
            
        });

    </script>
@stop