docs.blade.php 6.6 KB
@extends('workers.cabinet_layout', ['title' => 'Добавление стандартного документа - РекаМоре'])

@section('cabinet_content')
<h3 class="cabinet__h4 font30">Место работы</h3>
<div class="cabinet__inputs">
    @csrf
    <input type="hidden" name="worker_id" id="worker_id" class="input" value="{{ $worker->id }}">

    <div class="error-block"></div>

    <div class="cabinet__body-item width100">
        <div class="cabinet__inputs">
            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Должность</label>
                <div class="form-group__item">
                    <input type="text" name="job_title" id="job_title" class="input" value="{{ old('job_title') ?? $doc->job_title ?? '' }}" required>
                </div>
            </div>

            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Название т/х</label>
                <div class="form-group__item">
                    <input type="text" name="teplohod" id="teplohod" class="input" value="{{ old('teplohod') ?? $doc->teplohod ?? '' }}" required>
                </div>
            </div>

            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Тип судна</label>
                <div class="form-group__item">
                    <input type="text" name="GWT" id="GWT" class="input" value="{{ old('GWT') ?? $doc->GWT ?? '' }}" required>
                </div>
            </div>

            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Марка ГД</label>
                <div class="form-group__item">
                    <input type="text" name="Marka_GD" id="Marka_GD" class="input" value="{{ old('Marka_GD') ?? $doc->Marka_GD ?? '' }}">
                </div>
            </div>

            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Мощность (кВт)</label>
                <div class="form-group__item">
                    <input type="text" name="KBT" id="KBT" class="input" value="{{ old('KBT') ?? $doc->KBT ?? '' }}">
                </div>
            </div>

            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Водоизмещение (GRT)</label>
                <div class="form-group__item">
                    <input type="text" name="GRT" id="GRT" class="input" value="{{ old('GRT') ?? $doc->GRT ?? '' }}" required>
                </div>
            </div>

            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Название компании</label>
                <div class="form-group__item">
                    <input type="text" name="name_company" id="name_company" class="input" value="{{ old('name_company') ?? $doc->name_company ?? '' }}" required>
                </div>
            </div>

            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Начало контракта</label>
                <div class="form-group__item">
                    <input type="text" name="Begin_work" id="Begin_work" class="input" value="{{ old('begin_work') ?? $doc->begin_work ?? '' }}">
                </div>
            </div>

            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Окончание контракта</label>
                <div class="form-group__item">
                    <input type="text" name="End_work" id="End_work" class="input" value="{{ old('end_work') ?? $doc->end_work ?? '' }}">
                </div>
            </div>
        </div>

        <div class="flex">
            <button class="button add-place-of-work-button mr-10">Сохранить</button>
            <a href="{{ route('worker.cabinet') }}" class="button button_light">Назад</a>
        </div>
    </div>
</div>

<div class="hide">
    <div id="after_add_place_of_work_chat" class="modal-dialog">
        <div class="modal-dialog-title">
            <h2>Место работы успешно добавлено</h2>
        </div>
        <div class="modal-dialog-body pt-20"></div>
        <div class="modal-dialog-footer center">
            <a href="{{ route('worker.add_document', ['worker' => $worker->id]) }}" class="button remove-chat-button mr-20">Добавить еще</a>
            <a href="{{ route('worker.cabinet') }}" class="button button_light" onclick="$.fancybox.close();">Закончить</a>
        </div>
    </div>
    <button class="open-after_add_place_of_work_chat-button" data-fancybox data-src="#after_add_place_of_work_chat"></button>
</div>
@endsection

@section('scripts')
    <script>
        $(function(){
            $('.add-place-of-work-button').click(function(){
                var this_btn = $(this);
                spinStart(this_btn);
                var wrap = this_btn.closest('.cabinet__inputs');
                var data = {};
                var form_is_not_filled = false;

                wrap.find('.error-block').html('');
                wrap.find('input').removeClass('border-red');

                wrap.find('input').each(function(){
                    var val = $(this).val().trim();

                    if ($(this).is('[required]') && !val){
                        $(this).addClass('border-red');
                        form_is_not_filled = true;
                    }

                    var name = $(this).attr('name');
                    data[name] = val;
                });

                if (form_is_not_filled){
                    spinStop(this_btn);
                    return;
                }

                $.ajax({
                    type: 'POST',
                    url: "{{ route('worker.add_document_save') }}",
                    data: data,
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('[name="_token"]').val()
                    },
                    success: function(res){
                        spinStop(this_btn);
                        $('.open-after_add_place_of_work_chat-button').click();
                    },
                    error: function(jqXHR, exception){
                        if (jqXHR && jqXHR.responseJSON && jqXHR.responseJSON.message){
                            wrap.find('.error-block').html(jqXHR.responseJSON.message);
                        }
                        spinStop(this_btn);
                    }
                });
            });


        });
    </script>
@endsection