@extends('layouts.master')

@section('style')
<link href="{{  URL::asset('assets/front_end/css/dragula.css') }}" rel="stylesheet">
<link href="{{  URL::asset('assets/front_end/css/example.css') }}" rel="stylesheet">
<link href="{{  URL::asset('assets/dropzone/dropzone.css')}}" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.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}}
                        <button class="btn btn-success btn-xs pull-right upload-cls"  data-toggle="modal" data-target=".bs-example-modal-lg1"><i class="fa fa-plus-circle" aria-hidden="true"></i> ADD TASK</button> 
                    </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('admin/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">
                                        Type
                                    </label>
                                    <select name="task_type" id="" class="form-control">
                                        <option value="2">Normal</option>
                                        <option value="1">Regular</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="Add new Project">
                                        Priority
                                    </label>
                                    <select name="priority" id="" class="form-control">
                                        <option value="1">Low</option>
                                        <option value="2">Mid</option>
                                        <option value="3">High</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="Add new Project">
                                        Dead Line
                                    </label>
                                    <br>
                                    <b>Date:</b>
                                    <input name="dead_line" class="form-control" id="dead-pik" placeholder="Select dead" required="" type="new-project">
                                    </input>
                                </div>
                                <b>Hours:</b>
                                    <select name="dead_hour">
                                        @for($i=0;$i<=23;$i++)
                                            <option value="{{$i}}">{{$i}}</option>
                                        @endfor
                                    </select>
                                <b>Min:</b>
                                    <select name="dead_min">
                                        @for($i=0;$i<=59;$i+=5)
                                            <option value="{{$i}}">{{$i}}</option>
                                        @endfor
                                    </select>
                                <br>
                                <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>
                          
                            <button type="submit" class="btn btn-primary">Add</button>
                          </div>
                          </form>  
                        </div>
                    </div>
                </div>
            </div>-->
            <div class="row">
                <div class="col-md-12">
                    <div class="col-md-6">
                        <header class="panel-heading col-md-12">
                            Created
                        </header>
                        <div id='left-defaults' class='container' style="min-height:10px">
                            <div style="background: transparent"></div>
                            <input type="hidden" class="cls-project-id" value="{{$project_id}}">
                            <?php $count=1; ?>
                            @if(!empty($tasks))
                                @foreach($tasks as $tsk)
                                <li id='{{$tsk->id}}' class="test ui-state-default" style="list-style-type: none;padding: 8px;background:#fff;margin-top:2%;margin-bottom: 2%">
                                    {{$count++ ."."}} 

                                    
                                    <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
                                    </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>

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

                                    <i class="fa fa-plus-circle pull-right cls-assign"  data-toggle="modal" data-target=".bs-example-modal-lg" aria-hidden="true" style="cursor:pointer;"></i> --}}

                                    <br>
                                @endforeach
                                @else
                                    {{"No task available ..."}}
                                @endif
                                </li>
                        </div>
                    </div>
                    
                    <div class="col-md-6">
                        <header class="panel-heading col-md-12">
                            In process
                        </header>
                        <div id='right-defaults' class='container' style="min-height:10px">
                            <div style="background: transparent"></div>
                            <?php $count=1; ?>
                            @if(!empty($in_process))
                                @foreach($in_process as $tsk)
                                    <li id='{{$tsk->id}}' class="test ui-state-default" style="list-style-type: none;padding: 8px;background:#fff;margin-top:2%;margin-bottom: 2%">
                                        {{$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 class="cls-show-time">
                                                S:{{date("d-m-Y/ H:i",strtotime($tsk->start_time))}}
                                                # E:{{date("H:i",strtotime($tsk->estimated_time))}}
                                            </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>

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

                                            <i class="fa fa-plus-circle pull-right cls-assign"  data-toggle="modal" data-target=".bs-example-modal-lg" aria-hidden="true" style="cursor:pointer;"></i> --}}

                                            <br>

                                    </li>
                                @endforeach
                            @else
                                {{"No task available ..."}}
                            @endif
                        </div>
                    </div>
                    
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="col-md-6">
                        <header class="panel-heading col-md-12">
                            Completed
                        </header>
                        <div id='test1' class='container ' style="min-height:10px">
                            <div style="background: transparent"></div>
                            <?php $count=1; ?>
                            @if(!empty($complete))
                                @foreach($complete as $tsk)
                                    <li id='{{$tsk->id}}' class="test ui-state-default" style="list-style-type: none;padding: 8px;background:#fff;margin-top:2%;margin-bottom: 2%">
                                        {{$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 class="cls-show-time">
                                            S:{{date("d-m-Y/ H:i",strtotime($tsk->start_time))}}
                                            # E:{{date("H:i",strtotime($tsk->estimated_time))}}
                                        </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>

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

                                        <i class="fa fa-plus-circle pull-right cls-assign"  data-toggle="modal" data-target=".bs-example-modal-lg" aria-hidden="true" style="cursor:pointer;"></i> --}}

                                        <br>
                                    </li>
                                @endforeach
                            @else
                                {{"No task available ..."}}
                            @endif
                        </div>
                    </div>
                    <div class="col-md-6">
                        <header class="panel-heading col-md-12">
                            Done
                        </header>
                        <div id='test2' class='container ' style="min-height:10px">
                            <div style="background: transparent"></div>
                            <?php $count=1; ?>
                            @if(!empty($done))
                                @foreach($done as $tsk)
                                    <li id='{{$tsk->id}}' class="test ui-state-default" style="list-style-type: none;padding: 8px;background:#fff;margin-top:2%;margin-bottom: 2%">
                                        {{$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 class="cls-show-time">
                                            S:{{date("d-m-Y/ H:i",strtotime($tsk->start_time))}}
                                            # D:{{date("d-m-Y/ H:i",strtotime($tsk->closing_time))}}
                                            # E:{{date("H:i",strtotime($tsk->estimated_time))}}
                                        </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>

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

                                        <i class="fa fa-plus-circle pull-right cls-assign"  data-toggle="modal" data-target=".bs-example-modal-lg" aria-hidden="true" style="cursor:pointer;"></i> --}}

                                        <br>
                                    </li>
                                @endforeach
                            @else
                                {{"No task available ..."}}
                            @endif
                        </div>
                    </div>
                </div>
            </div>
            <!--<div class="col-md-6">
                <section class="panel tasks-widget">
                    <header class="panel-heading">
                        Notes
                    </header>
                    <div class="panel-body">
                        <div class=" add-task-row">
                        </div>
                        <div class="table-foot">
                           No task available ...
                        </div>
                    </div>
                </section>
            </div>-->
        </div>
            
        <div class="col-md-3">
            <div class="panel">
                <header class="panel-heading">
                    USERS
                    <button class="btn btn-success btn-xs pull-right" data-toggle="modal" data-target="#myModal1"><i class="fa fa-plus-circle" data-toggle="modal" data-target="#myModal1" aria-hidden="true"></i> ADD USER</button> 
                </header>
                <div class="panel-body">
                    <div class=" add-task-row">
                        @if(!empty($proj_assign_user))
                            <?php $count_a =1 ; ?>
                            <table>
                            @foreach($proj_assign_user as $info)
                                <tr>
                                    <td>
                                       {{$count_a++.'. '.$info->one_user->name}} 
                                    </td>
                                    <td>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <input class="cls-pm" value="{{$info->id}}"  data-toggle="tooltip" title="Assign {{$info->one_user->name}} as PM" @if($info->pm_status==1){{'checked'}} @endif type="checkbox"><i class="fa fa-user" aria-hidden="true"></i>
                                        &nbsp;
                                        <a onclick="return confirm ('want to delete?')" href="{{url("admin/remove_proj_user/$info->id")}}" data-toggle="tooltip" title="Remove {{$info->one_user->name}}" style="color:#FD4B39;">
                                            <i class="fa fa-times" aria-hidden="true"></i>
                                        </a>
                                    </td>
                                </tr> 
                            @endforeach
                            </table>
                        @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 DOCUMENT</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("admin/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 -->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="{{ URL::asset('assets/css/jquery.datetimepicker.css') }}">
<style>
  .container{ list-style-type: none; }  
  .test { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 12px; height: auto; }
  #save{
      cursor: pointer;
  }
</style>

<!-- Modal Add USER -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
     <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 User</h4>

          </div>
          <div class="modal-body">

            <form role="form" action="{{url('admin/assign_project')}}" method="POST">
                {!! csrf_field() !!}

                <input type="hidden" name="proj_id" value="{{$project_id}}">
                
                <div class="form-group">
                    <label for="Add new Project">
                        Add
                    </label>
                    <select name="types" id="id-group-user" class="form-control">
                        <option value="0">Select type</option>
                        <option value="1">Group</option>
                        <option value="2">User</option>
                    </select>
                </div>
                <div class="form-group cls-group">
                    <label for="Add new Project">
                        Group
                    </label>
                    <select name="group_id" id="" class="form-control">
                        @foreach($groups as $grps)
                            <option value="{{$grps->id}}">{{$grps->group_name}}</option>
                        @endforeach
                    </select>
                </div>
                <div class="form-group cls-user">
                    <label for="Add new Project">
                        User
                    </label>
                    <select name="user_id" id="" class="form-control">
                        @foreach($users as $usr)
                            <option value="{{$usr->id}}">{{$usr->name}}</option>
                        @endforeach
                    </select>
                </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">Add</button>
          </div>
          </form>  
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<div class="modal fade bs-example-modal-lg1" tabindex="-1" id="task_add" 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">ADD TASK</h4>
      </div>
      <div class="modal-body">
        <form role="form" action="{{url('admin/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">
                    Type
                </label>
                <select name="task_type" id="" class="form-control">
                    <option value="2">Normal</option>
                    <option value="1">Regular</option>
                </select>
            </div>
            <div class="form-group">
                <label for="Add new Project">
                    Priority
                </label>
                <select name="priority" id="" class="form-control">
                    <option value="1">Low</option>
                    <option value="2">Mid</option>
                    <option value="3">High</option>
                </select>
            </div>
            <div class="form-group">
                <label for="Add new Project">
                    User
                </label>
                <select name="user_id" id="" class="form-control">
                    <option>SELECT A USER</option>
                    @foreach($proj_assign_user as $info1)
                        <option value="{{$info1->one_user->id}}">{{$info1->one_user->name}}</option>
                    @endforeach
                </select>
            </div>
            <div class="form-group">
                <label for="Add new Project">
                    Dead Line
                </label>
                <br>
                <b>Date:</b>
                <input name="dead_line" type="text" class="form-control" id="dead-pik" placeholder="Select Closeing Date and Time" required="">
                </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>
      
            <button type="submit" class="btn btn-primary">Add</button>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default attatchment-doc-comment" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
<!-- Modal assign task -->
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg">
        <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">Assign Task</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-7">
                        <b>Assinged users:</b> 
                        <div class="assinged-users">
                            
                        </div>
                    </div>
                    <div class="col-md-5">
                    

                        <input type="hidden" name="id_task_id" id="id_task_id" value="">
                        
                        <div class="form-group">
                            <label for="Add new Project">
                                User
                            </label>
                            <select name="user_id" id="id_user_id" class="form-control cls-proj-user">
                                
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="Add new Project">
                                Estimated Time
                            </label>
                            <br>
                            <input type="text" id="id_estimated_time" name="estimated_time" class="form-control">
                            
                        </div>

                        <div class="form-group">
                            <button class="btn btn-primary assign-task-user">Assign</button>
                        </div>
                    
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div style="margin-bottom:10px;">
                            <b>Details:</b> <span class="cls-task-details"></span>
                        </div>
                        <textarea class="form-control" name="comment_txt" id="comment_txt" cols="" rows="2" placeholder="Post comment here"></textarea>
                        <button class="btn btn-success add-task-comment" style="margin-top:5px;">Post Comment</button>
                        <button class="btn btn-success add-task-comment-doc" style="margin-top:5px;" data-toggle="modal" data-target="#add_doc_task_modal">Attach Documnet</button>
                        <br><br>
                        <b>Comments:</b><br>
                        <div class="comments-cls"  style="height:400px;overflow:scroll;">
                            
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                    <br/>
                    <b>Activity Logs:</b><br>
                        <div class="show-logs" style="height:150px;overflow:scroll;">
                            
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <div class="row">
                    <div class="col-md-10">
                        Change status to: 
                        <button data-id='2' class="btn btn-primary cls-change-created btn-xs">In-process</button>
                        <span class="show-change-btn">
                            <button data-id='3' class="btn btn-primary cls-change-created btn-xs">Completed</button>
                            <button data-id='4' class="btn btn-primary cls-change-created btn-xs">Checking</button>
                            <button data-id='5' class="btn btn-primary cls-change-created btn-xs">Bug-fixing</button>
                            <button data-id='6' class="btn btn-primary cls-change-created btn-xs">Done</button>    
                        </span>
                    </div>
                    <div class="col-md-2">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Assign task finished -->
<!--  Assign modal -->
@include('admin.modal_assign_task')

@endsection

@section('script')
<script>
    var drag_url="{{ url('/admin/updateDrag') }}";
</script>
<script src="{{ URL::asset('assets/front_end/js/dragula.js') }}"></script>

<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 src="{{URL::asset('assets/front_end/js/plugins/timepicker/bootstrap-timepicker.js')}}"></script>
<script type="text/javascript">
        
    $('.bs-example-modal-lg').on('shown.bs.modal', function () {
        datePicker1();
    });
    $('.bs-example-modal-lg1').on('shown.bs.modal', function () {
        datePicker();
    });
    function tPicker(){
        $('#id_estimated_time').timepicker({
            timeFormat: 'H:i:s',
            template: false,
            //showInputs: false,
            //minuteStep: 5,
            
            //maxHour: 20,
            //maxMinutes: 30,
            //startTime: new Date(0,0,0,15,0,0), // 3:00:00 PM - noon
            //interval: 15 // 15 minutes
        });
    }
    function datePicker(){
        $( "#dead-pik" ).datetimepicker({
        });
    }
    function datePicker1(){
        $( "#id_estimated_time" ).datetimepicker({
        });
    }
    $(document).ready(function(){
             
        $('.cls-group').hide();    
        $('.cls-user').hide();  
        $('.show-change-btn').hide();   
        // Replace the <textarea id="editor1"> with a CKEditor
        // instance, using default configuration.
        CKEDITOR.replace( 'editor1' );
        CKEDITOR.replace( 'comment_txt' );
    });

    $('.cls-proj').change(function(event){
        
        var proj_id = $(this).val();
        
        $.ajax({
            url: "{{url("admin/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('admin/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]);
                $('#id_estimated_time').val(data[6]);
            });
                
    });

    $('.assign-task-user').click(function(event)
    {
        //url('admin/task_assign_to_user')
        //var id_estimated_time = $('#id_estimated_time').val();
        var id_estimated_time = $('#id_estimated_time').val();
        //var min = $('#id_estimated_time_min').val();
        //var id_estimated_time = hours+":"+min+":00";
        
        var id_user_id = $('#id_user_id').val();
        var id_task_id = $('#id_task_id').val();
        
        if(id_estimated_time !=''){
            $.ajax({
                url: "{{url('admin/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('admin/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('admin/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('admin/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('admin/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('admin/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('admin/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);
    });

    $('.cls-pm').click(function(event) {
        
        var id = $(this).val();
        var pm_status;

        if($(this).attr('checked')){
            pm_status = 1 ; //check
        }
        else{
            pm_status = 0 ; //uncheck
        }

        $.ajax({
            url: "{{url('admin/make_pm')}}",
            type: 'POST',
            data: {id: id,pm_status: pm_status},
        })
        .done(function(data) {
            alert(data);
        });
        
    });

    $('.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('admin/add_task_comment')}}",
            type: 'POST',
            data: {comment: comment,task_id: task_id},
        })
        .done(function(data){
            
            $('.comments-cls').html(data);
        });        
    });

    $('#timepicker_hours_2').timepicker({
        hours: {
            starts: 10,
            ends: 40
        },
        rows: 8,
        showPeriodLabels: false,
        showPeriod: false,
        showMinutes: false
    });
</script>
<script src="{{ URL::asset('assets/front_end/js/example.js') }}"></script>
<script>
    
    
    
</script>

@endsection

