parent
18744975b3
commit
ede8ae6742
|
@ -5,6 +5,8 @@
|
||||||
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
|
* Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only)
|
||||||
*/
|
*/
|
||||||
/* global i18nMsg */
|
/* global i18nMsg */
|
||||||
|
var dbResults = [];
|
||||||
|
var ggResults = [];
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
var msg = i18nMsg;
|
var msg = i18nMsg;
|
||||||
|
@ -19,8 +21,6 @@ $(document).ready(function () {
|
||||||
// var gg_get_info = "/books/v1/volumes/";
|
// var gg_get_info = "/books/v1/volumes/";
|
||||||
var ggDone = false;
|
var ggDone = false;
|
||||||
|
|
||||||
var dbResults = [];
|
|
||||||
var ggResults = [];
|
|
||||||
var showFlag = 0;
|
var showFlag = 0;
|
||||||
String.prototype.replaceAll = function (s1, s2) {
|
String.prototype.replaceAll = function (s1, s2) {
|
||||||
return this.replace(new RegExp(s1, "gm"), s2);
|
return this.replace(new RegExp(s1, "gm"), s2);
|
||||||
|
@ -32,11 +32,11 @@ $(document).ready(function () {
|
||||||
var bookHtml;
|
var bookHtml;
|
||||||
showFlag++;
|
showFlag++;
|
||||||
if (showFlag === 1) {
|
if (showFlag === 1) {
|
||||||
$("#meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
$("#metaModal #meta-info").html("<ul id=\"book-list\" class=\"media-list\"></ul>");
|
||||||
}
|
}
|
||||||
if (ggDone && dbDone) {
|
if (ggDone && dbDone) {
|
||||||
if (!ggResults && !dbResults) {
|
if (!ggResults && !dbResults) {
|
||||||
$("#meta-info").html("<p class=\"text-danger\">"+ msg.no_result +"</p>");
|
$("#metaModal #meta-info").html("<p class=\"text-danger\">"+ msg.no_result +"</p>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,8 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
bookHtml = "<li class=\"media\">" +
|
bookHtml = "<li class=\"media\">" +
|
||||||
"<img class=\"pull-left img-responsive\" data-toggle=\"modal\" data-target=\"#metaModal\" src=\"" +
|
"<img class=\"pull-left img-responsive\" data-toggle=\"modal\" data-target=\"#metaModal\" src=\"" +
|
||||||
bookCover + "\" alt=\"Cover\" style=\"width:100px;height:150px\" onclick='javascript:getMeta(\"google\"," +
|
bookCover + "\" alt=\"Cover\" style=\"width:100px;height:150px\" onclick='getMeta(\"google\"," +
|
||||||
i + ")\\>\"" +
|
i + ")'>" +
|
||||||
"<div class=\"media-body\">" +
|
"<div class=\"media-body\">" +
|
||||||
"<h4 class=\"media-heading\"><a href=\"https://books.google.com/books?id=" +
|
"<h4 class=\"media-heading\"><a href=\"https://books.google.com/books?id=" +
|
||||||
book.id + "\" target=\"_blank\">" + book.volumeInfo.title + "</a></h4>" +
|
book.id + "\" target=\"_blank\">" + book.volumeInfo.title + "</a></h4>" +
|
||||||
|
@ -62,7 +62,7 @@ $(document).ready(function () {
|
||||||
"<p>"+ msg.source + ":<a href=\"https://books.google.com\" target=\"_blank\">Google Books</a></p>" +
|
"<p>"+ msg.source + ":<a href=\"https://books.google.com\" target=\"_blank\">Google Books</a></p>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"</li>";
|
"</li>";
|
||||||
$("#book-list").append(bookHtml);
|
$("#metaModal #book-list").append(bookHtml);
|
||||||
}
|
}
|
||||||
ggDone = false;
|
ggDone = false;
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,8 @@ $(document).ready(function () {
|
||||||
book = dbResults[i];
|
book = dbResults[i];
|
||||||
bookHtml = "<li class=\"media\">" +
|
bookHtml = "<li class=\"media\">" +
|
||||||
"<img class=\"pull-left img-responsive\" data-toggle=\"modal\" data-target=\"#metaModal\" src=\"" +
|
"<img class=\"pull-left img-responsive\" data-toggle=\"modal\" data-target=\"#metaModal\" src=\"" +
|
||||||
book.image + "\" alt=\"Cover\" style=\"width:100px;height: 150px\" onclick='javascript:getMeta(\"douban\"," +
|
book.image + "\" alt=\"Cover\" style=\"width:100px;height: 150px\" onclick='getMeta(\"douban\"," +
|
||||||
i + ")\\'>" +
|
i + ")'>" +
|
||||||
"<div class=\"media-body\">" +
|
"<div class=\"media-body\">" +
|
||||||
"<h4 class=\"media-heading\"><a href=\"https://book.douban.com/subject/" +
|
"<h4 class=\"media-heading\"><a href=\"https://book.douban.com/subject/" +
|
||||||
book.id + "\" target=\"_blank\">" + book.title + "</a></h4>" +
|
book.id + "\" target=\"_blank\">" + book.title + "</a></h4>" +
|
||||||
|
@ -82,7 +82,7 @@ $(document).ready(function () {
|
||||||
"<p>" + msg.source + ":<a href=\"https://book.douban.com\" target=\"_blank\">Douban Books</a></p>" +
|
"<p>" + msg.source + ":<a href=\"https://book.douban.com\" target=\"_blank\">Douban Books</a></p>" +
|
||||||
"</div>" +
|
"</div>" +
|
||||||
"</li>";
|
"</li>";
|
||||||
$("#book-list").append(bookHtml);
|
$("#metaModal #book-list").append(bookHtml);
|
||||||
}
|
}
|
||||||
dbDone = false;
|
dbDone = false;
|
||||||
}
|
}
|
||||||
|
@ -106,38 +106,6 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMeta (source, id) {
|
|
||||||
var meta;
|
|
||||||
var tags;
|
|
||||||
if (source === "google") {
|
|
||||||
meta = ggResults[id];
|
|
||||||
$("#description").val(meta.volumeInfo.description);
|
|
||||||
$("#bookAuthor").val(meta.volumeInfo.authors.join(" & "));
|
|
||||||
$("#book_title").val(meta.volumeInfo.title);
|
|
||||||
if (meta.volumeInfo.categories) {
|
|
||||||
tags = meta.volumeInfo.categories.join(",");
|
|
||||||
$("#tags").val(tags);
|
|
||||||
}
|
|
||||||
if (meta.volumeInfo.averageRating) {
|
|
||||||
$("#rating").val(Math.round(meta.volumeInfo.averageRating));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (source === "douban") {
|
|
||||||
meta = dbResults[id];
|
|
||||||
$("#description").val(meta.summary);
|
|
||||||
$("#bookAuthor").val(meta.author.join(" & "));
|
|
||||||
$("#book_title").val(meta.title);
|
|
||||||
tags = "";
|
|
||||||
for (var i = 0; i < meta.tags.length; i++) {
|
|
||||||
tags = tags + meta.tags[i].title + ",";
|
|
||||||
}
|
|
||||||
$("#tags").val(tags);
|
|
||||||
$("#rating").val(Math.round(meta.rating.average / 2));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function dbSearchBook (title) {
|
function dbSearchBook (title) {
|
||||||
var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10";
|
var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10";
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -149,7 +117,7 @@ $(document).ready(function () {
|
||||||
dbResults = data.books;
|
dbResults = data.books;
|
||||||
},
|
},
|
||||||
error () {
|
error () {
|
||||||
$("#meta-info").html("<p class=\"text-danger\">"+ msg.search_error+"!</p>");
|
$("#metaModal #meta-info").html("<p class=\"text-danger\">"+ msg.search_error+"!</p>");
|
||||||
},
|
},
|
||||||
complete () {
|
complete () {
|
||||||
dbDone = true;
|
dbDone = true;
|
||||||
|
@ -160,7 +128,7 @@ $(document).ready(function () {
|
||||||
|
|
||||||
function doSearch (keyword) {
|
function doSearch (keyword) {
|
||||||
showFlag = 0;
|
showFlag = 0;
|
||||||
$("#meta-info").text(msg.loading);
|
$("#metaModal #meta-info").text(msg.loading);
|
||||||
// var keyword = $("#keyword").val();
|
// var keyword = $("#keyword").val();
|
||||||
if (keyword) {
|
if (keyword) {
|
||||||
dbSearchBook(keyword);
|
dbSearchBook(keyword);
|
||||||
|
@ -183,4 +151,36 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getMeta (source, id) {
|
||||||
|
var meta;
|
||||||
|
var tags;
|
||||||
|
if (source === "google") {
|
||||||
|
meta = ggResults[id];
|
||||||
|
$("#description").val(meta.volumeInfo.description);
|
||||||
|
$("#bookAuthor").val(meta.volumeInfo.authors.join(" & "));
|
||||||
|
$("#book_title").val(meta.volumeInfo.title);
|
||||||
|
if (meta.volumeInfo.categories) {
|
||||||
|
tags = meta.volumeInfo.categories.join(",");
|
||||||
|
$("#tags").val(tags);
|
||||||
|
}
|
||||||
|
if (meta.volumeInfo.averageRating) {
|
||||||
|
$("#rating").val(Math.round(meta.volumeInfo.averageRating));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (source === "douban") {
|
||||||
|
meta = dbResults[id];
|
||||||
|
$("#description").val(meta.summary);
|
||||||
|
$("#bookAuthor").val(meta.author.join(" & "));
|
||||||
|
$("#book_title").val(meta.title);
|
||||||
|
tags = "";
|
||||||
|
for (var i = 0; i < meta.tags.length; i++) {
|
||||||
|
tags = tags + meta.tags[i].title + ",";
|
||||||
|
}
|
||||||
|
$("#tags").val(tags);
|
||||||
|
$("#rating").val(Math.round(meta.rating.average / 2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -117,6 +117,9 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block modal %}
|
||||||
{% if g.user.role_delete_books() %}
|
{% if g.user.role_delete_books() %}
|
||||||
<div class="modal fade" id="deleteModal" role="dialog" aria-labelledby="metaDeleteLabel">
|
<div class="modal fade" id="deleteModal" role="dialog" aria-labelledby="metaDeleteLabel">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
|
|
|
@ -188,6 +188,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% block modal %}{% endblock %}
|
||||||
{% block js %}{% endblock %}
|
{% block js %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user