Commit ef0828fc by Julian Arni

Behave properly on non-tar-gz files

parent eaa4b3ef
...@@ -60,7 +60,6 @@ var submitBtn = $('.submit-button'); ...@@ -60,7 +60,6 @@ var submitBtn = $('.submit-button');
$('#fileupload').fileupload({ $('#fileupload').fileupload({
dataType: 'json', dataType: 'json',
type: 'POST', type: 'POST',
...@@ -68,18 +67,35 @@ $('#fileupload').fileupload({ ...@@ -68,18 +67,35 @@ $('#fileupload').fileupload({
autoUpload: false, autoUpload: false,
options: {
acceptFileTypes: /(\.|\/)tar\.gz$/i ,
processQueue: [{
action: 'validate',
acceptFileTypes: '@'
}]
},
add: function(e, data) { add: function(e, data) {
submitBtn.show().click(function(e){ var file = data.files[0];
e.preventDefault(); if (file.type == "application/x-gzip") {
data.submit().complete(function(result, textStatus, xhr) { submitBtn.click(function(e){
if (result.status != 200) { e.preventDefault();
alert('${_("Your import has failed.")}\n\n' + data.submit().complete(function(result, textStatus, xhr) {
JSON.parse(result.responseText)["ErrMsg"]); if (result.status != 200) {
submitBtn.show(); alert('${_("Your import has failed.")}\n\n' +
bar.hide(); JSON.parse(result.responseText)["ErrMsg"]);
} submitBtn.show();
bar.hide();
} else {
bar.hide()
alert('${_("Your import was successful.")}');
window.location = '${successful_import_redirect_url}';
}
});
}); });
}); } else {
data.files = [];
}
}, },
progressall: function(e, data){ progressall: function(e, data){
...@@ -93,6 +109,20 @@ $('#fileupload').fileupload({ ...@@ -93,6 +109,20 @@ $('#fileupload').fileupload({
alert('${_("Your import was successful.")}'); alert('${_("Your import was successful.")}');
window.location = '${successful_import_redirect_url}'; window.location = '${successful_import_redirect_url}';
}, },
processActions: {
validate: function(data, options) {
var dfdata = $.Deferred(),
file = data.files[data.index];
if (!options.acceptFileTypes.test(file.type)) {
file.error = 'Invalid file type: must be a tar.gz file!';
dfdata.rejectWith(this, [data]);
} else {
dfdata.resolveWith(this, [data]);
}
return dfdata.promise();
}
}
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment