/home/mip/mip/app/Modules/Client/Views/settings/roles/index.blade.php
@extends('Client::layouts')
@section('page-body')

    <section class="content-header">
        <h1>
            <i class="fa fa-ban"></i> Role Manager
             @include('Client::cache.descriptions.'.$permissions->menu_id)
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-cog"></i> Settings</a></li>
            <li class="active">Role</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">        
        @include('Client::message')
        <div class="box box-default">
            <div class="box-header">
                <h3 class="box-title">List of Roles</h3>
                @can('create', $permissions)
                    <a href="{{ url(config('modules.client').'/settings/roles/create') }}" class="btn btn-primary btn-flat pull-right" data-toggle="tooltip" data-placement="top" title="" data-original-title="Add Role"><i class="fa fa-plus-circle"></i> Add Role</a>
                @endcan
            </div>
            <div class="box-body">
                <table class="table table-condensed table-bordered table-striped table-hover" id="roles-table" width="100%">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Name</th>
                            <th>Display Name</th>
                            <th>Action</th>
                        </tr>
                    </thead>
               </table>
            </div>                
        </div>
        @include('Client::logs')
    </section>
@stop
@section('page-js')

<script type="text/javascript">
$(function() {
    var roleTable = $('#roles-table').DataTable({
    processing: true,
    serverSide: true,
    "pagingType": "input",
    ajax: '{!! url(config('modules.client').'/settings/roles/get-roles-data') !!}',
    columns: [
        {
            width:'10px', searchable: false, orderable: false,
            render: function (data, type, row, meta) {
                return meta.row + meta.settings._iDisplayStart + 1;
            }
        },
        { data: 'name', name: 'name' },
        { data: 'display_name', name: 'display_name', sortable: false, searchable: false},
        { data: 'action', name: 'action', orderable: false, searchable: false, width:'50px', className:'text-center'},
    ],
    fnDrawCallback: function ( oSettings ) {
        $('[data-toggle="tooltip"]').tooltip();
        $("#roles-table 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") {
                            roleTable.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