@extends('layouts.master')

@section('style')

<link href="{{URL::asset('assets/dropzone/dropzone.css')}}" rel="stylesheet" type="text/css" />
<style type="text/css">
    .panel-body{
        color: #4d4d4d;
    }
    .cls-assign:hover{
        color:#1ab394;
    }
    .cls-show-time{
        color: #000;
        font-style: italic;
        font-size: 11px;
    }
    
</style>
@endsection
@section('content')
<!-- Main content -->
<section class="content">
    <!-- Main row -->
    <div class="row">
        <div class="col-md-9">
            @if(!empty($self->description))
            <div class="col-md-12">
                <section class="panel tasks-widget">
                    <div class="panel-body">
                        <b>Description:</b> {{$self->description}}
                    </div>
                </section>
            </div>
            @endif
            <div class="col-md-6" style="">
                <div class="panel">
                    <div class="panel-body" role="document">
                        <div class="">
                          <div class="modal-body">
                            <h4 class="modal-title" id="gridSystemModalLabel">ADD TASK</h4>
                            <form role="form" action="{{url('user/add_task')}}" method="POST">
                                {!! csrf_field() !!}
                                <input type="hidden" name="proj_id" value="{{$project_id}}">

                                <div class="form-group">
                                    <label for="Add new Project">
                                        New Task
                                    </label>
                                    <input name="name" class="form-control" id="new-project" placeholder="Add new task" required="" type="new-project">
                                    </input>
                                </div>
                            
                                <div class="form-group">
                                    <label for="Add new Project">
                                        Description
                                    </label>
                                    <textarea name="description" class="form-control" id="editor1" placeholder="Description" rows="5"></textarea>
                                </div>

                                <div class="form-group">
                                    <label for="Add new Project">
                                        Deadline
                                    </label>
                                    <br>
                                    <input type="text" id="test" name="dead_line" class="form-control">
                                </div>
                          
                            <button type="submit" class="btn btn-primary">Add</button>
                          </div>
                          </form>  
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <section class="panel tasks-widget">
                    <header class="panel-heading">
                        Pending
                    </header>
                    <div class="panel-body">
                        <div class=" add-task-row">
                            <?php $count=1; ?>
                            
                            <input type="hidden" class="cls-project-id" value="{{$project_id}}">

                            @if(!empty($pending))
                            @foreach($pending as $tsk)
                                {{$count++.'. '}}
                                {{-- {{$tsk->name}} --}}

                                <input type="hidden" value="{{$tsk->id}}">
                                
                                <span class="cls-assign" data-toggle="modal" data-target=".bs-example-modal-lg" aria-hidden="true" style="cursor:pointer;">{{$tsk->name}}</span>
                                <span style="color:green;">
                                    @if($tsk->priority == 1)
                                        (Low)
                                    @elseif($tsk->priority == 2)
                                        (Mid)
                                    @elseif($tsk->priority == 3)
                                        (High)
                                    @endif
                                </span>
                                <span class="cls-show-time">
                                    @if($tsk->user_id > 0)
                                        A:{{date("d-m-Y/ H:i",strtotime($tsk->assign_time))}}
                                    @else
                                        C:{{date("d-m-Y/ H:i",strtotime($tsk->created_time))}}
                                    @endif
                                    @if(date("Y",strtotime($tsk->dead_line))>2000)
                                        <span style="color:red;">
                                            Dline:{{date("d-m-Y/ H:i",strtotime($tsk->dead_line))}}
                                        </span>
                                    @endif
                                </span>
                                    

                                @if($tsk->user_id == 0)
                                    <span style="color:#32CD32"><b>(!)</b></span>
                                @endif

                                {{-- <a onclick="return confirm ('want to delete?')" href="{{url("admin/remove_task/$tsk->id")}}" data-toggle="tooltip" title="Remove {{$tsk->name}}" style="color:#FD4B39;">
                                            <i class="fa fa-times pull-right" aria-hidden="true"></i>
                                </a> --}}
                                <span class="pull-right">
                                    <input type="checkbox" data-id="{{$tsk->id}}" class="change-to-inprocess" data-toggle="tooltip" title="{{$tsk->name}}">In-process
                                </span>

                                <br>
                            @endforeach
                            @endif
                        </div>
                        <div class="table-foot">
                            
                        </div>
                    </div>
                </section>
            </div>
            <div class="col-md-6">
                <section class="panel tasks-widget">
                    <header class="panel-heading">
                        In process
                    </header>
                    <div class="panel-body">
                        <div class=" add-task-row">
                            <?php $count=1; ?>
                            @if(!empty($in_process))
                            @foreach($in_process as $tsk)
                                {{$count++.'. '}}

                                {{-- {{$tsk->name}} --}}

                                <input type="hidden" value="{{$tsk->id}}">
                                
                                <span class="cls-assign" aria-hidden="true" style="cursor:pointer;">{{$tsk->name}}</span>
                                <span style="color:green;">
                                    @if($tsk->priority == 1)
                                        (Low)
                                    @elseif($tsk->priority == 2)
                                        (Mid)
                                    @elseif($tsk->priority == 3)
                                        (High)
                                    @endif
                                </span>
                                <span class="cls-show-time">
                                    S:{{date("d-m-Y/ H:i",strtotime($tsk->start_time))}}
                                    # E:{{date("H:i",strtotime($tsk->estimated_time))}}
                                    @if(date("Y",strtotime($tsk->dead_line))>2000)
                                        <span style="color:red;">
                                            #Dline:{{date("d-m-Y/ H:i",strtotime($tsk->dead_line))}}
                                        </span>
                                    @endif
                                </span>

                                {{-- <a onclick="return confirm ('want to delete?')" href="{{url("admin/remove_task/$tsk->id")}}" data-toggle="tooltip" title="Remove {{$tsk->name}}" style="color:#FD4B39;">
                                            <i class="fa fa-times pull-right" aria-hidden="true"></i>
                                </a> --}}

                                <span class="pull-right">
                                    <input type="checkbox" data-id="{{$tsk->id}}" class="change-to-done"  data-toggle="tooltip" title="{{$tsk->name}}">Done
                                </span>

                                <br>
                            @endforeach
                            @endif
                        </div>
                        <div class="table-foot">
                        
                        </div>
                    </div>
                </section>
            </div>
            
        </div>
            
        <div class="col-md-3">
            <div class="panel" style="margin-bottom:40px;">
                <a href="{{url("user/uproject_details/$project_id")}}" class="btn btn-success pull-right">Proj Details -></a>
            </div>
            <div class="panel">
                <header class="panel-heading">
                    USERS
                </header>
                <div class="panel-body">
                    <div class=" add-task-row">
                        @if(!empty($proj_assign_user))
                            <?php $count_a =1 ; ?>
                            @foreach($proj_assign_user as $info)
                                {{$count_a++.'. '.$info->one_user->name}}
                                @if($info->pm_status == 1)
                                    <span style="color:#48C2A9;">{{"- PM"}}</span>
                                @endif
                               
                                <br>
                            @endforeach
                        @endif
                    </div>
                </div>
                <header class="panel-heading">
                    DOCUMENT
                    <button class="btn btn-success btn-xs pull-right upload-cls" data-toggle="modal" data-target="#att_modal"><i class="fa fa-plus-circle" aria-hidden="true"></i> ADD DOC.</button> 
                </header>
                <div class="panel-body">
                    <div class=" add-task-row">
                        @if(!empty($documents))
                            <?php $count_a =1 ; ?>
                            @foreach($documents as $info_document)
                                {{$count_a++.'. '}}
                                <a style="color:#4d4d4d;" target="_blank" href="{{url("assets/document/project/$info_document->url")}}">{{$info_document->name}}</a>
                                <a onclick="return confirm ('want to delete?')" href="{{url("user/remove_proj_document/$info_document->id")}}" data-toggle="tooltip" title="Remove {{$info_document->name}}" style="color:#FD4B39;">
                                            <i class="fa fa-times pull-right" aria-hidden="true"></i>
                                </a>
                                <br>
                            @endforeach
                        @endif
                    </div>
                </div>
                <header class="panel-heading">
                    ACTIVITY LOG
                </header>
                <div class="panel-body" style="overflow: scroll; height:450px;">
                    <div class=" add-task-row">
                    @if(!empty($logss))
                        <?php $countt =1 ; ?>
                        @foreach($logss as $logg)
                            {{$countt++.". "}}
                            {!! $logg->msg !!}
                            - {{$logg->one_user->name}}
                            <br>
                        @endforeach
                    @endif
                    </div>
                </div>
            </div>

        </div>
    </div>
</section>
<!-- row end -->
<!-- /.content -->


<!-- Assign task finished -->
<!--  Assign modal -->
<!--  Assign modal -->
@include('user.modal_assign_task')


@endsection

@section('script')
<link rel="stylesheet" href="{{ URL::asset('assets/css/jquery.datetimepicker.css') }}">
<script type="text/javascript" src="{{ URL::asset('assets/js/jquery.datetimepicker.full.min.js') }}"></script>
<script src="{{URL::asset('assets/dropzone.js')}}" type="text/javascript"></script>
<script src="{{URL::asset('assets/ckeditor/ckeditor.js')}}"></script>
<script type="text/javascript">
    $('.bs-example-modal-lg').on('shown.bs.modal', function () {
        datePicker1();
    });
    function datePicker1(){
        $( "#test2" ).datetimepicker({
        });
    }
    $(document).ready(function(){
        $( "#test" ).datetimepicker({

        });
        $('.cls-group').hide();    
        $('.cls-user').hide();  
        $('.show-change-btn').hide();
        $('input:checkbox').removeAttr('checked');
        CKEDITOR.replace( 'editor1' );
    });

    $('.change-to-inprocess').click(function(event) {
            
            if($(this).prop("checked") == true){

                var task_id = $(this).attr("data-id");
                var status = 2;
                
                if(confirm('Want to change status?')){

                    $('.change-to-inprocess').hide();
                    $.ajax({
                        url: '{{url("user/change_to_inprocess")}}',
                        type: 'POST',
                        data: {task_id: task_id,status: status},
                    })
                    .done(function(){
                        location.reload();
                    });
                }
                
            }
    });

    $('.change-to-done').click(function(event) {
            
            if($(this).prop("checked") == true){

                var task_id = $(this).attr("data-id");
                var status = 6;
                
                if(confirm('Want to change status?')){

                    $('.change-to-done').hide();
                    $.ajax({
                        url: '{{url("user/change_to_inprocess")}}',
                        type: 'POST',
                        data: {task_id: task_id,status: status},
                    })
                    .done(function(){
                        location.reload();
                    });
                }
                
            }
    });

     $('.cls-proj').change(function(event){
        
         var proj_id = $(this).val();
        
         $.ajax({
             url: "{{url("user/change_tast_by_proj")}}",
             type: 'POST',
             data: { proj_id:proj_id},
        })
         .done(function(data){
             $('.cls-tasks').html(data);
         });
        
     });

     $('#id-group-user').change(function(event)
     {    
         var chk_id = $(this).val();

         if(chk_id == 1){
             $('.cls-group').show();    
             $('.cls-user').hide();        
        }
         else if(chk_id == 2){
             $('.cls-group').hide();    
             $('.cls-user').show();
         }
         else{
             $('.cls-group').hide();    
             $('.cls-user').hide();
         }
     });

     $('.cls-assign').click(function(event)
     {
         var proj_id = $('.cls-project-id').val();
         var task_id = $(this).prev().val();
         $('#id_task_id').val(task_id);

         $.ajax({
                 url: "{{url('user/user_list_for_task_assign')}}",
                 type: 'POST',
                 data: {proj_id: proj_id, task_id: task_id},
             })
             .done(function(data) {

                 var status = data[4];
                 if(status > 1)
                 {
                     $('.show-change-btn').show();
                 }
                 else{
                     $('.show-change-btn').hide();
                 }

                 $('.cls-proj-user').html(data[0]);
                 $('.assinged-users').html(data[1]);
                 $('.show-logs').html(data[2]);
                 $('.comments-cls').html(data[3]);
                 $('.cls-task-details').html(data[5]);
           });
                
    });

     $('.assign-task-user').click(function(event)
     {
        var id_estimated_time = $('#test2').val();
        alert(id_estimated_time);
        var id_user_id = $('#id_user_id').val();
        var id_task_id = $('#id_task_id').val();
        
        if(id_estimated_time !=''){
             $.ajax({
                 url: "{{url('user/task_assign_to_user')}}",
                type: 'POST',
                 data: {id_estimated_time: id_estimated_time,id_user_id: id_user_id,id_task_id: id_task_id},
            })
            .done(function(data) {
                 $('.assinged-users').html(data);
             });
         }
         else{
             alert('Please define time estimate!');
        }
        
     });


    $('.assinged-users').on('click','.remove-task-assign-user',function(){

        var id = $(this).prev('input').val();
        var task_id = $('#id_task_id').val();

        $.ajax({
             url: "{{url('user/remove_assign_task_user')}}",
             type: 'POST',
             data: {id: id,task_id: task_id},
         })
         .done(function(data) {
             $('.assinged-users').html(data);
         });

     });

    
    $('.add-task-comment').click(function(event) {
        
         var comment = CKEDITOR.instances.comment_txt.getData();
         var task_id = $('#id_task_id').val();

         if(comment.length > 0){
             $.ajax({
             url: "{{url('user/add_task_comment')}}",
                 type: 'POST',
                 data: {comment: comment,task_id: task_id},
             })
             .done(function(data) {
                
                 $('.comments-cls').html(data);
            });
         }
         else{
             alert('Please fill-up comment field.');
         }
        
     });

     $('.comments-cls').on('click','.edit_comment',function(){
        
         var id = $(this).data('id');
        
         $.ajax({
             url: '{{url('user/edit_comment_form')}}',
             type: 'POST',
             data: {id: id},
         })
         .done(function(data) {
             $('.modal-edit').modal('show');
             $('.update-comment').val(data['comment']);
             $('.update-comment-id').val(data['id']);
         });
        
     });

     $('.comments-cls').on('click','.remove_comment',function(){
        
         var id = $(this).data('id');
         var task_id = $('#id_task_id').val();

         $.ajax({
             url: "{{url('user/remove_comment')}}",
             type: 'POST',
             data: {id: id,task_id: task_id},
         })
         .done(function(data) {
             $('.comments-cls').html(data);
         }); 
     });

     $('.save-updated-comment').click(function(event) {
        
         var id = $('.update-comment-id').val();
        var comment = $('.update-comment').val();
         var task_id = $('#id_task_id').val();

         $.ajax({
             url: '{{url('user/save_update_comment')}}',
             type: 'POST',
             data: {id: id,comment: comment,task_id: task_id},
         })
         .done(function(data) {
             $('.modal-edit').modal('hide');
             $('.comments-cls').html(data);
             $('.update-comment').val('');
             alert('Data updated successfully!');
         });
        
     });

     $('.cls-change-created').click(function(event)
     {
         if(confirm("Are you sure you want to change status ?")) 
        {
             var task_id = $('#id_task_id').val();
             var status = $(this).data('id');
            
            $.ajax({
                 url: "{{url('user/change_to_process')}}",
                 type: 'POST',
                 data: {task_id: task_id, status: status},
            })
             .done(function(data) {
                
                 if(data == 'Yes'){
                    alert('Status Changed !!');
                     location.reload();
                }
                 else{
                    alert('Status Not Changed !!');
                }
             });
            
        }
    });

    $('.upload-cls').click(function(event){

        var id = $('.cls-project-id').val();
        $('.cls-proj-id').val(id);
    });

     $('.add-task-comment-doc').click(function(event){

        var task_id = $('#id_task_id').val();
         $('.cls-task-doc-id').val(task_id);
     });

    $('.attatch-close-btn').click(function(event) {
        
        location.reload();
    });

     $('.attatchment-doc-comment').click(function(event) {
        
         //this event only for fetch the comments after close 
         //attatchemnt dropzone.
         var comment = '';
         var task_id = $('#id_task_id').val();

        $.ajax({
             url: "{{url('user/add_task_comment')}}",
             type: 'POST',
             data: {comment: comment,task_id: task_id},
         })
         .done(function(data){
            
             $('.comments-cls').html(data);
        });        
     });

</script>
@endsection

