@extends('layouts.master')

@section('content')
<!-- Main content -->
<section class="content">
    <!-- Main row -->
    <div class="row">
        <div class="col-md-12">
            <section class="panel tasks-widget">
                <header class="panel-heading" style="height:40px;">
                    <div class="pull-left">
                        {{$title}}
                    </div>
                    <div>
                        <button class="btn btn-success btn-xs pull-right" data-toggle="modal" data-target=".add-modal">Add Address Book Info</button>
                    </div>
                </header>
                <div class="table-responsive project-list">

                @if(Session::has('msg'))
                    {{Session::get('msg')}}
                    {{"sdjflsdfjls"}}

                @endif
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>
                                    Name
                                </th>
                                <th>
                                    Company name
                                </th>
                                <th>
                                    Designation
                                </th>
                                <th>
                                    Mobile
                                </th>
                                <th>
                                    Email
                                </th>
                                <th>
                                    Action
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                        @if (session('data'))
                            <div class="alert alert-success">
                                {{ session('data') }}
                            </div>
                        @endif
                        @if($all)
                            @foreach($all as $info)
                            <tr>
                                <td>{{$info->name}}</td>
                                <td>
                                    {{$info->company->name or ''}}
                                </td>
                                <td>
                                    {{$info->designation}}
                                </td>
                                <td>
                                    Mobile 01 # {{$info->mob1}} <br>
                                    Mobile 02 # {{$info->mob2}} 
                                </td>
                                <td>
                                    Email 01 # {{$info->email1}} <br>
                                    Email 02 # {{$info->email2}} 
                                </td>
                                <td>
                                    <input type="hidden" id="proj_id" value="{{$info->id}}">
                                    <button class="btn btn-xs edit-btn" data-toggle="modal" data-target=".edit-company" style="color: #7dcc93;">
                                        <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                                    </button>
                                    &nbsp;  &nbsp;
                                    
                                    <a onclick="return confirm ('want to delete?')" href="{{url("admin/address_book/$info->id")}}">
                                        <button class="btn btn-xs" style="color:#FD4B39;">
                                            <i class="fa fa-times" aria-hidden="true"></i>
                                        </button>
                                    </a>
                                    
                                </td>
                            </tr>
                            @endforeach
                        @endif 
                        </tbody>
                    </table>
                    <hr>
                    </hr>
                </div>
                <div class="panel-body">
                    <div class=" add-task-row">
                    </div>
                    <div class="table-foot">
                        <ul class="pagination pagination-sm no-margin ">
                            <li>
                                <a href="#">
                                    «
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    1
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    2
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    3
                                </a>
                            </li>
                            <li>
                                <a href="#">
                                    »
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
            </section>
        </div>
    </div>
</section>
<!-- row end -->
<!-- /.content -->


<!-- Modal Add Contract person -->
<div class="modal fade add-modal" 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">Add Address Book Info</h4>
      </div>
      <div class="modal-body">

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

            {{ csrf_field() }}
            <div class="form-group in-group">
                <label for="">Name<span class="field_mendatory">*</span></label>
                <input type="text" name="name" required="" class="form-control" id="" placeholder="Contact Person Name" >
            </div>
            <div class="form-group in-group">
                <label for="">Company Name</label>
                <select class="form-control" name="company_name" id="company_name">
                    <option value="0">Select Company Name</option>
                    @if(count($company)>0)
                        @foreach($company as $info)
                            <option value="{{$info->id}}">{{$info->name}}</option>
                        @endforeach
                    @endif
                </select>
            </div>
            <div class="form-group in-group">
                <label for="">Designation</label>
                <input type="text" name="designation" class="form-control" id="" placeholder="Designation" >
            </div>
            <div class="form-group in-group">
                <label for="">Mobile no #01<span class="field_mendatory">*</span></label>
                <input type="text" name="mob1" required="" class="form-control" id="" placeholder="Mobile number" >
            </div>
            <div class="form-group in-group">
                <label for="">Mobile no #02</label>
                <input type="text" name="mob2" class="form-control" id="" placeholder="Optional mobile number" >
            </div>
            <div class="form-group in-group">
                <label for="">Email #01</label>
                <input type="email" name="email1" required="" class="form-control" id="" placeholder="Email address" >
            </div>
            <div class="form-group in-group">
                <label for="">Email #02</label>
                <input type="email" name="email2" class="form-control" id="" placeholder="Optional email address" >
            </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><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!-- Modal Edit Company -->
<div class="modal fade edit-company" 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">Edit Address Book Info</h4>
      </div>
      <div class="modal-body">

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

            {{ csrf_field() }}
            <input type="hidden" name="edit_id" value="" id="edit_id">

            <div class="form-group in-group">
                <label for="">Name<span class="field_mendatory">*</span></label>
                <input type="text" name="edit_name" required="" class="form-control" id="edit_name" placeholder="User name" >
            </div>
            <div class="form-group in-group">
                <label for="">Company Name</label>
                <select class="form-control" name="edit_company_name" id="edit_company_name">
                    <option value="0">Select Company Name</option>
                    @if(count($company)>0)
                        @foreach($company as $info)
                            <option value="{{$info->id}}">{{$info->name}}</option>
                        @endforeach
                    @endif
                </select>
            </div>
            <div class="form-group in-group">
                <label for="">Designation</label>
                <input type="text" name="edit_designation" class="form-control" id="edit_designation" placeholder="Designation" >
            </div>
            <div class="form-group in-group">
                <label for="">Mobile no #01<span class="field_mendatory">*</span></label>
                <input type="text" name="edit_mob1" required="" class="form-control" id="edit_mob1" placeholder="Mobile number" >
            </div>
            <div class="form-group in-group">
                <label for="">Mobile no #02</label>
                <input type="text" name="edit_mob2" class="form-control" id="edit_mob2" placeholder="Optional mobile number" >
            </div>
            <div class="form-group in-group">
                <label for="">Email #01<span class="field_mendatory">*</span></label>
                <input type="email" name="edit_email1" required="" class="form-control" id="edit_email1" placeholder="Email address" >
            </div>
            <div class="form-group in-group">
                <label for="">Email #02</label>
                <input type="email" name="edit_email2" class="form-control" id="edit_email2" placeholder="Optional email address" >
            </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><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
@endsection


@section('script')
<script type="text/javascript">
    $('.edit-btn').click(function(event) {
        
        var id = $(this).prev('input').val();
        
        $.ajax({
            url: "{{url("admin/address_book")}}/"+id+"/edit",
            type: 'GET',
        })
        .done(function(data){

            $('#edit_id').val(data['id']);
            $('#edit_name').val(data['name']);
            $('#edit_designation').val(data['designation']);
        
            var company_name = data['company_name'];
            $("#edit_company_name option[value='"+company_name+"']").prop('selected', true);

            $('#edit_mob1').val(data['mob1']);
            $('#edit_mob2').val(data['mob2']);
            $('#edit_email1').val(data['email1']);
            $('#edit_email2').val(data['email2']);
        });
    });
</script>
@endsection
