Skip to content

Commit f531080

Browse files
committed
rr-add the cancel button
1 parent 96ac869 commit f531080

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

src/resources/views/crud/inc/form_save_buttons.blade.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
<a href="{{ $crud->hasAccess('list') ? url($crud->route) : url()->previous() }}" class="btn btn-secondary text-decoration-none"><span class="la la-ban"></span> &nbsp;{{ trans('backpack::crud.cancel') }}</a>
2929
@endif
3030

31+
@if ($crud->get('update.showDeleteButton') && $crud->get('delete.configuration') && $crud->hasAccess('delete'))
32+
<button onclick="confirmAndDeleteEntry()" type="button" class="btn btn-danger float-right"><i class="la la-trash-alt"></i> {{ trans('backpack::crud.delete') }}</button>
33+
@endif
3134
</div>
3235
@endif
3336

@@ -108,4 +111,76 @@ function changeTabIfNeededAndDisplayErrors(form) {
108111
});
109112
});
110113
</script>
114+
115+
@if ($crud->get('update.showDeleteButton') && $crud->get('delete.configuration') && $crud->hasAccess('delete'))
116+
<script>
117+
function confirmAndDeleteEntry() {
118+
// Ask for confirmation before deleting an item
119+
swal({
120+
title: "{!! trans('backpack::base.warning') !!}",
121+
text: "{!! trans('backpack::crud.delete_confirm') !!}",
122+
icon: "warning",
123+
buttons: ["{!! trans('backpack::crud.cancel') !!}", "{!! trans('backpack::crud.delete') !!}"],
124+
dangerMode: true,
125+
}).then((value) => {
126+
if (value) {
127+
$.ajax({
128+
url: '{{ url($crud->route.'/'.$entry->getKey()) }}',
129+
type: 'DELETE',
130+
success: function(result) {
131+
if (result !== '1') {
132+
// if the result is an array, it means
133+
// we have notification bubbles to show
134+
if (result instanceof Object) {
135+
// trigger one or more bubble notifications
136+
Object.entries(result).forEach(function(entry) {
137+
var type = entry[0];
138+
entry[1].forEach(function(message, i) {
139+
new Noty({
140+
type: type,
141+
text: message
142+
}).show();
143+
});
144+
});
145+
} else { // Show an error alert
146+
swal({
147+
title: "{!! trans('backpack::crud.delete_confirmation_not_title') !!}",
148+
text: "{!! trans('backpack::crud.delete_confirmation_not_message') !!}",
149+
icon: "error",
150+
timer: 4000,
151+
buttons: false,
152+
});
153+
}
154+
}
155+
// All is good, show a success message!
156+
swal({
157+
title: "{!! trans('backpack::crud.delete_confirmation_title') !!}",
158+
text: "{!! trans('backpack::crud.delete_confirmation_message') !!}",
159+
icon: "success",
160+
buttons: false,
161+
closeOnClickOutside: false,
162+
closeOnEsc: false,
163+
});
164+
165+
// Redirect in 1 sec so that admins get to see the success message
166+
setTimeout(function () {
167+
window.location.href = '{{ is_bool($crud->get('update.showDeleteButton')) ? url($crud->route) : (string) $crud->get('update.showDeleteButton') }}';
168+
}, 1000);
169+
},
170+
error: function() {
171+
// Show an alert with the result
172+
swal({
173+
title: "{!! trans('backpack::crud.delete_confirmation_not_title') !!}",
174+
text: "{!! trans('backpack::crud.delete_confirmation_not_message') !!}",
175+
icon: "error",
176+
timer: 4000,
177+
buttons: false,
178+
});
179+
}
180+
});
181+
}
182+
});
183+
}
184+
</script>
185+
@endif
111186
@endpush

0 commit comments

Comments
 (0)