Clean-up javascript formatting

This commit is contained in:
Simon Walton 2018-11-14 10:17:48 -08:00
parent e96cad230a
commit f5e14565b8

View file

@ -14,17 +14,16 @@ $(document).ready(function(){
return html; return html;
} }
function uploadNextChunk(file, offset) function uploadNextChunk(file, offset) {
{
if (offset == undefined) { if (offset == undefined) {
offset = 0; offset = 0;
} }
var fileSize = file.size; var fileSize = file.size;
var filename = file.name; var filename = file.name;
var CHUNK_SIZE = 1048576; // 1 MiB var CHUNK_SIZE = 1048576; // 1 MiB
var isFinal = Boolean(fileSize - offset <= CHUNK_SIZE); var isFinal = Boolean(fileSize - offset <= CHUNK_SIZE);
var nextChunkSize = Math.min(fileSize - offset, CHUNK_SIZE); var nextChunkSize = Math.min(fileSize - offset, CHUNK_SIZE);
var chunk = file.slice(offset, offset + CHUNK_SIZE, file.type); var chunk = file.slice(offset, offset + CHUNK_SIZE, file.type);
@ -33,29 +32,29 @@ $(document).ready(function(){
var formItemName = isFinal ? 'restore-file-chunk-final' : 'restore-file-chunk'; var formItemName = isFinal ? 'restore-file-chunk-final' : 'restore-file-chunk';
chunkFormData.append(formItemName, chunk, filename); chunkFormData.append(formItemName, chunk, filename);
var ajaxParams = { var ajaxParams = {
url: '/content/upload', url: '/content/upload',
type: 'POST', type: 'POST',
timeout: 30000, // 30 s timeout: 30000, // 30 s
cache: false, cache: false,
processData: false, processData: false,
contentType: false, contentType: false,
data: chunkFormData data: chunkFormData
}; };
var ajaxObject = $.ajax(ajaxParams); var ajaxObject = $.ajax(ajaxParams);
ajaxObject.fail(function(jqXHR, textStatus, errorThrown) { ajaxObject.fail(function(jqXHR, textStatus, errorThrown) {
showErrorMessage( showErrorMessage(
"Error", "Error",
"There was a problem restoring domain content.\n" "There was a problem restoring domain content.\n"
+ "Please ensure that the content archive or entity file is valid and try again." + "Please ensure that the content archive or entity file is valid and try again."
); );
}); });
if (!isFinal) { if (!isFinal) {
ajaxObject.done(function (data, textStatus, jqXHR) ajaxObject.done(function (data, textStatus, jqXHR)
{uploadNextChunk(file, offset + CHUNK_SIZE);}); { uploadNextChunk(file, offset + CHUNK_SIZE); });
} else { } else {
ajaxObject.done(function(data, textStatus, jqXHR) { ajaxObject.done(function(data, textStatus, jqXHR) {
isRestoring = true; isRestoring = true;
// immediately reload backup information since one should be restoring now // immediately reload backup information since one should be restoring now
@ -65,7 +64,7 @@ $(document).ready(function(){
}); });
} }
} }
function setupBackupUpload() { function setupBackupUpload() {
// construct the HTML needed for the settings backup panel // construct the HTML needed for the settings backup panel
@ -106,7 +105,6 @@ $(document).ready(function(){
showSpinnerAlert("Uploading content to restore"); showSpinnerAlert("Uploading content to restore");
uploadNextChunk(files[0]); uploadNextChunk(files[0]);
} }
); );