summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-09-13 14:11:49 +0300
committerAndrew Dolgov <[email protected]>2018-09-13 14:11:49 +0300
commitb5b914878733d9c1a7f95f833dcda15cad9770d9 (patch)
tree5c70fb4d2de5e8b48e90be0c593f9525744b5e5f
parentf9030b3157226733a8154abe235f78a8f35a1df5 (diff)
add download complete notifications
-rw-r--r--index.php1
-rw-r--r--js/index.js31
2 files changed, 24 insertions, 8 deletions
diff --git a/index.php b/index.php
index e3610d2..22eac6c 100644
--- a/index.php
+++ b/index.php
@@ -171,6 +171,7 @@
</div>
</div>
+<div style="display : none" class="alert alert-info dl-progress"></div>
<?php
diff --git a/js/index.js b/js/index.js
index c51515b..b16a742 100644
--- a/js/index.js
+++ b/js/index.js
@@ -1,5 +1,7 @@
'use strict';
+var _dl_progress_timeout;
+
function cache_refresh(force) {
if ('serviceWorker' in navigator) {
localforage.getItem("epube.cache-timestamp").then(function(stamp) {
@@ -94,7 +96,9 @@ function offline_cache(bookId, callback) {
console.log(cacheId + ' got data');
- fetch('backend.php?op=download&id=' + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
+ var promises = [];
+
+ promises.push(fetch('backend.php?op=download&id=' + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
if (resp.status == 200) {
console.log(cacheId + ' got book');
@@ -102,9 +106,9 @@ function offline_cache(bookId, callback) {
localforage.setItem(cacheId + '.book', resp.blob());
}
- });
+ }));
- fetch("backend.php?op=getpagination&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
+ promises.push(fetch("backend.php?op=getpagination&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
if (resp.status == 200) {
console.log(cacheId + ' got pagination');
@@ -112,30 +116,41 @@ function offline_cache(bookId, callback) {
localforage.setItem(cacheId + '.locations', JSON.parse(text));
});
}
- });
+ }));
- fetch("backend.php?op=getlastread&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
+ promises.push(fetch("backend.php?op=getlastread&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
if (resp.status == 200) {
console.log(cacheId + ' got lastread');
resp.text().then(function(text) {
localforage.setItem(cacheId + '.lastread', JSON.parse(text));
});
}
- });
+ }));
if (data.has_cover) {
- fetch("backend.php?op=cover&id=" + bookId, {credentials: 'same-origin'}).then(function(resp) {
+ promises.push(fetch("backend.php?op=cover&id=" + bookId, {credentials: 'same-origin'}).then(function(resp) {
if (resp.status == 200) {
console.log(cacheId + ' got cover');
localforage.setItem(cacheId + '.cover', resp.blob());
}
- });
+ }));
}
+ Promise.all(promises).then(function() {
+ $(".dl-progress")
+ .show()
+ .html("Finished downloading <b>" + data.title + "</b>");
+
+ window.clearTimeout(_dl_progress_timeout);
+
+ _dl_progress_timeout = window.setTimeout(function() {
+ $(".dl-progress").fadeOut();
+ }, 5*1000);
+ });
});
}