@extends('adminlte::page') @section('content')
<?php Fun::lang() ?>
<div class="title-page">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="#">Construction</a></li>
            <li><a href="#">Set Up Information</a></li>
            <li><a href="#">Responsibilities Contractor</a></li>
            <li><a href="#">Edit</a></li>
        </ul>
    </div>
</div>
<div class="page">
    <div class="top-content">
        <div class="row">
            <div class="col-sm-12 col-xs-12">
                <div class="title-page">
                    <div class="pull-left">
                        <h3>Edit Responsibilities Contractor</h3>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 col-xs-12">

            <div class="form-wrapper">
                {!! Form::model($data, ['method' => 'PATCH','route' => ['task-working-construction.update_responsibilities_contractor', $data->id],'enctype'=>'multipart/form-data']) !!}
                <div class="row">
                    <div class="form-group col-sm-6 col-xs-12">
                        <label class="required">Group Work</label>
                        {!! Form::select('group_work', $group_work_types, $data->work_group_id, ['class' => 'form-control select2','id'=>'group_work-id','required']) !!}
                    </div>
                    <div class="form-group col-sm-6 col-xs-12">
                        <label class="required">Category responsibility </label>
                        {!! Form::select('category_responsibility', $category_responsibilies,$data->category_responsibility_id, ['class' => 'form-control select2','required']) !!}
                    </div>
                    <div class="form-group col-sm-6 col-xs-12">
                        <label>Name</label>
                        {!! Form::textarea('name', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')) !!}
                    </div>
                    <div class="form-group col-sm-6 col-xs-12">
                        <label>Description</label>
                        {!! Form::textarea('description', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')) !!}
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <div class="form-group">
                            <button type="submit" class="button_sm button_primary pull-right"><span class="fa fa-save"></span> Save</button>
                            <button type="button" onClick="javascript:history.go(-1)" class="button_sm button_warning pull-right">
                                <span class=" fa fa-arrow-circle-left"></span> Back</button>
                        </div>
                    </div>
                </div>
                <br/>
                {!! Form::close() !!}
            </div>
        </div>
    </div>
</div>
@endsection @section('js')
<script>
    $(document).on("change","#group_work-id",function(){
        var $_value = $(this).val();
        $("#main-spinner").show();
        var route = "{{ route('task-working-construction.get_category_sponsibilities',':id') }}";
        route = route.replace(":id",$_value);
        $.ajax({
            url:route,
            type:"GET",
            dataType:"JSON",
            success:function(data){
                var opt = `<option value="">Please Select</option>`;
                $.each(data,function(index,value){
                    opt += `<option = "${value.id}">${value.name}</option>`;
                });
                $('select[name=category_responsibility]').html(opt);
            },
            complete:function(){
                $("#main-spinner").hide();
            }
        });
    });
    $(document).on("change","#group_work-id",function(){
        var $_value = $(this).val();
        $("#main-spinner").show();
        var route = "{{ route('task-working-construction.get_sub_category_task',':id') }}";
        route = route.replace(":id",$_value);
        $.ajax({
            url:route,
            type:"GET",
            dataType:"JSON",
            success:function(data){
                var opt = `<option value="">Please Select</option>`;
                $.each(data,function(index,value){
                    opt += `<option = "${value.id}">${value.name}</option>`;
                });
                $('select[name=sub_category_task]').html(opt);
            },
            complete:function(){
                $("#main-spinner").hide();
            }
        });
    });
    function add_row_buliding_work(obj)
    {
        var tb_building_work = `
                            <tr>
                                <td>
                                    {!! Form::text('code[]', null, array('placeholder' => 'code','class' => 'form-control','required')) !!}
                                </td>
                                <td>
                                    {!! Form::textarea('name[]', null, array('placeholder' => 'Name','class' => 'form-control','rows'=>'2')) !!}
                                </td>
                                <td>
                                    {!! Form::textarea('description[]', null, array('placeholder' => 'Description','class' => 'form-control','rows'=>'2')) !!}
                                </td>
                                <td><button type="button" class="btn btn-sm btn-danger" onclick="remove(this)">
                                    <span class="fa fa-trash"></span></button>
                                </td>
                            </tr>
        `;
        $(obj).closest('table').find('tbody').append(tb_building_work);
        
    }
    function remove(obj)
    {
        var index = 1;
        var tr_class =  $(obj).closest("table").find('tbody').attr('class');
        $(obj).closest('tr').remove();
        $("tr.tr-table-"+tr_class).each(function(){
            $(this).find('td:eq(0)').html(`<span>${++index}</span>`);
        });
    }
</script>
@endsection