I am trying to add a confirmation dialog to an upload, can make it work using the standard confirm function but would like to use a custom dialog instead.
Markup below correctly displays the dialog but can't work out where to place e.preventDefault() to stop the upload or how to allow upload if user clicks OK.
Markup below correctly displays the dialog but can't work out where to place e.preventDefault() to stop the upload or how to allow upload if user clicks OK.
$(document).ready(function () {
$("#attachments").kendoUpload({
async: {
saveUrl: '@Url.Action("SaveAppointments", "Upload")',
autoUpload: false,
},
upload: onUpload,
select: onSelect,
success: onSuccess
});
});
function onUpload(e) {
//Standard confirm works fine but would like to use a dialog
//so style can be applied etc
//if (!confirm("Is this upload for the correct candidate?")) {
// e.preventDefault();
// return;
//}
//Dialog shows correctly but how do I stop
//the upload if the user clicks no
var kendoWindow = $("<
div
/>").kendoWindow({
title: "Confirm",
resizable: false,
modal: true
});
kendoWindow.data("kendoWindow")
.content($("#upload-confirmation").html())
.center().open();
kendoWindow
.find(".upload-confirm,.upload-cancel")
.click(function () {
if ($(this).hasClass("upload-confirm")) {
alert("Upload file...");
}
kendoWindow.data("kendoWindow").close();
})
.end()
var files = e.files;
$.each(files, function () {
var ext = ".bmp .doc .docx .xls .xlsx .pdf .txt .jpg .jpeg .gif .zip .mp3 .wav .wmv .png .zipx .rar";
if (ext.indexOf(this.extension) <
0
) {
alert("Incorrect file type, accepted file types are: .bmp, .doc, .docx, .xls, .xlsx, .pdf, .txt, .jpg, .jpeg, .gif, .zip, .zipx, .rar, .mp3, .wav, .wmv and .png")
e.preventDefault();
};
if (this.size > 10485760) {
alert("File too large, maximun upload size is 10mb")
e.preventDefault();
};
if ($("#fileDescription").val() + '' == 'undefined') {
alert("A file description is required.")
e.preventDefault();
};
e.data = { fileDescription: $("#fileDescription").val(), appointmentid: $("#appointmentid").val() };
});
}