prev_company_form.blade.php 4.76 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">Название компании:<span class="red">*</span></label>
                <div class="form-group__item">
                    <input type="text" name="name_company" id="name_company" class="input" value="{{ old('name_company') ?? '' }}" required>
                </div>
            </div>
            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">ФИО сотрудника:<span class="red">*</span></label>
                <div class="form-group__item">
                    <input type="text" name="direct" id="direct" class="input" value="{{ old('direct') ?? '' }}" 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="telephone" id="telephone" class="input" value="{{ old('telephone') ?? '' }}">
                </div>
            </div>
            <div class="cabinet__inputs-item form-group">
                <label class="form-group__label">Телефон сотрудника:</label>
                <div class="form-group__item">
                    <input type="text" name="telephone2" id="telephone2" class="input" value="{{ old('telephone2') ?? '' }}">
                </div>
            </div>
        </div>

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

<div class="hide">
    <div id="after_add_company_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.new_prev_company',['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_company_chat-button" data-fancybox data-src="#after_add_company_chat"></button>
</div>
@endsection

@section('scripts')
    <script>
        $(function(){
            $('.add-company-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_prev_company') }}",
                    data: data,
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('[name="_token"]').val()
                    },
                    success: function(res){
                        spinStop(this_btn);
                        $('.open-after_add_company_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