index.blade.php 10.5 KB
@extends('layout.admin', ['title' => 'Админка - Сообщения адмистратора'])

@section('script')
    <script>
        $(document).ready(function() {
            $('.rejecte-button').click(function(){
                var this_btn = $(this);
                var wrap = this_btn.closest('tr');
                var message_id = wrap.data('message-id');
                var target = wrap.find('.user-name').text();

                $('#rejecte_message').data('message-id', message_id);
                $('#rejecte_message').find('.user-name').text(target.trim());
                $('#rejecte_message').find('.message-id').text(message_id);
            });

            $('.send-button').click(function(){cl(1000);
                var this_btn = $(this);
                var wrap = this_btn.closest('tr');
                var message_id = wrap.data('message-id');
                var target = wrap.find('.user-name').text();

                $('#send_message').data('message-id', message_id);
                $('#send_message').find('.user-name').text(target.trim());
                $('#send_message').find('.message-id').text(message_id);
            });

            $(document).on('change', '.checkread', function () {
                var this_ = $(this);
                var value = this_.val();
                var ajax_block = $('#ajax_block');
                var bool = 0;

                if(this.checked){
                    bool = 1;
                } else {
                    bool = 0;
                }

                $.ajax({
                    type: "GET",
                    url: "{{ url()->full()}}",
                    data: "id=" + value + "&flag_new=" + bool,
                    success: function (data) {
                        console.log('Обновление таблицы сообщений администратора ');
                        //data = JSON.parse(data);
                        //console.log(data);
                        ajax_block.html(data);
                    },
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    error: function (data) {
                        console.log('Error: ' + data);
                    }
                });
            });

        });
    </script>
@endsection

@section('content')
    <div class="w-full overflow-hidden rounded-lg shadow-xs" id="ajax_block">
        <div class="w-full overflow-x-auto">
            <table class="w-full whitespace-no-wrap">
                <thead>
                <tr
                    class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-gray-400 dark:bg-gray-800"
                >
                    <th class="px-4 py-3">№</th>
                    <th class="px-4 py-3">От юзера</th>
                    <th class="px-4 py-3">Должности</th>
                    <th class="px-4 py-3">Текст</th>
                    <th class="px-4 py-3">Дата</th>
                    <th class="px-4 py-3">Прочтено</th>
                </tr>
                </thead>
                <tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
                @foreach($Msgs as $msg)
                    <tr class="text-gray-700 dark:text-gray-400" data-message-id="{{ $msg->id }}">
                        <td class="px-4 py-3">
                            {{ $msg->id }}
                        </td>
                        <td class="px-4 py-3">
                            <div class="user-name">
                            @if (isset($msg->user->name))
                                {{$msg->user->name}} ({{$msg->user->id}})
                            @else
                                Пользователь удален
                            @endif
                            </div>
                        </td>
                        <td class="px-4 py-3">
                            @if($msg->job_titles)
                                @foreach($msg->jobs as $job)
                                    {{ $job->name }}
                                    @if(!$loop->last)
                                        <br>
                                    @endif
                                @endforeach
                            @endif
                        </td>
                        <td class="px-4 py-3">
                            <div>
                                {{ $msg->text }}
                            </div>
                        </td>
                        <td class="px-4 py-3 text-sm">
                            {{ date('d.m.Y h:i:s', strtotime($msg->created_at)) }}
                        </td>
                        <td class="px-4 py-3">
                            @if($msg->is_rejected)
                                Отклонено
                            @elseif($msg->is_sent)
                                Отправлено
                            @else
                                <div class="">
                                    <button class="rejecte-button px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-red-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple"
                                            data-fancybox data-src="#rejecte_message"
                                    >
                                        Отклонить
                                    </button>
                                    <button class="send-button px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-green-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple"
                                            data-fancybox data-src="#send_message"
                                    >
                                        Отправить
                                    </button>
                                </div>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>

        <div class="grid px-4 py-3 text-xs font-semibold tracking-wide text-gray-500 uppercase border-t dark:border-gray-700 bg-gray-50 sm:grid-cols-9 dark:text-gray-400 dark:bg-gray-800">
            <?=$Msgs->appends($_GET)->links('admin.pagginate'); ?>
        </div>
    </div><br>

    <div class="w-full overflow-hidden rounded-lg shadow-xs" id="ajax_block2">

        <form method="POST" action="{{ route('admin.admin-messages-post') }}" enctype="multipart/form-data">
            @csrf
            <div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
                <h3 class="text-gray-700 dark:text-gray-400">Отправка сообщения</h3>
                <hr>
                <label for="ad_employer_id" class="block text-sm">
                    <input type="hidden" name="user_id" id="user_id" value="{{ $id_admin }}"/>

                    <span class="text-gray-700 dark:text-gray-400">Кому:</span>

                    <select name="to_user_id" id="to_user_id" class="block change_js mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray">
                        @foreach($users as $user)
                            <option value="{{ $user->id }}">{{ $user->name }} ({{ $user->id }})</option>
                        @endforeach
                    </select>
                </label><br>

                <label class="block text-sm">
                    <span class="text-gray-700 dark:text-gray-400">Заголовок</span>
                    <input name="title" id="title"
                           class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray form-input"
                           placeholder="Заголовок" value="{{ old('title') ?? '' }}"
                    />
                    @error('title')
                    <span class="text-xs text-red-600 dark:text-red-400">
                        {{ $message }}
                    </span>
                    @enderror
                </label><br>

                <label class="block text-sm">
                    <span class="text-gray-700 dark:text-gray-400">Текст</span>
                    <textarea class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-textarea focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray" name="text" placeholder="Текст" required
                              rows="4">{{ old('text') ?? '' }}</textarea>
                    @error('text')
                    <span class="text-xs text-red-600 dark:text-red-400">
                  {{ $message }}
            </span>
                    @enderror
                </label><br>


                <label class="block text-sm">
                    <span class="text-gray-700 dark:text-gray-400">Файл</span>
                    <input type="file" class="block w-full mt-1 text-sm dark:border-gray-600 dark:bg-gray-700
                                  focus:border-purple-400 focus:outline-none focus:shadow-outline-purple
                                  dark:text-gray-300 dark:focus:shadow-outline-gray form-input"
                           id="file" name="file">
                    @error('file')
                    <span class="text-xs text-red-600 dark:text-red-400">
                        {{ $message }}
                    </span>
                    @enderror
                </label><br>

                <div class="flex flex-col flex-wrap mb-4 space-y-4 md:flex-row md:items-end md:space-x-4">
                    <div>
                        <button type="submit" class="px-3 py-1 text-sm font-medium leading-5 text-white transition-colors duration-150 bg-purple-600 border border-transparent rounded-md active:bg-purple-600 hover:bg-purple-700 focus:outline-none focus:shadow-outline-purple">
                            Отправить
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>

    @include('modals.admin.messages.rejecte_message')
    @include('modals.admin.messages.send_message')
@endsection