Trigger inputchanged event when fileupload is completed

This commit is contained in:
Winston Chang
2017-01-31 16:25:38 -06:00
parent 5cd9ba609a
commit 015bc98d60

View File

@@ -81,15 +81,6 @@ $.extend(FileUploader.prototype, FileProcessor.prototype);
function(error) {
self.onError(error);
});
// Trigger shiny:inputchanged. Unlike a normal shiny:inputchanged event,
// it's not possible to modify the information before the values get
// sent to the server.
var evt = jQuery.Event("shiny:inputchanged");
evt.name = this.id;
evt.value = fileInfo;
evt.inputType = '';
$(document).trigger(evt);
};
this.onFile = function(file, cont) {
var self = this;
@@ -124,6 +115,24 @@ $.extend(FileUploader.prototype, FileProcessor.prototype);
};
this.onComplete = function() {
var self = this;
var fileInfo = $.map(this.files, function(file, i) {
return {
name: file.name,
size: file.size,
type: file.type
};
});
// Trigger shiny:inputchanged. Unlike a normal shiny:inputchanged event,
// it's not possible to modify the information before the values get
// sent to the server.
var evt = jQuery.Event("shiny:inputchanged");
evt.name = this.id;
evt.value = fileInfo;
evt.inputType = 'fileupload';
$(document).trigger(evt);
this.makeRequest(
'uploadEnd', [this.jobId, this.id],
function(response) {
@@ -139,13 +148,7 @@ $.extend(FileUploader.prototype, FileProcessor.prototype);
// Trigger event when all files are finished uploading.
var evt = jQuery.Event("shiny:fileuploaded");
evt.name = this.id;
evt.files = $.map(this.files, function(file, i) {
return {
name: file.name,
size: file.size,
type: file.type
};
});
evt.files = fileInfo;
$(document).trigger(evt);
};
this.onError = function(message) {