/home/mip/mip/app/Modules/Client/Views/officers/index.blade.php
@extends('Client::layouts')
@section('page-body')
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            <i class="fa fa-{{$pageIcon ? $pageIcon : 'angle-double-right'}}" aria-hidden="true"></i> {{$pageTitle}}
            <br>
            <small>{{$pageDescription}}</small>
        </h1>
        <ol class="breadcrumb">
            <li class="active"><i class="fa fa-{{$pageIcon ? $pageIcon : 'angle-double-right'}}"></i> {{$pageTitle}}</li>           
        </ol>
    </section>
    <!-- Main content -->
    <section class="content"> 
        @include('Client::message')
        <div class="box box-primary">
            <div class="box-header with-border">
                <h1 class="box-title">
                    <form class="form-inline">
                        <div class="form-group">
                            <label>Access Type</label>
                            {!! Form::select('access_type', $access_types, null, array('class' => 'form-control', 'placeholder' => ' - All - ')) !!}
                        </div>
                    </form>
                </h1>
                @can('create', $permissions)
                    <span class="pull-right">
                        <a href="{{ route(config('modules.client').'.officer.create') }}" class="btn btn-primary btn-flat"><i class="fa fa-plus-circle"></i> Add {{$pageModuleName}}</a>
                    </span>
                @endcan
            </div>
            <div class="box-body">
                <table class="table table-bordered table-striped table-hover" id="officer-table" width="100%">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Access Type</th>
                            <th>Account Validity</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
               </table>
            </div>                
        </div>
        @include('Client::logs')
    </section>
@stop
@section('page-js')
@include('Client::questionnaire.template.js')
<script type="text/javascript">
$(function() {
    var officerTable = $('#officer-table').DataTable({
        processing: true,
        serverSide: true,
        pagingType:'input',
        "pagingType": "input",
        rowReorder: true,
        ajax: {
            url:'{!! url(config('modules.client').'/officers/get-datatables-index') !!}',
            data: function(d){
                d.access_type = $('select[name="access_type"]').val();
            }            
        },
        columns: [
            {
                width:'10px', searchable: false, orderable: false,
                render: function (data, type, row, meta) {
                    return meta.row + meta.settings._iDisplayStart + 1;
                }
            },
            { data: 'name', name: 'name', orderable:true, searchable: true},
            { data: 'email', name: 'email', orderable:true, searchable: true},
            { data: 'access_type', name: 'access_type', orderable:true, searchable:false},
            { data: 'validity_date', name: 'validity_date', orderable:false, searchable: false, className:'text-center'},
            { data: 'status', name: 'status', orderable: false, searchable: false, className:'text-center'},
            { data: 'action', name: 'action', orderable: false, searchable: false, width:'100px', className:'text-center'},
        ],
        fnDrawCallback: function ( oSettings ) {
            $('[data-toggle="tooltip"]').tooltip();
            officerTable.$("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") {
                                officerTable.draw();
                                swal(data.message, '', 'success')
                           }else{
                                swal(data.message, '', 'error')
                           }
                        },
                        error :function( jqXhr ) {
                            swal('Unable to delete.', 'Please try again.', 'error')
                        }
                    });
                });
            });

        
        },
        "order": [[1, "desc"]],
    });

    $('select[name="access_type"]').on('change', function(){
        officerTable.draw();
    });
});
</script>
@include('Client::notify')
@stop