I would like to ask user, delete or not delete then call ajax.
But but where should the $.confirm method be?
Above code delete first for user screen then delete at backend.
How to call before $.confirm method delete?
$("#kt_tree_type-make-model").jstree({
"core": {
"check_callback": true,
"data": data
},
"types": {
"default": {
"icon": "fa fa-folder text-primary"
},
"file": {
"icon": "fa fa-file text-primary"
}
},
"contextmenu":{
'items' : function(node) {
var items = $.jstree.defaults.contextmenu.items();
items.create.label = 'ADD';
items.rename.label = 'RENAME';
items.remove.label = 'DELETE';
items.ccp = false;
return items;
}
},
"plugins": ["contextmenu", "state", "types"]
}).on('create_node.jstree', function (e, data) {
}).on('rename_node.jstree', function (e, data) {
}).on('delete_node.jstree', function (e, data) {
$.confirm({
type: 'orange',
title: 'ARE YOU SURE?',
content: 'DELETING.',
buttons: {
confirm: {
text: 'YES, DELETE',
action: function () {
let node = data.node.id.split('_');
let kind = node[0];
let id = node[1];
$.ajax({
url: `/vehicles/type-make-model/${kind}/delete/${id}`,
type: 'get',
headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
dataType: 'json',
success: function (response) {
$.alert({title: false, type: 'green', content: 'Deleted successfully.'});
data.instance.refresh();
},
error: function (xhr, ajaxOptions, thrownError) {
$.alert({title: false, type: 'red', content: xhr.responseJSON.message});
data.instance.refresh();
}
});
}
},
cancel: {
text: 'CANCEL'
}
}
});
});