From ef0828fc66e43f5fc3c0f2c6badc2a67e649194e Mon Sep 17 00:00:00 2001 From: Julian Arni Date: Mon, 19 Aug 2013 13:57:01 -0400 Subject: [PATCH] Behave properly on non-tar-gz files --- cms/templates/import.html | 52 ++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/cms/templates/import.html b/cms/templates/import.html index 26ebc24493..be09e3f6d7 100644 --- a/cms/templates/import.html +++ b/cms/templates/import.html @@ -60,7 +60,6 @@ var submitBtn = $('.submit-button'); $('#fileupload').fileupload({ - dataType: 'json', type: 'POST', @@ -68,18 +67,35 @@ $('#fileupload').fileupload({ autoUpload: false, + options: { + acceptFileTypes: /(\.|\/)tar\.gz$/i , + processQueue: [{ + action: 'validate', + acceptFileTypes: '@' + }] + }, + add: function(e, data) { - submitBtn.show().click(function(e){ - e.preventDefault(); - data.submit().complete(function(result, textStatus, xhr) { - if (result.status != 200) { - alert('${_("Your import has failed.")}\n\n' + - JSON.parse(result.responseText)["ErrMsg"]); - submitBtn.show(); - bar.hide(); - } + var file = data.files[0]; + if (file.type == "application/x-gzip") { + submitBtn.click(function(e){ + e.preventDefault(); + data.submit().complete(function(result, textStatus, xhr) { + if (result.status != 200) { + alert('${_("Your import has failed.")}\n\n' + + 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){ @@ -93,6 +109,20 @@ $('#fileupload').fileupload({ alert('${_("Your import was successful.")}'); 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(); + } + } + });