From 38e46fff548729ba459d0a83a46fbfa0d844e85d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 22 Jul 2016 14:03:14 +0200 Subject: upgrade readmore.js and improve collapsing a little --- view/js/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'view/js') diff --git a/view/js/main.js b/view/js/main.js index a288f98f5..a3fade0ea 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -659,7 +659,7 @@ function collapseHeight() { var position = $(window).scrollTop(); $(".wall-item-content, .directory-collapse").each(function() { - var orgHeight = parseInt($(this).css('height')); + var orgHeight = $(this).outerHeight(true); if(orgHeight > divmore_height) { if(! $(this).hasClass('divmore')) { @@ -679,7 +679,7 @@ function collapseHeight() { beforeToggle: function(trigger, element, expanded) { if(expanded) { if((($(element).offset().top + divmore_height) - $(window).scrollTop()) < 65 ) { - $(window).scrollTop($(window).scrollTop() - (orgHeight - divmore_height)); + $(window).scrollTop($(window).scrollTop() - ($(element).outerHeight(true) - divmore_height)); } } } -- cgit v1.2.3 From 6998bb1f23b63c3439f34d9b3f53c42a6922a58e Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sun, 24 Jul 2016 07:41:53 -0400 Subject: Multiple file upload by drag and drop with progress indicators and auto page reload --- view/js/mod_cloud.js | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 view/js/mod_cloud.js (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js new file mode 100644 index 000000000..71e916446 --- /dev/null +++ b/view/js/mod_cloud.js @@ -0,0 +1,98 @@ +/** + * JavaScript for mod/cloud + */ + +$(document).ready(function () { + // call initialization file + if (window.File && window.FileList && window.FileReader) { + DragDropUploadInit(); + } +}); + +// +// initialize +function DragDropUploadInit() { + + var fileselect = $("#fileselect"), + filedrag = $("#filedrag"); + + // file select + fileselect.on("change", DragDropUploadFileSelectHandler); + + // is XHR2 available? + var xhr = new XMLHttpRequest(); + if (xhr.upload) { + + // file drop + filedrag.on("dragover", DragDropUploadFileHover); + filedrag.on("dragleave", DragDropUploadFileHover); + filedrag.on("drop", DragDropUploadFileSelectHandler); + filedrag.show(); + + } + + window.filesToUpload = 0; + window.fileUploadsCompleted = 0; + + +} + +// file drag hover +function DragDropUploadFileHover(e) { + e.stopPropagation(); + e.preventDefault(); + e.target.className = (e.type == "dragover" ? "hover" : ""); +} + +// file selection +function DragDropUploadFileSelectHandler(e) { + + // cancel event and hover styling + DragDropUploadFileHover(e); + + // fetch FileList object + var files = e.target.files || e.originalEvent.dataTransfer.files; + $("#file-upload-list").empty(); + // process all File objects + for (var i = 0, f; f = files[i]; i++) { + $("#file-upload-list").append( + "

" + " -> File: " + f.name + + " type: " + f.type + + " size: " + f.size + + " bytes

" + ); + DragDropUploadFile(f, i); + } + +} + +// upload files +function DragDropUploadFile(file, idx) { + + window.filesToUpload = window.filesToUpload + 1; + + var xhr = new XMLHttpRequest(); + xhr.withCredentials = true; // Include the SESSION cookie info for authentication + (xhr.upload || xhr).addEventListener('progress', function (e) { + var done = e.position || e.loaded; + var total = e.totalSize || e.total; + // Dynamically update the percentage complete displayed in the file upload list + $('#upload-progress-' + idx).html(Math.round(done / total * 100) + '%'); + }); + xhr.addEventListener('load', function (e) { + //console.log('xhr upload complete', e); + window.fileUploadsCompleted = window.fileUploadsCompleted + 1; + // When all the uploads have completed, refresh the page + if (window.filesToUpload > 0 && window.fileUploadsCompleted === window.filesToUpload) { + window.fileUploadsCompleted = window.filesToUpload = 0; + // After uploads complete, refresh browser window to display new files + window.location.href = window.location.href; + } + }); + // POST to the entire cloud path + xhr.open('post', window.location.pathname, true); + + var data = new FormData(document.getElementById("ajax-upload-files")); + data.append('file', file); + xhr.send(data); +} -- cgit v1.2.3 From 01338a76103a18d053413f1a8ad45870b2babf02 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 24 Jul 2016 22:58:26 -0700 Subject: make drag/drop work with acl, which bypassed the form --- view/js/mod_cloud.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 71e916446..8f08c7fe9 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -90,9 +90,9 @@ function DragDropUploadFile(file, idx) { } }); // POST to the entire cloud path - xhr.open('post', window.location.pathname, true); + xhr.open('post', 'file_upload', true); var data = new FormData(document.getElementById("ajax-upload-files")); - data.append('file', file); + data.append('userfile', file); xhr.send(data); } -- cgit v1.2.3 From 0f5f1c98cae1becdbd303a85005fd5381eefe1b0 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 25 Jul 2016 01:46:40 -0700 Subject: revert cloud acl selector (branched so as to continue development) --- view/js/mod_cloud.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 8f08c7fe9..71e916446 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -90,9 +90,9 @@ function DragDropUploadFile(file, idx) { } }); // POST to the entire cloud path - xhr.open('post', 'file_upload', true); + xhr.open('post', window.location.pathname, true); var data = new FormData(document.getElementById("ajax-upload-files")); - data.append('userfile', file); + data.append('file', file); xhr.send(data); } -- cgit v1.2.3 From 7126fd4b313d60062e111c55fafbae47b9e53a68 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 26 Jul 2016 15:57:47 +0200 Subject: fix drag and drop --- view/js/mod_cloud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 71e916446..0584cec53 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -93,6 +93,6 @@ function DragDropUploadFile(file, idx) { xhr.open('post', window.location.pathname, true); var data = new FormData(document.getElementById("ajax-upload-files")); - data.append('file', file); + data.append('file[]', file); xhr.send(data); } -- cgit v1.2.3 From f808f1601b548ee4830f7a16b479eadce3b66094 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 27 Jul 2016 16:49:55 +0200 Subject: rework drag and drop to drag directly into files area, implement the default upload button to work with the same mechanism as drag and drop, revert 560af7a5b8e30001ea6bf9a6d2ea36e94ae904d0 since it did not work so well with the new cloud upload mechanism --- view/js/mod_cloud.js | 184 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 114 insertions(+), 70 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 0584cec53..4ef87ec4b 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -3,96 +3,140 @@ */ $(document).ready(function () { - // call initialization file - if (window.File && window.FileList && window.FileReader) { - DragDropUploadInit(); - } + // call initialization file + if (window.File && window.FileList && window.FileReader) { + UploadInit(); + } }); // // initialize -function DragDropUploadInit() { +function UploadInit() { - var fileselect = $("#fileselect"), - filedrag = $("#filedrag"); + var fileselect = $("#files-upload"); + var filedrag = $("#cloud-drag-area"); + var submit = $("#upload-submit"); - // file select - fileselect.on("change", DragDropUploadFileSelectHandler); + // is XHR2 available? + var xhr = new XMLHttpRequest(); + if (xhr.upload) { - // is XHR2 available? - var xhr = new XMLHttpRequest(); - if (xhr.upload) { + // file select + fileselect.on("change", UploadFileSelectHandler); - // file drop - filedrag.on("dragover", DragDropUploadFileHover); - filedrag.on("dragleave", DragDropUploadFileHover); - filedrag.on("drop", DragDropUploadFileSelectHandler); - filedrag.show(); - - } - - window.filesToUpload = 0; - window.fileUploadsCompleted = 0; + // file submit + submit.on("click", fileselect, UploadFileSelectHandler); + // file drop + filedrag.on("dragover", DragDropUploadFileHover); + filedrag.on("dragleave", DragDropUploadFileHover); + filedrag.on("drop", DragDropUploadFileSelectHandler); + } + window.filesToUpload = 0; + window.fileUploadsCompleted = 0; } // file drag hover function DragDropUploadFileHover(e) { - e.stopPropagation(); - e.preventDefault(); - e.target.className = (e.type == "dragover" ? "hover" : ""); + e.stopPropagation(); + e.preventDefault(); + e.currentTarget.className = (e.type == "dragover" ? "hover" : ""); } -// file selection +// file selection via drag/drop function DragDropUploadFileSelectHandler(e) { + // cancel event and hover styling + DragDropUploadFileHover(e); + + // fetch FileList object + var files = e.target.files || e.originalEvent.dataTransfer.files; - // cancel event and hover styling - DragDropUploadFileHover(e); - - // fetch FileList object - var files = e.target.files || e.originalEvent.dataTransfer.files; - $("#file-upload-list").empty(); - // process all File objects - for (var i = 0, f; f = files[i]; i++) { - $("#file-upload-list").append( - "

" + " -> File: " + f.name + - " type: " + f.type + - " size: " + f.size + - " bytes

" - ); - DragDropUploadFile(f, i); - } + $('.new-upload').remove(); + // process all File objects + for (var i = 0, f; f = files[i]; i++) { + prepareHtml(f, i); + UploadFile(f, i); + } +} + +// file selection via input +function UploadFileSelectHandler(e) { + // fetch FileList object + if(e.type === 'click') { + e.preventDefault(); + var files = e.data[0].files; + } + else { + var files = e.target.files; + } + + $('.new-upload').remove(); + + // process all File objects + for (var i = 0, f; f = files[i]; i++) { + prepareHtml(f, i); + if(e.type === 'click') + UploadFile(f, i); + } +} + +function prepareHtml(f, i) { + $("#cloud-index").prepend( + "" + "" + f.name + + "" + f.type + + "" + formatSizeUnits(f.size) + + "" + ); +} + +function formatSizeUnits(bytes){ + if (bytes>=1000000000) {bytes=(bytes/1000000000).toFixed(2)+' GB';} + else if (bytes>=1000000) {bytes=(bytes/1000000).toFixed(2)+' MB';} + else if (bytes>=1000) {bytes=(bytes/1000).toFixed(2)+' KB';} + else if (bytes>1) {bytes=bytes+' bytes';} + else if (bytes==1) {bytes=bytes+' byte';} + else {bytes='0 byte';} + return bytes; } // upload files -function DragDropUploadFile(file, idx) { - - window.filesToUpload = window.filesToUpload + 1; - - var xhr = new XMLHttpRequest(); - xhr.withCredentials = true; // Include the SESSION cookie info for authentication - (xhr.upload || xhr).addEventListener('progress', function (e) { - var done = e.position || e.loaded; - var total = e.totalSize || e.total; - // Dynamically update the percentage complete displayed in the file upload list - $('#upload-progress-' + idx).html(Math.round(done / total * 100) + '%'); - }); - xhr.addEventListener('load', function (e) { - //console.log('xhr upload complete', e); - window.fileUploadsCompleted = window.fileUploadsCompleted + 1; - // When all the uploads have completed, refresh the page - if (window.filesToUpload > 0 && window.fileUploadsCompleted === window.filesToUpload) { - window.fileUploadsCompleted = window.filesToUpload = 0; - // After uploads complete, refresh browser window to display new files - window.location.href = window.location.href; - } - }); - // POST to the entire cloud path - xhr.open('post', window.location.pathname, true); - - var data = new FormData(document.getElementById("ajax-upload-files")); - data.append('file[]', file); - xhr.send(data); +function UploadFile(file, idx) { + + window.filesToUpload = window.filesToUpload + 1; + + var xhr = new XMLHttpRequest(); + + xhr.withCredentials = true; // Include the SESSION cookie info for authentication + + (xhr.upload || xhr).addEventListener('progress', function (e) { + var done = e.position || e.loaded; + var total = e.totalSize || e.total; + // Dynamically update the percentage complete displayed in the file upload list + $('#upload-progress-' + idx).html(Math.round(done / total * 100) + '%'); + }); + + xhr.addEventListener('load', function (e) { + + //console.log('xhr upload complete', e); + window.fileUploadsCompleted = window.fileUploadsCompleted + 1; + + // When all the uploads have completed, refresh the page + if (window.filesToUpload > 0 && window.fileUploadsCompleted === window.filesToUpload) { + window.fileUploadsCompleted = window.filesToUpload = 0; + + // After uploads complete, refresh browser window to display new files + window.location.href = window.location.href; + } + }); + + // POST to the entire cloud path + xhr.open('post', window.location.pathname, true); + + var data = new FormData(document.getElementById("ajax-upload-files")); + + data.append('file', file); + + xhr.send(data); } -- cgit v1.2.3 From 9fa3956aa886f7522553ac161a42569706613b0c Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 28 Jul 2016 10:28:48 +0200 Subject: translate mime types to icons, update some icons, move file preview (upload progress) below table header --- view/js/mod_cloud.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 4ef87ec4b..e29efd664 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -83,11 +83,13 @@ function UploadFileSelectHandler(e) { } function prepareHtml(f, i) { - $("#cloud-index").prepend( - "" + "" + f.name + - "" + f.type + - "" + formatSizeUnits(f.size) + - "" + $("#cloud-index tr:nth-child(2)").after( + "" + + "" + + "" + f.name + "" + + "" + + "" + formatSizeUnits(f.size) + "" + + "" ); } @@ -101,6 +103,51 @@ function formatSizeUnits(bytes){ return bytes; } +// this is basically a js port of include/text.php getIconFromType() function +function getIconFromType(type) { + var map = { + //Common file + 'application/octet-stream': 'fa-file-o', + //Text + 'text/plain': 'fa-file-text-o', + 'application/msword': 'fa-file-word-o', + 'application/pdf': 'fa-file-pdf-o', + 'application/vnd.oasis.opendocument.text': 'fa-file-word-o', + 'application/epub+zip': 'fa-book', + //Spreadsheet + 'application/vnd.oasis.opendocument.spreadsheet': 'fa-file-excel-o', + 'application/vnd.ms-excel': 'fa-file-excel-o', + //Image + 'image/jpeg': 'fa-picture-o', + 'image/png': 'fa-picture-o', + 'image/gif': 'fa-picture-o', + 'image/svg+xml': 'fa-picture-o', + //Archive + 'application/zip': 'fa-file-archive-o', + 'application/x-rar-compressed': 'fa-file-archive-o', + //Audio + 'audio/mpeg': 'fa-file-audio-o', + 'audio/wav': 'fa-file-audio-o', + 'application/ogg': 'fa-file-audio-o', + 'audio/ogg': 'fa-file-audio-o', + 'audio/webm': 'fa-file-audio-o', + 'audio/mp4': 'fa-file-audio-o', + //Video + 'video/quicktime': 'fa-file-video-o', + 'video/webm': 'fa-file-video-o', + 'video/mp4': 'fa-file-video-o', + 'video/x-matroska': 'fa-file-video-o' + }; + + var iconFromType = 'fa-file-o'; + + if (type in map) { + iconFromType = map[type]; + } + + return iconFromType; +} + // upload files function UploadFile(file, idx) { -- cgit v1.2.3 From b05c1a98293a4a7c17a57589db750eace2db4c9d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 28 Jul 2016 11:45:57 +0200 Subject: use single quote for js and double quote for html with proper escapes and implement a simple progressbar --- view/js/mod_cloud.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index e29efd664..8e6b8cb05 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -84,12 +84,12 @@ function UploadFileSelectHandler(e) { function prepareHtml(f, i) { $("#cloud-index tr:nth-child(2)").after( - "" + - "" + - "" + f.name + "" + - "" + - "" + formatSizeUnits(f.size) + "" + - "" + '' + + '' + + '' + f.name + '' + + '' + + '' + formatSizeUnits(f.size) + '' + + '' ); } @@ -162,6 +162,7 @@ function UploadFile(file, idx) { var total = e.totalSize || e.total; // Dynamically update the percentage complete displayed in the file upload list $('#upload-progress-' + idx).html(Math.round(done / total * 100) + '%'); + $('#new-upload-' + idx).css('background-size', Math.round(done / total * 100) + '%'); }); xhr.addEventListener('load', function (e) { -- cgit v1.2.3 From e65949f5947d38aff1ac8a5bb2abf682543dfc4f Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 28 Jul 2016 11:54:42 +0200 Subject: make progressbar slightly more transparent and give it a default width of 3px to indicate which files are to be uploaded --- view/js/mod_cloud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 8e6b8cb05..f7f9092c0 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -84,7 +84,7 @@ function UploadFileSelectHandler(e) { function prepareHtml(f, i) { $("#cloud-index tr:nth-child(2)").after( - '' + + '' + '' + '' + f.name + '' + '' + -- cgit v1.2.3 From fc105cf1415cf4124f69d40419b5c52307e993a2 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 28 Jul 2016 15:35:45 +0200 Subject: reusing the original form did not work so well via xhr upload - let us create a new form for this action. revert progressbar- only works nice in firefox --- view/js/mod_cloud.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index f7f9092c0..ea1ce35a7 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -22,6 +22,7 @@ function UploadInit() { if (xhr.upload) { // file select + fileselect.attr("multiple", 'multiple'); fileselect.on("change", UploadFileSelectHandler); // file submit @@ -64,27 +65,30 @@ function DragDropUploadFileSelectHandler(e) { // file selection via input function UploadFileSelectHandler(e) { // fetch FileList object - if(e.type === 'click') { + if(e.target.id === 'upload-submit') { e.preventDefault(); var files = e.data[0].files; } - else { + if(e.target.id === 'files-upload') { + $('.new-upload').remove(); var files = e.target.files; } - $('.new-upload').remove(); + // process all File objects for (var i = 0, f; f = files[i]; i++) { - prepareHtml(f, i); - if(e.type === 'click') + if(e.target.id === 'files-upload') + prepareHtml(f, i); + if(e.target.id === 'upload-submit') { UploadFile(f, i); + } } } function prepareHtml(f, i) { $("#cloud-index tr:nth-child(2)").after( - '' + + '' + '' + '' + f.name + '' + '' + @@ -182,8 +186,8 @@ function UploadFile(file, idx) { // POST to the entire cloud path xhr.open('post', window.location.pathname, true); - var data = new FormData(document.getElementById("ajax-upload-files")); - + var data = new FormData(); + data.append('sabreAction', 'put'); data.append('file', file); xhr.send(data); -- cgit v1.2.3 From 500ee4c1bf50efc5a9db419d9ad1c722851c29aa Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 28 Jul 2016 16:35:27 +0200 Subject: re-implement progress-bar to work with all browsers --- view/js/mod_cloud.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index ea1ce35a7..72e6185d6 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -88,11 +88,14 @@ function UploadFileSelectHandler(e) { function prepareHtml(f, i) { $("#cloud-index tr:nth-child(2)").after( - '' + - '' + + '' + + '' + '' + f.name + '' + - '' + - '' + formatSizeUnits(f.size) + '' + + '' + + '' + formatSizeUnits(f.size) + '' + + '' + + '' + + '' + '' ); } @@ -166,7 +169,7 @@ function UploadFile(file, idx) { var total = e.totalSize || e.total; // Dynamically update the percentage complete displayed in the file upload list $('#upload-progress-' + idx).html(Math.round(done / total * 100) + '%'); - $('#new-upload-' + idx).css('background-size', Math.round(done / total * 100) + '%'); + $('#upload-progress-bar-' + idx).css('background-size', Math.round(done / total * 100) + '%'); }); xhr.addEventListener('load', function (e) { -- cgit v1.2.3 From 3bf2935ee363a784f0140242b569eb4e2a837249 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 28 Jul 2016 22:32:58 +0200 Subject: add more info on what is happening after we are at 100% and minor fixes --- view/js/mod_cloud.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 72e6185d6..cdcb0c8ee 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -88,13 +88,13 @@ function UploadFileSelectHandler(e) { function prepareHtml(f, i) { $("#cloud-index tr:nth-child(2)").after( - '' + + '' + '' + '' + f.name + '' + '' + '' + formatSizeUnits(f.size) + '' + '' + - '' + + '' + '' + '' ); @@ -134,6 +134,7 @@ function getIconFromType(type) { 'application/x-rar-compressed': 'fa-file-archive-o', //Audio 'audio/mpeg': 'fa-file-audio-o', + 'audio/mp3': 'fa-file-audio-o', //webkit browsers need that 'audio/wav': 'fa-file-audio-o', 'application/ogg': 'fa-file-audio-o', 'audio/ogg': 'fa-file-audio-o', @@ -158,27 +159,37 @@ function getIconFromType(type) { // upload files function UploadFile(file, idx) { - window.filesToUpload = window.filesToUpload + 1; + window.filesToUpload = window.filesToUpload + 1 var xhr = new XMLHttpRequest(); xhr.withCredentials = true; // Include the SESSION cookie info for authentication (xhr.upload || xhr).addEventListener('progress', function (e) { + var done = e.position || e.loaded; var total = e.totalSize || e.total; // Dynamically update the percentage complete displayed in the file upload list $('#upload-progress-' + idx).html(Math.round(done / total * 100) + '%'); $('#upload-progress-bar-' + idx).css('background-size', Math.round(done / total * 100) + '%'); + + if(done == total) { + $('#upload-progress-' + idx).html('Processing...'); + } + }); + xhr.addEventListener('load', function (e) { + //we could possibly turn the filenames to real links here and add the delete and edit buttons to avoid page reload... + $('#upload-progress-' + idx).html('Ready!'); //console.log('xhr upload complete', e); window.fileUploadsCompleted = window.fileUploadsCompleted + 1; // When all the uploads have completed, refresh the page if (window.filesToUpload > 0 && window.fileUploadsCompleted === window.filesToUpload) { + window.fileUploadsCompleted = window.filesToUpload = 0; // After uploads complete, refresh browser window to display new files @@ -186,6 +197,11 @@ function UploadFile(file, idx) { } }); + + xhr.addEventListener('error', function (e) { + $('#upload-progress-' + idx).html('ERROR'); + }); + // POST to the entire cloud path xhr.open('post', window.location.pathname, true); -- cgit v1.2.3 From ed7e4df0142c51096ef7f1219d80289ad3d14085 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 28 Jul 2016 22:57:07 +0200 Subject: missing semicolon --- view/js/mod_cloud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index cdcb0c8ee..6d6ef9fd1 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -159,7 +159,7 @@ function getIconFromType(type) { // upload files function UploadFile(file, idx) { - window.filesToUpload = window.filesToUpload + 1 + window.filesToUpload = window.filesToUpload + 1; var xhr = new XMLHttpRequest(); -- cgit v1.2.3 From b15a53b672fa6b94181c9144e8a11a8b774fb7d5 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 28 Jul 2016 22:59:01 +0200 Subject: missing space --- view/js/mod_cloud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 6d6ef9fd1..0c3bfe120 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -94,7 +94,7 @@ function prepareHtml(f, i) { '' + '' + formatSizeUnits(f.size) + '' + '' + - '' + + '' + '' + '' ); -- cgit v1.2.3 From 5e5ec5a66a64d43ef5ea14c03b32055863f11bf1 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 29 Jul 2016 11:30:33 +0200 Subject: catch all input fields (in preparation for acl in this place) and display the files to upload in the right order --- view/js/mod_cloud.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'view/js') diff --git a/view/js/mod_cloud.js b/view/js/mod_cloud.js index 0c3bfe120..e56ec2a81 100644 --- a/view/js/mod_cloud.js +++ b/view/js/mod_cloud.js @@ -74,8 +74,6 @@ function UploadFileSelectHandler(e) { var files = e.target.files; } - - // process all File objects for (var i = 0, f; f = files[i]; i++) { if(e.target.id === 'files-upload') @@ -87,7 +85,8 @@ function UploadFileSelectHandler(e) { } function prepareHtml(f, i) { - $("#cloud-index tr:nth-child(2)").after( + var num = i - 1; + $('#cloud-index #new-upload-progress-bar-' + num.toString()).after( '' + '' + '' + f.name + '' + @@ -205,8 +204,12 @@ function UploadFile(file, idx) { // POST to the entire cloud path xhr.open('post', window.location.pathname, true); + var formfields = $("#ajax-upload-files").serializeArray(); + var data = new FormData(); - data.append('sabreAction', 'put'); + $.each(formfields, function(i, field) { + data.append(field.name, field.value); + }); data.append('file', file); xhr.send(data); -- cgit v1.2.3