answer_from_admin_chat.blade.php 1.92 KB
<div class="hide">
    <div id="answer_from_admin_chat_modal" class="modal-dialog">
        <div class="modal-dialog-title">
            <h2>Ответить работодателю</h2>
        </div>
        <div class="modal-dialog-body">
            <textarea class="textarea" name="text" placeholder="" required></textarea>
        </div>
        <div class="modal-dialog-footer">
            <button type="button" class="button answer-from-admin-chat-button">Отправить</button>
            <button type="button" class="button button_light" onclick="$.fancybox.close();">Закрыть</button>
        </div>
    </div>
</div>

<script>
    $(function (){
        $('.answer-from-admin-chat-button').click(function(){
            spinStart($(this));
            var wrap = $(this).closest('#answer_from_admin_chat_modal');
            var to_user_id = wrap.data('to-user-id');
            var reply_message_id = wrap.data('message-id');
            var textarea = wrap.find('[name="text"]');
            var text = textarea.val()

            textarea.removeClass('border-red');
            if (!text.trim()){
                textarea.addClass('border-red');
                return;
            }

            $.ajax({
                type: "POST",
                url: "{{ route('send_message')  }}",
                data: {
                    to_user_id: to_user_id,
                    reply_message_id: reply_message_id,
                    text: text
                },
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('[name="_token"]').val()
                },
                success: function(res){
                    if (res && res.success && res.url_redirect){
                        window.location.replace(res.url_redirect);
                    } else{
                        location.reload();
                    }
                }
            });
        });
    });
</script>