56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
function initFileUpload(objectContext) {
|
|
"use strict";
|
|
|
|
$("form#create").data("validator").settings.submitHandler =
|
|
function (form) {
|
|
var identifier = $(form).find("input[name='Identifier']").val();
|
|
$("<div id='confirmCreate'>" + "Please confirm submitting '" + identifier + "'</div>")
|
|
.dialog({
|
|
text: "Confirm",
|
|
buttons: {
|
|
"Confirm": function () {
|
|
$("#confirmCreate")
|
|
.next(".ui-dialog-buttonpane button:contains('Confirm')")
|
|
.attr("disabled", true)
|
|
.addClass("ui-state-disabled");
|
|
form.submit();
|
|
},
|
|
"Cancel": function () {
|
|
$(this).dialog("close");
|
|
}
|
|
}
|
|
});
|
|
};
|
|
|
|
// We use the upload handler integrated into Backload:
|
|
// In this example we set an objectContect (id) in the url query (or as form parameter).
|
|
// You can use a user id as objectContext give users only access to their own uploads.
|
|
var url = "/umbraco/surface/Backload/FileHandler?objectContext=" + objectContext;
|
|
|
|
// Initialize the jQuery File Upload widget:
|
|
$("#fileupload").fileupload({
|
|
url: url,
|
|
autoUpload: true,
|
|
maxFileSize: 5000000,
|
|
maxChunkSize: 10000000, // Optional: file chunking with 10MB chunks
|
|
acceptFileTypes: /(csv)$/i // Allowed file types
|
|
})
|
|
.bind("fileuploadsubmit", function (e, data) {
|
|
// Optional: We add a random uuid form parameter. On chunk uploads the uuid is used to store the chunks.
|
|
//data.formData = { uuid: Math.random().toString(36).substr(2, 8) };
|
|
});
|
|
|
|
// Load existing files:
|
|
$("#fileupload").addClass("fileupload-processing");
|
|
$.ajax({
|
|
url: url,
|
|
dataType: "json",
|
|
context: $("#fileupload")[0]
|
|
}).always(function () {
|
|
$(this).removeClass("fileupload-processing");
|
|
}).done(function (result) {
|
|
$(this).fileupload("option", "done")
|
|
.call(this, $.Event("done"), { result: result });
|
|
});
|
|
};
|