diff --git a/cps/static/js/get_meta.js b/cps/static/js/get_meta.js index 99fce061..26167326 100644 --- a/cps/static/js/get_meta.js +++ b/cps/static/js/get_meta.js @@ -5,6 +5,8 @@ * Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only) */ /* global i18nMsg */ +var dbResults = []; +var ggResults = []; $(document).ready(function () { var msg = i18nMsg; @@ -19,8 +21,6 @@ $(document).ready(function () { // var gg_get_info = "/books/v1/volumes/"; var ggDone = false; - var dbResults = []; - var ggResults = []; var showFlag = 0; String.prototype.replaceAll = function (s1, s2) { return this.replace(new RegExp(s1, "gm"), s2); @@ -32,11 +32,11 @@ $(document).ready(function () { var bookHtml; showFlag++; if (showFlag === 1) { - $("#meta-info").html(""); + $("#metaModal #meta-info").html(""); } if (ggDone && dbDone) { if (!ggResults && !dbResults) { - $("#meta-info").html("

"+ msg.no_result +"

"); + $("#metaModal #meta-info").html("

"+ msg.no_result +"

"); return; } } @@ -51,8 +51,8 @@ $(document).ready(function () { } bookHtml = "
  • " + "\"Cover\"" + "
    " + "

    " + book.volumeInfo.title + "

    " + @@ -62,7 +62,7 @@ $(document).ready(function () { "

    "+ msg.source + ":Google Books

    " + "
    " + "
  • "; - $("#book-list").append(bookHtml); + $("#metaModal #book-list").append(bookHtml); } ggDone = false; } @@ -71,8 +71,8 @@ $(document).ready(function () { book = dbResults[i]; bookHtml = "
  • " + "\"Cover\"" + + book.image + "\" alt=\"Cover\" style=\"width:100px;height: 150px\" onclick='getMeta(\"douban\"," + + i + ")'>" + "
    " + "

    " + book.title + "

    " + @@ -82,7 +82,7 @@ $(document).ready(function () { "

    " + msg.source + ":Douban Books

    " + "
    " + "
  • "; - $("#book-list").append(bookHtml); + $("#metaModal #book-list").append(bookHtml); } 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) { var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10"; $.ajax({ @@ -149,7 +117,7 @@ $(document).ready(function () { dbResults = data.books; }, error () { - $("#meta-info").html("

    "+ msg.search_error+"!

    "); + $("#metaModal #meta-info").html("

    "+ msg.search_error+"!

    "); }, complete () { dbDone = true; @@ -160,7 +128,7 @@ $(document).ready(function () { function doSearch (keyword) { showFlag = 0; - $("#meta-info").text(msg.loading); + $("#metaModal #meta-info").text(msg.loading); // var keyword = $("#keyword").val(); if (keyword) { dbSearchBook(keyword); @@ -183,4 +151,36 @@ $(document).ready(function () { } }); -}); \ No newline at end of file +}); + +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; + } +} diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html index 594aff22..5b44ac07 100644 --- a/cps/templates/book_edit.html +++ b/cps/templates/book_edit.html @@ -117,6 +117,9 @@ {% endif %} +{% endblock %} + +{% block modal %} {% if g.user.role_delete_books() %} + {% block modal %}{% endblock %} {% block js %}{% endblock %}