Advertisement
Daniel_HBK

Backpack custom btn error

Apr 29th, 2022
955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @if ($crud->hasAccess('update'))
  2. <a href="javascript:void(0)" onclick="updateEntry(this)"
  3.     data-route="{{ url($crud->route.'/'.$entry->getKey().'/markasread') }}" class="btn btn-sm btn-link"
  4.     data-button-type="update"><i class="la la-book"></i> Mark as {{$entry->is_read == '1' ? 'unread' : 'read'}}</a>
  5. @endif
  6.  
  7. {{-- Button Javascript --}}
  8. {{-- - used right away in AJAX operations (ex: List) --}}
  9. {{-- - pushed to the end of the page, after jQuery is loaded, for non-AJAX operations (ex: Show) --}}
  10. @push('after_scripts') @if (request()->ajax()) @endpush @endif
  11. <script>
  12.     console.log(this);
  13.     if (typeof updateEntry != 'function') {
  14.       $("[data-button-type=update]").unbind('click');
  15.         function updateEntry(button) {
  16.             // ask for confirmation before deleting an item
  17.             // e.preventDefault();
  18.             var route = $(button).attr('data-route');
  19.                 $.ajax({
  20.                     url: route,
  21.                     type: 'POST',
  22.                     dataType: "json",
  23.                     data: [
  24.                     {
  25.                     "id": {{$entry->getKey()}}
  26.                     }
  27.                     ],
  28.                     success: function(result) {
  29.                     // Show an alert with the result
  30.                     console.log(result,route);
  31.                         new Noty({
  32.                             text: {{$entry->is_read == '1' ? 'Marked as unread' : 'Marked as read'}},
  33.                             type: "success"
  34.                         }).show();
  35.                
  36.                     // Hide the modal, if any
  37.                     $('.modal').modal('hide');
  38.                    
  39.                     crud.table.ajax.reload();
  40.                 },
  41.                 error: function(result) {
  42.                         // Show an alert with the result
  43.                         new Noty({
  44.                             text: "Error",
  45.                             type: "warning"
  46.                         }).show();
  47.                     }
  48.                 });
  49.       }
  50.     }
  51.     // make it so that the function above is run after each DataTable draw event
  52.     // crud.addFunctionToDataTablesDrawEventQueue('deleteEntry');
  53. </script>
  54. @if (!request()->ajax()) @endpush @endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement