79 lines
3.0 KiB
JavaScript
79 lines
3.0 KiB
JavaScript
//ce jamra da ne najde post je treba dati @Html.AntiForgeryToken() v page
|
|
|
|
function fileDelete(idFile, onDelete, onCancel){
|
|
$.blockUI();
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "/Files/Upload/?handler=File",
|
|
data: {
|
|
idFile
|
|
},
|
|
success: function(data) {
|
|
$.unblockUI();
|
|
if (data.successful){
|
|
if (data.itemInUse){
|
|
Swal.fire('Datoteka je v uporabi!',
|
|
'Brisanje ni možno!',
|
|
'warning');
|
|
return;
|
|
}
|
|
Swal.fire({
|
|
title: `Izbrišem datoteko ${data.file.title}?`,
|
|
text: "Tega dejanja ni možno razveljaviti!",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Da, izbriši!',
|
|
cancelButtonText: 'Prekliči!'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
$.blockUI();
|
|
$.ajax({
|
|
type: "DELETE",
|
|
beforeSend: function(xhr) {
|
|
xhr.setRequestHeader("XSRF-TOKEN",
|
|
$('input:hidden[name="__RequestVerificationToken"]').val());
|
|
},
|
|
url: "/Files/Upload/?handler=File",
|
|
data: {
|
|
idFile
|
|
},
|
|
success: function(data) {
|
|
$.unblockUI();
|
|
if (data.successful){
|
|
if (onDelete != null){
|
|
onDelete(data.idFile);
|
|
}
|
|
} else {
|
|
Swal.fire('Napaka pri brisanju datoteke',
|
|
data.error,
|
|
'error');
|
|
}
|
|
|
|
},
|
|
error: function (xhr, ajaxOptions, thrownError) {
|
|
console.log(xhr);
|
|
alert(xhr.responseText);
|
|
$.unblockUI();
|
|
}
|
|
});
|
|
} else{
|
|
if (onCancel != null){
|
|
onCancel();
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
Swal.fire('Napaka pri branju datoteke',
|
|
data.error,
|
|
'error');
|
|
}
|
|
},
|
|
error: function (xhr, ajaxOptions, thrownError) {
|
|
console.log(xhr);
|
|
alert(xhr.responseText);
|
|
$.unblockUI();
|
|
}
|
|
});
|
|
} |