summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-04-21 08:43:04 +0300
committerAndrew Dolgov <[email protected]>2020-04-21 08:43:04 +0300
commitd7b02e140e628fcb0ba838925ff0ad4237dbb6cd (patch)
tree00063293b9a97b093bb24e23c9c49e3cccaffea1
parent0a80c7a89cbe092d4ec6591b1ce0ab68479323d6 (diff)
app: rename some offline-related methods
-rw-r--r--index.php2
-rw-r--r--js/app.js192
2 files changed, 97 insertions, 97 deletions
diff --git a/index.php b/index.php
index 1e4f523..6d402f8 100644
--- a/index.php
+++ b/index.php
@@ -120,7 +120,7 @@
</a></li>
<?php } ?>
<?php if ($mode == "favorites") { ?>
- <li><a href="#" onclick="App.offlineGetAll()" title="Download all">
+ <li><a href="#" onclick="App.Offline.getAll()" title="Download all">
<span class="glyphicon glyphicon-download-alt text-primary"></span> <span class='hidden-sm hidden-md hidden-lg'>Download all</span>
</a></li>
<?php } ?>
diff --git a/js/app.js b/js/app.js
index 885bfb2..2aacebf 100644
--- a/js/app.js
+++ b/js/app.js
@@ -112,101 +112,6 @@ const App = {
return false;
},
- offlineGetAll: function() {
- if (confirm("Download all books on this page?")) {
-
- $(".row > div").each(function (i, row) {
- const bookId = $(row).attr("id").replace("cell-", "");
- const dropitem = $(row).find(".offline_dropitem")[0];
-
- if (bookId) {
-
- const cacheId = 'epube-book.' + bookId;
- localforage.getItem(cacheId).then(function(book) {
-
- if (!book) {
- App.offlineCache(bookId, function() {
- App.Offline.mark(dropitem);
- });
- }
-
- });
-
- }
- });
- }
- },
- offlineCache: function(bookId, callback) {
- console.log("offline cache: " + bookId);
-
- $.post("backend.php", {op: "getinfo", id: bookId}, function(data) {
-
- if (data) {
- const cacheId = 'epube-book.' + bookId;
-
- localforage.setItem(cacheId, data).then(function(data) {
-
- console.log(cacheId + ' got data');
-
- const 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');
-
- callback();
-
- localforage.setItem(cacheId + '.book', resp.blob());
- }
- }));
-
- 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');
-
- resp.text().then(function(text) {
- localforage.setItem(cacheId + '.locations', JSON.parse(text));
- });
- }
- }));
-
- 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) {
-
- 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(App._dl_progress_timeout);
-
- App._dl_progress_timeout = window.setTimeout(function() {
- $(".dl-progress").fadeOut();
- }, 5*1000);
- });
- });
- }
- });
- },
showCovers: function() {
$("img[data-book-id]").each((i,e) => {
e = $(e);
@@ -362,7 +267,7 @@ const App = {
} else {
elem.onclick = function() {
- App.offlineCache(bookId, function() {
+ App.Offline.get(bookId, function() {
App.Offline.mark(elem);
});
return false;
@@ -542,4 +447,99 @@ const App = {
});
}
},
+ getAll: function() {
+ if (confirm("Download all books on this page?")) {
+
+ $(".row > div").each(function (i, row) {
+ const bookId = $(row).attr("id").replace("cell-", "");
+ const dropitem = $(row).find(".offline_dropitem")[0];
+
+ if (bookId) {
+
+ const cacheId = 'epube-book.' + bookId;
+ localforage.getItem(cacheId).then(function(book) {
+
+ if (!book) {
+ App.Offline.get(bookId, function() {
+ App.Offline.mark(dropitem);
+ });
+ }
+
+ });
+
+ }
+ });
+ }
+ },
+ get: function(bookId, callback) {
+ console.log("offline cache: " + bookId);
+
+ $.post("backend.php", {op: "getinfo", id: bookId}, function(data) {
+
+ if (data) {
+ const cacheId = 'epube-book.' + bookId;
+
+ localforage.setItem(cacheId, data).then(function(data) {
+
+ console.log(cacheId + ' got data');
+
+ const 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');
+
+ callback();
+
+ localforage.setItem(cacheId + '.book', resp.blob());
+ }
+ }));
+
+ 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');
+
+ resp.text().then(function(text) {
+ localforage.setItem(cacheId + '.locations', JSON.parse(text));
+ });
+ }
+ }));
+
+ 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) {
+
+ 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(App._dl_progress_timeout);
+
+ App._dl_progress_timeout = window.setTimeout(function() {
+ $(".dl-progress").fadeOut();
+ }, 5*1000);
+ });
+ });
+ }
+ });
+ },
};