diff --git a/app/assets/javascripts/direct-upload.js b/app/assets/javascripts/direct-upload.js
index 59923b0ef..5fc36a608 100644
--- a/app/assets/javascripts/direct-upload.js
+++ b/app/assets/javascripts/direct-upload.js
@@ -139,12 +139,12 @@
}
/*
- * Validates files on server and uploads them to S3 server.
+ * Spoof checks files on server and uploads them to S3 server.
*
- * First we asyncronously validate files on server and generate post requests
- * (fetchUploadSignature), if OK the post requests are used to uplaod files
- * asyncronously to S3 (uploadFile), and if successful the form is submitted,
- * otherwise no file is saved and errors are shown.
+ * First we asyncronously spoof check files on server and generate post
+ * requests (fetchUploadSignature), if OK the post requests are used to uplaod
+ * files asyncronously to S3 (uploadFile), and if successful the form is
+ * submitted, otherwise no file is saved and errors are shown.
* If any post fails, the user is allowed to leave the page, but other files
* are still being uploaded because of asynchronous behaviour, so that errors
* for other files can still show afterwards.
@@ -171,7 +171,7 @@
preventLeavingPage(true, I18n.t("general.file.uploading"));
ev.preventDefault();
- // Validates files and if OK gets upload post requests
+ // Spoof checks files and, if OK, gets upload post requests
_.each($fileInputs, function (fileInput) {
var file = fileInput.files[0];
if (!_.isUndefined(file)) {
@@ -182,7 +182,7 @@
});
$.when.apply($, signRequests).then(function () {
- // After successful file validation and posts fetching
+ // After successful file spoof check and upload post requests fetching
if (signRequests.length) {
var fileRequests = [];
@@ -196,16 +196,21 @@
processPosts(ev, $fileInput, data.posts, fileRequests);
});
- $.when.apply($, fileRequests).always(function () {
+ $.when.apply($, fileRequests).then(function () {
+ // After successful posts processing and file uploading
+ $form.onAjaxComplete(function () {
+ animateSpinner(null, false);
+ preventLeavingPage(false);
+ });
+ $form.submit();
+ }, function() {
+ // After unsuccessful posts processing and file uploading
animateSpinner(null, false);
preventLeavingPage(false);
- }).then(function () {
- // After successful posts processing and file uploading
- $form.submit();
});
}
}, function () {
- // After unsuccessful file validation and posts fetching
+ // After unsuccessful file spoof check and posts fetching
animateSpinner(null, false);
preventLeavingPage(false);
});
diff --git a/app/assets/javascripts/sitewide/form_cleanups.js b/app/assets/javascripts/sitewide/form_cleanups.js
index d2710a436..33e6e25c3 100644
--- a/app/assets/javascripts/sitewide/form_cleanups.js
+++ b/app/assets/javascripts/sitewide/form_cleanups.js
@@ -27,7 +27,7 @@ $.fn.removeBlankFileForms = function () {
*/
$.fn.removeBlankExcelTables = function (editMode) {
if(editMode) {
- $tables = $(this).find(".handsontable");
+ $tables = $(this).find("[data-role='editable-table']");
// In edit mode, tables can't be blank
$tables.each(function () {
if (!$(this).find("td:not(:empty)").length) {
@@ -35,4 +35,4 @@ $.fn.removeBlankExcelTables = function (editMode) {
}
});
}
-}
\ No newline at end of file
+}
diff --git a/app/assets/javascripts/sitewide/form_validators.js.erb b/app/assets/javascripts/sitewide/form_validators.js.erb
index 65d09c75f..6b0045616 100644
--- a/app/assets/javascripts/sitewide/form_validators.js.erb
+++ b/app/assets/javascripts/sitewide/form_validators.js.erb
@@ -82,7 +82,7 @@ function filesValidator(ev, fileInputs, fileTypeEnum) {
if (fileInputs.length) {
var filesPresentValid = filesPresentValidator(ev, fileInputs);
var filesSizeValid = filesSizeValidator(ev, fileInputs, fileTypeEnum);
- // TODO File content check
+ // File spoof check is done on server-side only
filesValid = filesPresentValid && filesSizeValid;
}
return filesValid;
@@ -129,7 +129,7 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
});
if(filesSizeValid) {
// Check if there is enough free space for the files
- filesSizeValid = enaughSpaceValidator(ev, fileInputs);
+ filesSizeValid = enoughSpaceValidator(ev, fileInputs);
}
return filesSizeValid;
}
@@ -138,6 +138,6 @@ function filesSizeValidator(ev, fileInputs, fileTypeEnum) {
* Overriden in billing module for checking whether enough
* organization space is free.
*/
-function enaughSpaceValidator(ev, fileInputs) {
+function enoughSpaceValidator(ev, fileInputs) {
return true;
}
diff --git a/app/assets/javascripts/sitewide/gestures.js b/app/assets/javascripts/sitewide/gestures.js
index f7d4e41b5..96835c06c 100644
--- a/app/assets/javascripts/sitewide/gestures.js
+++ b/app/assets/javascripts/sitewide/gestures.js
@@ -13,4 +13,4 @@ function goToFormElement(input) {
"slow",
function() { $(input).focus(); }
);
-}
\ No newline at end of file
+}
diff --git a/app/assets/javascripts/sitewide/utils.js b/app/assets/javascripts/sitewide/utils.js
index fd680dd76..4fd3b1cf9 100644
--- a/app/assets/javascripts/sitewide/utils.js
+++ b/app/assets/javascripts/sitewide/utils.js
@@ -1,6 +1,5 @@
/*
- * Converts JSON data received from the server to flat array
- * of values.
+ * Converts JSON data received from the server to flat array of values.
*/
function jsonToValuesArray(jsonData) {
errMsgs =[];
@@ -12,3 +11,17 @@ function jsonToValuesArray(jsonData) {
}
return errMsgs;
}
+
+/*
+ * Calls callback function on AJAX success (because built-in functions don't
+ * work!)
+ */
+$.fn.onAjaxComplete = function (cb) {
+ $(this)
+ .on("ajax:success", function() {
+ cb();
+ })
+ .on("ajax:error", function() {
+ cb();
+ });
+}
diff --git a/app/controllers/steps_controller.rb b/app/controllers/steps_controller.rb
index cbe01ac41..e66260729 100644
--- a/app/controllers/steps_controller.rb
+++ b/app/controllers/steps_controller.rb
@@ -35,14 +35,16 @@ class StepsController < ApplicationController
step_assets = step_params.slice(:assets_attributes)
@step = Step.new(step_data)
- step_assets[:assets_attributes].each do |_i, data|
- # Ignore destroy requests on create
- next if data[:_destroy].present?
+ unless step_assets[:assets_attributes].nil?
+ step_assets[:assets_attributes].each do |_i, data|
+ # Ignore destroy requests on create
+ next if data[:_destroy].present?
- asset = Asset.new(data)
- asset.created_by = current_user
- asset.last_modified_by = current_user
- new_assets << asset
+ asset = Asset.new(data)
+ asset.created_by = current_user
+ asset.last_modified_by = current_user
+ new_assets << asset
+ end
end
@step.assets << new_assets
else
diff --git a/app/helpers/assets_helper.rb b/app/helpers/assets_helper.rb
index b0f74793e..01d19ecbb 100644
--- a/app/helpers/assets_helper.rb
+++ b/app/helpers/assets_helper.rb
@@ -11,7 +11,7 @@ module AssetsHelper
data-download-url='#{download_asset_path(asset)}'
>
- #{t('general.file.loading', fileName: asset.file_file_name)}
+ #{t('general.file.uploading', fileName: asset.file_file_name)}