@extends('layouts.app')

@section('content')
<div class="card card-outline-info">
  <div class="card-header">
      <h4 class="m-b-0 text-white">Send New Complaint</h4>
  </div>
  <div class="card-body">
    <div class="x_content">
            {!! Form::open(['method' => 'POST','id'=> 'register_frm', 'data-parsley-validate'=>'', 'url' => [url('/users/sendUcomplaints')]]) !!}
            <div class="row">
                <div class="col-md-12">
                    <div class="form-group">
                        {!! Form::label('subject', 'Subject*', ['class' => 'control-label']) !!}
                        {!! Form::text('subject', '', ['class' => 'form-control form-control-normal', 'placeholder' => 'Subject']) !!}
                        <p class="help-block"></p>
                        @if($errors->has('subject'))
                            <p class="help-block error">
                                {{ $errors->first('subject') }}
                            </p>
                        @endif
                    </div>
                </div>
                <div class="col-md-12">
                    <div class="form-group">
                        {!! Form::label('message', 'Message*', ['class' => 'control-label']) !!}
                        {!! Form::textarea('message','' , ['class' => 'form-control form-control-normal', 'placeholder' => 'Your messsage....']) !!}
                        <p class="help-block"></p>
                        @if($errors->has('message'))
                            <p class="help-block error">
                                {{ $errors->first('message') }}
                            </p>
                        @endif
                    </div>
                </div>
            </div>
        </div>
        <div class="ln_solid"></div>
        <div class="form-group">
          <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
            <button type="submit" class="btn btn-success">Submit</button>
          </div>
        </div>
    {!! Form::close() !!}
    </div>
  </div>
<div class="card">
    <div class="card-body">
        <h3 class="card-title">Previous Complaints</h3>
        <div class="table-responsive">
            <table class="table table-bordered" id="users-table">
                    <thead>
                        <tr>
                            <th>S. No.</th>
                            <th>Subject</th>                            
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                </table>
        </div>
    </div>
</div>
<div class="modal fade" id="loadModalAjax" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="display: none;" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
    </div>
    <!-- /.modal-content -->
   </div>
  <!-- /.modal-dialog -->
</div>
</div>

@stop

@section('javascript')
    <script>
        var t = $('#users-table').DataTable({
                processing: true,
                serverSide: true,
                ajax: '{!! url('/') !!}/users/getComplaint',
                dom: 'frtip',
                'lengthMenu': [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
                columns: [
                    { data: 'id', name: 'id' },
                    { data: 'subject', name: 'subject' },
                    { data: 'user_read', name: 'user_read' },
                    { data: 'action', name: 'action' }
                ],
                "columnDefs": [
                    {
                        "render": function ( data, type, row ) {
                        if(data==0){
                            return '<span class="label label-success">Read</span>';
                        }else{
                            return '<span class="label label-danger">Unread</span>';
                        }
                        },
                        "targets": 2
                    },
                ],
                'order': [[1, 'asc']],
                drawCallback: function( settings ) {
                    openModal();
                  }
            });
            
            function openModal(){
              $('.openModal').click(function(){
                 $('#loadModalAjax .modal-content').load('{{ url('/') }}/users/' + $(this).attr('data-id'),function(result){
                    $('#loadModalAjax').modal({show:true});
                  //init_validation('#updateStudentForm', rules, messages);
                   });
              });
              $('.openModalInvoices').click(function(){
                 $('#loadModalAjax .modal-content').load('/student_invoices_modal.php?id=' + $(this).attr('data-id'),function(result){
                    $('#loadModalAjax').modal({show:true});
                  //init_validation('#updateStudentForm', rules, messages);
                   });
              });
            }

    </script>
@endsection
