display on progress uploading files, show PUT error

This commit is contained in:
ishadurin 2016-05-18 23:27:46 +03:00
parent dfcd42e917
commit 92e2cf3b96
4 changed files with 33 additions and 11 deletions

View file

@ -18,16 +18,18 @@ function uploadFile(files, nr, uri) {
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var newHash = xhr.responseText;
console.log("New hash - " + newHash);
if (newHash.length != 64) {
// something wrong
console.log("Something wrong on uploading");
console.log(newHash);
alert('Oh, error on PUT file to BZZ. See log for more information.');
return;
}
console.log("new hash - " + newHash);
insertImage(files, nr, newHash, currentFile.name);
insertImage(files, nr, newHash, currentFile.name, function () {
uploadFile(files, nr + 1, "/bzz:/" + newHash + "/");
});
}
};
xhr.open("PUT", uri + "imgs/" + currentFile.name, true);
@ -48,7 +50,7 @@ function readFile(file, onComplete) {
reader.readAsArrayBuffer(file);
}
function insertImage(files, nr, newHash, fileName) {
function insertImage(files, nr, newHash, fileName, onComplete) {
// insert image into index
var img = new Image();
img.onload = function () {
@ -68,16 +70,24 @@ function insertImage(files, nr, newHash, fileName) {
} else {
// square
thumbData[0] = imageToUrl(img, thumbSize, thumbSize);
thumbData[1] = [w, thumbSize];
thumbData[1] = [thumbSize, thumbSize];
}
jQuery('#currentPreview').attr('src', thumbData[0]);
// update index
var imgData = [];
imgData[0] = "imgs/" + fileName;
imgData[1] = [img.naturalWidth, img.naturalHeight];
imgs.data.splice(eidx, 0, {img: imgData, thumb: thumbData, blur: blur});
console.log("this one");
uploadFile(files, nr + 1, "/bzz:/" + newHash + "/");
if (onComplete) {
onComplete();
}
};
img.onerror = function () {
if (onComplete) {
onComplete();
}
};
img.src = "/bzz:/" + newHash + "/imgs/" + fileName;

View file

@ -289,3 +289,7 @@ img
{
background: url(cut-mov.png) top left repeat-y, url(cut-mov.png) top right repeat-y;
}
#currentPreview {
max-height: 120px;
}

View file

@ -12,9 +12,9 @@
<script src="mootools-more-1.4.js" type="text/javascript"></script>
<script src="mootools-idle.js" type="text/javascript"></script>
<script src="mootools-mooswipe.js" type="text/javascript"></script>
<script src="index.js" type="text/javascript"></script>
<script src="file-manager.js" type="text/javascript"></script>
<script src="index.js" type="text/javascript"></script>
<link href="index.css" rel="stylesheet" type="text/css"/>
</head>
<body>

View file

@ -2,7 +2,8 @@
// Copyright(c) 2003-2014 by wave++ "Yuri D'Elia" <wavexx@thregr.org>
// Distributed under GPL2 (see COPYING) WITHOUT ANY WARRANTY.
var datafile = 'data.json';
var padding = 22;
var padding = 100;
var marginTop = 50;
var duration = 500;
var thrdelay = 1500;
var hidedelay = 3000;
@ -41,6 +42,7 @@ var eback; // background
var enoise; // additive noise
var eflash; // flashing object
var ehdr; // header
var progress; // progress
var elist; // thumbnail list
var fscr; // thumbnail list scroll fx
var econt; // picture container
@ -231,7 +233,7 @@ function resizeMainImg(img)
img.setStyles(
{
'position': 'absolute',
'top': contSize.y / 2 - img.height / 2,
'top': (contSize.y / 2 - img.height / 2) + marginTop,
'left': contSize.x / 2 - img.width / 2
});
}
@ -362,6 +364,9 @@ function onMainReady()
ehdr.set('html', dsc.join(' '));
ehdr.setStyle('display', (dsc.length? 'block': 'none'));
progress.set('html', '<img id="currentPreview">');
progress.set('style', 'text-align: center; padding-top: 20px');
// complete thumbnails
var d = duration;
if(first !== false)
@ -596,6 +601,9 @@ function initGallery(data)
ehdr = new Element('div', { id: 'header' });
ehdr.inject(econt);
progress = new Element('div', { id: 'progress' });
progress.inject(econt);
elist = new Element('div', { id: 'list' });
elist.inject(emain);