@extends('layouts.master')

@section('style')
    <link href="{{URL::asset('assets/dropzone/dropzone.css')}}" rel="stylesheet" type="text/css"/>

    <style type="text/css">
        .cls-show-time{
        color: #000;
        font-style: italic;
        font-size: 12px;
        }
    </style>
@endsection

@section('content')
<!-- Main content -->
<section class="content">
    <!-- Main row -->
    <div class="row">
        <div class="col-md-7">
            <section class="panel tasks-widget">
                <header class="panel-heading">
                    WORK PROGRESS
                </header>
                <div class="table-responsive project-list">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th colspan="2">
                                    Project Name
                                </th>
                                <th>
                                    Client
                                </th>
                                <th>
                                    Description
                                </th>
                                <th>
                                    Action
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                        @if (session('data'))
                            <div class="alert alert-success">
                                {{ session('data') }}
                            </div>
                        @endif
                            @foreach($projj as $proj)
                                <tr>
                                    <td>

                                        <div class="task-checkbox">
                                            <input class="flat-grey" type="checkbox"/>
                                        </div>
                                    </td>
                                    <td>
                                        <a href="{{url("admin/project_details/$proj->id")}}">{{$proj->name}}</a>
                                        <span class="cls-show-time">
                                            @if(count($proj->tasks) > 0)
                                                <?php 
                                                    $pend = 0;
                                                    $donee = 0;
                                                    $not_assign = 0;
                                                ?>

                                                @foreach($proj->tasks as $pt)
                                                    @if($pt->user_id == 0)
                                                        <?php $not_assign++; ?>
                                                    @elseif($pt->status < 6 && $pt->user_id > 0)
                                                        <?php $pend++; ?>
                                                    @elseif($pt->status == 6)
                                                        <?php $donee++; ?>
                                                    @endif
                                                @endforeach
                                                <br>
                                                Not Assigned: {{$not_assign}},
                                                Pending: {{$pend}},
                                                Done: {{$donee++}}
                                            @else
                                                {{"No tasks added"}}
                                            @endif
                                        </span>
                                        <br>
                                            <small>
                                                <i class="fa fa-clock-o">
                                                </i>
                                                Created {{$proj->created_time}}
                                            </small>
                                        </br>
                                    </td>
                                    <td>
                                        {{$proj->client->name or 'No client selected'}}
                                    </td>
                                    <td>
                                        {{str_limit($proj->description, $limit = 30, $end = '...')}}
                                    </td>
                                    <td>
                                        <a href="" style="color: #7dcc93;">
                                            <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                                        </a>
                                        &nbsp;  &nbsp;
                                        <a onclick="return confirm ('want to delete?')" href="{{url("admin/remove_proj/$proj->id")}}" style="color:#FD4B39;">
                                            <i class="fa fa-times" aria-hidden="true"></i>
                                        </a>

                                        <input type="hidden" id="proj_id" value="{{$proj->id}}">

                                        &nbsp;  &nbsp;
                                        <i class="fa fa-paperclip upload-cls" aria-hidden="true" data-toggle="modal" data-target="#att_modal"></i>
                                    </td>
                                </tr>   
                            @endforeach
                            
                            
                        </tbody>
                    </table>
                    <hr>
                    </hr>
                </div>
                <div class="panel-body">
                    <div class=" add-task-row">
                    </div>
                    <div class="table-foot">
                       
                    </div>
                </div>
            </section>
        </div>
        <div class="col-md-5">
            <div class="panel">
                <header class="panel-heading">
                    Add Project
                </header>
                <div class="ibox-content">

                    @include('layouts.message')

                    <form role="form" action="{{url('admin/add_proj')}}" method="POST">
                        {!! csrf_field() !!}
                        <div class="form-group">
                            <label for="Add new Project">
                                New Project
                            </label>
                            <input name="proj_name" class="form-control" id="new-project" placeholder="Add new project" required="" type="new-project">
                            </input>
                        </div>
                        <div class="form-group">
                            <label for="Add new Project">
                                Client
                            </label>
                            <select name="client_id" id="" class="form-control">
                                <option>Select client</option>
                               @foreach($client_list as $client)
		                        <option value="{{ $client->id }}">{{ $client->name }}</option>
		               @endforeach
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="Add new Project">
                                Description
                            </label>
                            <textarea name="description" rows="5" class="form-control" id="new-project" placeholder="Add new project" ></textarea>
                        </div>
                        <div class="form-group">
                            <button class="btn btn-info" type="submit">
                            Submit
                            </button>
                        </div>
                    </form>
                    <p>
                    </p>
                    
                </div>
               
            </div>
        </div>
    </div>
</section>
<!-- row end -->
<!-- /.content -->

<!-- MODAL ATTATCHMENTSSS -->
<div class="modal fade" tabindex="-1" id="att_modal" role="dialog">
  <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">Attachment</h4>
      </div>
      <div class="modal-body">
        <form action="{{url('admin/add_file')}}" class="dropzone" id="my-awesome-dropzone">
            {!! csrf_field() !!}
            
            <input type="hidden" name="proj_id" class="cls-proj-id" value=""> 
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
@endsection

@section('script')
    <script src="{{URL::asset('assets/dropzone.js')}}" type="text/javascript"></script>

    <script type="text/javascript">
        
        $('.upload-cls').click(function(event) {
            
            var id = $(this).prev('input').val();
            $('.cls-proj-id').val(id);
        });
    </script>
@endsection
