/home/mip/mip/app/Modules/Client/Views/principals/contact-persons/index.blade.php
@extends('Client::layouts')
@section('page-body')           
     <!-- Content Header (Page header) -->
     <section class="content-header">
          <h1>
               <i class="fa fa-pencil" aria-hidden="true"></i> Manage Contacts
          </h1>
          <ol class="breadcrumb">
               <li><a href="{{ route(config('modules.client').'.settings.principals.index') }}"><i class="fa fa-user-o"></i> Client</a></li>
               <li class="active">Contact</li>  
          </ol>
     </section>
     <!-- Main content -->
     <section class="content">
          @include('Client::errors')
          @include('Client::message')
          <div class="row">
               <div class="col-md-3">
                    @include('Client::principals.navigation', array('active' => 'contact-person'))
               </div>
               <div class="col-md-9">
                    <div class="box box-primary">
                         <div class="box-header">
                              <h1 class="box-title">List of Contacts</h1>
                              @can('create', $permissions)
                              <span class="pull-right">
                                   <a href="{{ route(config('modules.client').'.principals.contact-persons.create', $principal->hashid) }}" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add Contact" class="btn btn-primary btn-flat"><i class="fa fa-plus-circle"></i> Add Contact</a>
                              </span>
                              @endcan
                         </div>
                         <div class="box-body">
                              <table class="table table-bordered table-condensed table-striped" id='contact-persons-table' width="100%">
                                   <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Details</th>
                                            <th>Contact Nos.</th>
                                            <th>Action</th>
                                        </tr>
                                   </thead>
                              </table>
                         </div>
                    </div>
                    @include('Client::logs')
               </div>
          </div>
     </section>
@stop
@section('page-css')
  
@stop
@section('page-js')
<script type="text/javascript">
$(function() {
    var contactTable = $('#contact-persons-table').DataTable({
        processing: true,
        serverSide: true,
        "pagingType": "input",
        ajax: "{!! url(config('modules.client').'/principals/'.$principal->hashid.'/get-contact-persons-data') !!}",
        columns: [
            {
                width:'10px', searchable: false, orderable: false,
                render: function (data, type, row, meta) {
                    return meta.row + meta.settings._iDisplayStart + 1;
                }
            },
            { data: 'contact_details', name: 'contact_details', searchable:false},
            { data: 'contact_numbers', name: 'contact_numbers', searchable: false, orderable: false},
            { data: 'action', name: 'action', orderable: false, searchable: false, width:'50px', className:'text-center'},
        ],
        fnDrawCallback: function ( oSettings ) {
          $('[data-toggle="tooltip"]').tooltip();
          contactTable.$("td").on("click", 'a#btn-delete', function() {
                var action = $(this).data('action');
                swal({
                    title: 'Are you sure you want to delete?',
                    text: "This will be permanently deleted",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes'
                    }).then(function () {                    
                    $.ajax({
                        type: "DELETE",
                        url: action,
                        dataType: 'json',
                        success: function(data) {
                            if(data.type == "success") {
                                contactTable.draw();
                                swal(data.message, '', 'success')
                           }else{
                                swal(data.message, '', 'error')
                           }
                        },
                        error :function( jqXhr ) {
                            swal('Unable to delete.', 'Please try again.', 'error')
                        }
                    });
                })
            });
        },
        "order": [[1, "asc"]],
    });
});
</script>
@include('Client::notify')
@stop