@if ($crud->checkIfFieldIsFirstOfItsType($field))
@push('crud_fields_scripts')
<script>
+
+ function parseData(data) {
+ if (data.alert) {
+ if(data.alert.icon===undefined){
+ data.alert.icon='error'
+ }
+ // Show an alert with the result
+ Swal.fire({
+ title: data.alert.title,
+ html: data.alert.message,
+ icon: data.alert.icon,
+ buttons: false,
+ });
+ }
+ if (data.confirm) {
+ if(data.confirm.icon===undefined){
+ data.confirm.icon='warning'
+ }
+
+ Swal.fire({
+ title: data.confirm.title,
+ html: data.confirm.message,
+ icon: data.confirm.icon,
+ showCloseButton: true,
+ showCancelButton: true,
+ focusConfirm: false,
+ focusCancel: true,
+ dangerMode: true,
+ }).then((value) => {
+ if (value.isConfirmed) {
+ $.ajax({
+ url: data.confirm.confirm_action,
+ success: function (result) {
+ parseData(result);
+ },
+ error: function (result) {
+ parseData(result);
+ }
+ });
+ }
+ });
+ }
+ }
+
$(function () {
$('{!! $field['trigger'] !!}').on('click', function () {
$("#{!! $id !!}").find('input[type="file"]').get(0).click();
var f = $(form).ajaxSubmit({dataType: 'json'});
var xhr = f.data('jqxhr');
xhr.done(function (data) {
- console.log(data);
+ parseData(data);
});
});
});