Ошибка Sweet Alert при удалении после удаления, если она не работает - PullRequest
0 голосов
/ 19 июня 2020
<!-- BEGIN PAGE LEVEL CUSTOM STYLES -->
<link rel="stylesheet" type="text/css" href="{{ asset('plugins/table/datatable/datatables.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('plugins/table/datatable/dt-global_style.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('assets/css/forms/theme-checkbox-radio.css')}}">
<link rel="stylesheet" type="text/css" href="{{ asset('plugins/table/datatable/custom_dt_custom.css')}}">
<script src="http://demo.itsolutionstuff.com/plugin/jquery.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<meta name="csrf-token" content="{{ csrf_token() }}">
<!-- END PAGE LEVEL CUSTOM STYLES -->
@extends('layouts.master')

@section('content')

    <!-- BEGIN LOADER -->

    @extends('layouts.nav')

    <div id="content" class="main-content">
        <div class="layout-px-spacing">

            <div class="row layout-top-spacing">
                <div class="col-lg-12">
                    <div class="statbox widget box box-shadow">
                        <div class="widget-header">
                            <div class="row">
                                <div class="col-xl-12 col-md-12 col-sm-12 col-12 layout-top-spacing">
                                    <a href="{{route('register')}}" class="btn btn-primary mb-2 mr-2">
                                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                             viewBox="0 0 24 24" fill="none" stroke="#ffffffff" stroke-width="2"
                                             stroke-linecap="round" stroke-linejoin="round"
                                             class="feather feather-plus-circle">
                                            <circle cx="12" cy="12" r="10"></circle>
                                            <line x1="12" y1="8" x2="12" y2="16"></line>
                                            <line x1="8" y1="12" x2="16" y2="12"></line>
                                        </svg>
                                        Add New</a>
                                </div>

                            </div>


                        </div>

                        <div class="widget-content widget-content-area">
                            <div class="table-responsive mb-4">
                                <table id="style-3" class="table style-3  table-hover">
                                    <thead>
                                    <tr>
                                        <!-- <th class="checkbox-column"> No. </th> -->
                                        <th>Name</th>
                                        <th>Email</th>
                                        <th class="">Country</th>
                                        <th class="">Roles</th>
                                        @can('edit-users')
                                            <th class="text-center">Action</th>
                                        @endcan
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($users as $user)
                                        <tr>
                                        <!-- <td class="checkbox-column"> {{$user->id}} </td> -->
                                            <td class="user-name">{{$user->name}}</td>
                                            <!-- <td class="">
                                                <a class="profile-img" href="javascript: void(0);">
                                                    <img src="assets/img/90x90.jpg" alt="product">
                                                </a>
                                            </td> -->
                                            <td>{{$user->email}}</td>
                                            <td>Ethiopia</td>
                                            <td>{{implode(',', $user->role()->get()->pluck('name')->toArray())}}</td>
                                            @can('edit-users')
                                                <td class="text-center">
                                                    <ul class="table-controls">
                                                        <li class="flot-left">
                                                            <button class="btn btn-light">
                                                                <a href="{{ route('admin.users.edit', $user->id) }}"
                                                                   class="bs-tooltip" data-toggle="tooltip"
                                                                   data-placement="top" title=""
                                                                   data-original-title="Edit">
                                                                    <svg xmlns="http://www.w3.org/2000/svg" width="24"
                                                                         height="24" viewBox="0 0 24 24" fill="none"
                                                                         stroke="currentColor" stroke-width="2"
                                                                         stroke-linecap="round" stroke-linejoin="round"
                                                                         class="feather feather-edit-2 p-1 br-6 mb-1">
                                                                        <path
                                                                            d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path>
                                                                    </svg>
                                                                </a>
                                                            </button>
                                                        </li>
                                                        <li class="flot-left">
                                                            <button type="submit" class="btn btn-light remove-user"
                                                                    data-id="{{ $user->id }}"
                                                                    data-action="{{ route('admin.users.destroy',$user->id) }}"
                                                                    data-toggle="tooltip" data-placement="top" title=""
                                                                    data-original-title="Delete">
                                                                <svg xmlns="http://www.w3.org/2000/svg" width="24"
                                                                     height="24" viewBox="0 0 24 24" fill="none"
                                                                     stroke="currentColor" stroke-width="2"
                                                                     stroke-linecap="round" stroke-linejoin="round"
                                                                     class="feather feather-trash p-1 br-6 mb-1">
                                                                    <polyline points="3 6 5 6 21 6"></polyline>
                                                                    <path
                                                                        d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
                                                                </svg>
                                                            </button>
                                                            {{--                                                        <button class="btn btn-danger btn-flat btn-sm remove-user" data-id="{{ $user->id }}" data-action="{{ route('admin.users.destroy',$user->id) }}"> Delete</button>--}}
                                                        </li>
                                                    </ul>
                                                </td>
                                            @endcan
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>


                    </div>
                </div>

            </div>

            <script src="{{ asset('plugins/table/datatable/datatables.js')}}"></script>
            <script>
                // var e;
                c1 = $('#style-1').DataTable({
                    headerCallback: function (e, a, t, n, s) {
                        e.getElementsByTagName("th")[0].innerHTML = '<label class="new-control new-checkbox checkbox-outline-info m-auto">\n<input type="checkbox" class="new-control-input chk-parent select-customers-info" id="customer-all-info">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span>\n</label>'
                    },
                    columnDefs: [{
                        targets: 0, width: "30px", className: "", orderable: !1, render: function (e, a, t, n) {
                            return '<label class="new-control new-checkbox checkbox-outline-info  m-auto">\n<input type="checkbox" class="new-control-input child-chk select-customers-info" id="customer-all-info">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span>\n</label>'
                        }
                    }],
                    "oLanguage": {
                        "oPaginate": {
                            "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>',
                            "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>'
                        },
                        "sInfo": "Showing page _PAGE_ of _PAGES_",
                        "sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
                        "sSearchPlaceholder": "Search...",
                        "sLengthMenu": "Results :  _MENU_",
                    },
                    "lengthMenu": [5, 10, 20, 50],
                    "pageLength": 5
                });

                multiCheck(c1);

                c2 = $('#style-2').DataTable({
                    headerCallback: function (e, a, t, n, s) {
                        e.getElementsByTagName("th")[0].innerHTML = '<label class="new-control new-checkbox checkbox-outline-info m-auto">\n<input type="checkbox" class="new-control-input chk-parent select-customers-info" id="customer-all-info">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span>\n</label>'
                    },
                    columnDefs: [{
                        targets: 0, width: "30px", className: "", orderable: !1, render: function (e, a, t, n) {
                            return '<label class="new-control new-checkbox checkbox-outline-info  m-auto">\n<input type="checkbox" class="new-control-input child-chk select-customers-info" id="customer-all-info">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span>\n</label>'
                        }
                    }],
                    "oLanguage": {
                        "oPaginate": {
                            "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>',
                            "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>'
                        },
                        "sInfo": "Showing page _PAGE_ of _PAGES_",
                        "sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
                        "sSearchPlaceholder": "Search...",
                        "sLengthMenu": "Results :  _MENU_",
                    },
                    "lengthMenu": [5, 10, 20, 50],
                    "pageLength": 5
                });

                multiCheck(c2);

                c3 = $('#style-3').DataTable({
                    "oLanguage": {
                        "oPaginate": {
                            "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>',
                            "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>'
                        },
                        "sInfo": "Showing page _PAGE_ of _PAGES_",
                        "sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
                        "sSearchPlaceholder": "Search...",
                        "sLengthMenu": "Results :  _MENU_",
                    },
                    "stripeClasses": [],
                    "lengthMenu": [5, 10, 20, 50],
                    "pageLength": 5
                });

                multiCheck(c3);

            </script>
            <script type="text/javascript">
                $("body").on("click", ".remove-user", function () {
                    var current_object = $(this);
                    swal({
                        title: "Are you sure?",
                        text: "You can not undo this once it is done!",
                        type: "error",
                        showCancelButton: true,
                        dangerMode: true,
                        cancelButtonClass: '#DD6B55',
                        confirmButtonColor: '#dc3545',
                        confirmButtonText: 'Delete!',
                    }, function (result) {
                        if (result) {
                            var action = current_object.attr('data-action');
                            var token = jQuery('meta[name="csrf-token"]').attr('content');
                            var id = current_object.attr('data-id');

                            $('body').html("<form class='form-inline remove-form' method='post' action='" + action + "'></form>");
                            $('body').find('.remove-form').append('<input name="_method" type="hidden" value="delete">');
                            $('body').find('.remove-form').append('<input name="_token" type="hidden" value="' + token + '">');
                            $('body').find('.remove-form').append('<input name="id" type="hidden" value="' + id + '">');
                            $('body').find('.remove-form').submit();
                        }
                    });
                });
            </script>

@endsection

Я использую laravel со сладким предупреждением, и когда я пытаюсь удалить его, он работает один раз, тогда он даже не будет отображать всплывающий диалог, это ошибка на консоли

sweetalert.all.js:1 Uncaught TypeError: Cannot call a class as a function
    at a (sweetalert.all.js:1)
    at r (sweetalert.all.js:1)
    at HTMLButtonElement.<anonymous> (users:975)
    at HTMLBodyElement.dispatch (jquery.js:3074)
    at HTMLBodyElement.elemData.handle (jquery.js:2750)

а также когда я удаляю весь кеш браузера, он работает. Я понимаю, что использую устаревшую версию sweetalert, но когда я пытаюсь использовать последнюю, она тоже не работала с другими ошибками. Я нашел это в учебном блоге и решил попробовать. Если есть лучшие способы или предложения, тоже предлагаю. Спасибо.

...