@extends('layouts.master')

@section('content')
<!-- DataTables -->
<link rel="stylesheet" href="{{ asset('/assets/') }}/css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/switch/rcswitcher.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/pnotify.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/sweetalert.css">
<link rel="stylesheet" href="{{ asset('/assets/') }}/alert/sweet-alert-animations.css">

<div class="panel panel-default">
    <!-- Default panel contents -->
    <div class="panel-heading"></div>
        <header class="panel-heading" style="height:50px;">
            <div class="pull-left">
                {{$title}}
            </div>
            <div>
                 @if(\Auth::user()->utype==1)
                    <a href="{{ url('admin/employee/add') }}" class="btn btn-sm btn-info pull-right"><i class="fa fa-plus"></i> Add Employee</a> <br><br>
                @endif
            </div>
        </header>
    <div class="panel-body">
        <div class="clearfix"></div>
        <table class="table table-bordered" id="example">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th>Email Address</th>
                    <th>Phone Number</th>
                    <th>Present Address</th>
                    <th>Status</th>
                    <th width="25%">Action</th>
                </tr>
            </thead>
            <tbody>
            @if($all)
            <?php $i=1;?>
            @foreach($all as $row)
                <tr>
                    <td>{{ $i++ }}</td>
                    <td>{{ $row->name }}</td>
                    <td>{{ $row->personal_email }}</td>
                    <td>{{ $row->phone }}</td>
                    <td>{{ $row->present_address }}</td>
                    <td style="text-align: center;">
                        @if($row->status == 4)
                        <label class="label label-primary"> Resigned</label>
                        @else
                        <label class="label label-success"> Present</label>
                        @endif
                    </td>
                    <td class="parent-action-cls">
                        <a href="{{ url('admin/employee/show') }}/{{ $row->id }}" class='btn btn-default btn-sm' data-toggle="tooltip" title="View" data-placement="top"><i class="fa fa-eye"></i></a>
                        @if(Auth::user()->utype==1)
                        <a href="{{ url('admin/employee/edit_employee') }}/{{ $row->id }}" class='btn btn-default btn-sm' data-toggle="tooltip" title="Edit" data-placement="top"><i class="fa fa-edit"></i></a>

                        <a href="{{ url('admin/employee/delete') }}/{{ $row->id }}" class='btn btn-default btn-sm' onclick="return confirm('Are you sure to delete this item ?')" data-toggle="tooltip" title="Delete" data-placement="top"><i class="fa fa-trash-o"></i></a>

                            @if($row->id == @$row->user->employee_id)
                            <input type="text" name="" class="hidden" value="{{ $row->user['id'] }}" />
                            <button class='btn btn-default btn-sm change-pass' data-toggle="modal" data-target="#change_password" ><i class="fa fa-key"></i> Change Password</button>
                            @else
                            <a href="{{ url('admin/employee/add_user') }}/{{ $row->id }}" class='btn btn-info btn-sm edit-btn' data-toggle="tooltip" title="Employee To User Create" data-placement="top" ><i class="fa fa-plus"></i> Add a User</a>
                            @endif
                        @endif
                    </td>
                </tr>
            @endforeach

            @endif
            </tbody>
        </table>
    </div>
</div>
<!-- Change password start -->
<div class="modal fade" id="change_password" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="gridSystemModalLabel">Change password</h4>
      </div>
      <div class="modal-body">

        <form action="{{url('admin/employee/change_password')}}" method="POST">

            {{ csrf_field() }}

            <input type="hidden" name="emp_id" value="" class="change-pass-user-id">
            
            <div class="form-group">
                <label for="password">Password</label>
                <input type="password" name="password" class="form-control" id="" placeholder="Password" required="">
            </div>
            <div class="form-group">
                <label for="password_confirmation">Confirm Password</label>
                <input type="password" name="password_confirmation" class="form-control" id="password_confirmation" placeholder="Confirm Password" required="">
            </div>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
      </form>  
    </div>
  </div>
</div>
<!-- Change password end -->

@stop

@section('style')
<style>
    .modal-dialog {
      width: 40% !important;
      height: 40% !important;
    }

    .modal-content {
      height: auto;
      min-height: 40% !important;
      border-radius: 0;
    }
</style>
@stop

@section('script')
<script src="{{ asset('/assets/') }}/js/jquery.dataTables.min.js"></script>
<script src="{{ asset('/assets/') }}/js/dataTables.bootstrap.min.js"></script>
<script src="{{ asset('/assets/') }}/switch/rcswitcher.js"></script>
<script src="{{ asset('/assets/') }}/alert/sweetalert.min.js"></script>
<script src="{{ asset('/assets/') }}/alert/pnotify.js"></script>
<script src="{{ asset('/assets/') }}/alert/notify.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
            $('[data-toggle="tooltip"]').tooltip();
            $("input[type='checkbox']").rcSwitcher();
        });

$(document).ready(function() {
    $('body').on('hidden.bs.modal', '.modal', function () {
      $(this).removeData('bs.modal');
    });
    var table=$("#example").DataTable({
         "searching": true,
         "lengthChange": true,
         "ordering": true,
         stateSave: true       
    });
    $('.change-pass').click(function(event) {           
        var id = $(this).parent('.parent-action-cls').children('input').val();
        $('.change-pass-user-id').val(id);      
    });
    
    $("input[type='checkbox']").rcSwitcher().on({'toggle.rcSwitcher': function( e, dataObj, changeType ){
                var id = $(this).data('id');
                var urll="{{ url('admin/employee/status') }}/"+id;
                var msg_success = 'Status Updated Successfully.';
                var msg_error = 'Something went wrong!';
                $.ajax({
                    url:urll,
                    success: function(data){
                      notify('success',msg_success);
                       
                    },
                    error: function (data) {
                        notify('error',msg_error);
                    }
                });
            }
        });
    

});
</script>
@stop
@if(Session::has('msg'))
    <div class="alert alert-success center-block msg_alt" >
        <a class="close" data-dismiss="alert" href="#">&times;</a>
        <strong><i class="fa fa-check"></i></strong>&nbsp;
    {{Session::get('msg')}}
    </div>
@endif