@extends('layouts.app')

@section('content')
<div class="card">
    <div class="card-body">
        <h4 class="card-title">Pending Business Partners</h4>
        <div class="table-responsive">
            <table class="table table-bordered" id="users-table">
                    <thead>
                        <tr>
                            <th>Id</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Sponsor</th>
                            <th>Commission Rate</th>
                            <th>Created At</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                </table>
        </div>
    </div>
</div>
<!-- The Modal -->
<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">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title">Business Partner</h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
        Modal body..
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>

    </div>
  </div>
</div>

@stop

@section('javascript')
    <script>
        $('#users-table').DataTable({
                processing: true,
                serverSide: true,
                ajax: '{!! url('/') !!}/admin/users/anydataPendingUsers',
                dom: 'Blfrtip',
                'pageLength': 30,
                'lengthMenu': [ [10, 30, 50, -1], [10, 30, 50, "All"] ],
                'buttons': [
                            'copy', 'csv', 'excel', 'pdf', 'print'
                        ],
                'columns': [
                    { data: 'id', name: 'id' },
                    { data: 'full_name', name: 'full_name' },
                    { data: 'email', name: 'email' },
                    { data: 'sponsor', name: 'sponsor' },
                    { data: 'commission_rate', name: 'commission_rate' },
                    { data: 'created_at', name: 'created_at' },
                    { data: 'action', name: 'action' }
                ],
                'order': [[0, 'asc']],
                drawCallback: function( settings ) {
                    openModal();
                  },
                initComplete: function() {
                    
                }
            });

            function openModal(){
                $('.openModal').click(function(){
              	 $('#loadModalAjax .modal-body').load('{{ url('/') }}/admin/users/' + $(this).attr('data-id') + '/edit',function(result){
            	    $('#loadModalAjax').modal({show:true});
                  //init_validation('#updateStudentForm', rules, messages);
            	   });
                });
                
                $('.activate').click(function(){
                    var ele = $(this);
                    $.ajax({
                       url: '{{ url('/') }}/admin/users/ajax_update/' + $(this).attr('data-id'),
                       type: 'PUT',
                       data: { "_token": "{{ csrf_token() }}", id : $(this).attr('data-id'), active : $(this).attr('data-active') },
                       success: function(response) {
                         if(response == true){
                            if(ele.attr('data-active') == 1){
                                ele.removeClass('btn-warning').addClass('btn-danger').attr('data-active','0').find('span.ladda-label').text('Deactivate');
                            }else{
                                ele.removeClass('btn-danger').addClass('btn-warning').attr('data-active','1').find('span.ladda-label').text('Activate');
                            }
                         }else{
                            alert('error'+ response);
                         }
                       }
                    });
                });              
                

                $('.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
