diff --git a/cps/static/js/get_meta.js b/cps/static/js/get_meta.js index 316d2651..80543516 100644 --- a/cps/static/js/get_meta.js +++ b/cps/static/js/get_meta.js @@ -4,6 +4,7 @@ * Google Books api document: https://developers.google.com/books/docs/v1/using * Douban Books api document: https://developers.douban.com/wiki/?title=book_v2 (Chinese Only) */ + /* global i18nMsg */ $(document).ready(function () { var msg = i18nMsg; @@ -26,36 +27,39 @@ $(document).ready(function () { }; function showResult () { + var book; + var i; + var bookHtml; showFlag++; if (showFlag === 1) { - $("#meta-info").html(''); + $("#meta-info").html(""); } if (ggDone && dbDone) { if (!ggResults && !dbResults) { - $("#meta-info").html('

'+ msg.no_result +"

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

"+ msg.no_result +"

"); return; } } if (ggDone && ggResults.length > 0) { - for (var i = 0; i < ggResults.length; i++) { - var book = ggResults[i]; + for (i = 0; i < ggResults.length; i++) { + book = ggResults[i]; var bookCover; if (book.volumeInfo.imageLinks) { bookCover = book.volumeInfo.imageLinks.thumbnail; } else { bookCover = "/static/generic_cover.jpg"; } - var bookHtml = '
  • ' + - 'Cover' + - '
    ' + - '

    ' + book.volumeInfo.title + '

    ' + + bookHtml = "
  • " + + "\"Cover\"Google Books

    ' + + "

    "+ msg.source + ":Google Books

    " + "" + "
  • "; $("#book-list").append(bookHtml); @@ -63,19 +67,19 @@ $(document).ready(function () { ggDone = false; } if (dbDone && dbResults.length > 0) { - for (var i = 0; i < dbResults.length; i++) { - var book = dbResults[i]; - var bookHtml = '
  • ' + - 'Cover' + - '
    ' + - '

    ' + book.title + "

    " + + for (i = 0; i < dbResults.length; i++) { + book = dbResults[i]; + bookHtml = "
  • " + + "\"Cover\"" + + "
    " + + "

    " + book.title + "

    " + "

    " + msg.author + ":" + book.author + "

    " + "

    " + msg.publisher + ":" + book.publisher + "

    " + "

    " + msg.description + ":" + book.summary + "

    " + - "

    " + msg.source + ':Douban Books

    ' + + "

    " + msg.source + ":Douban Books

    " + "
    " + "
  • "; $("#book-list").append(bookHtml); @@ -92,17 +96,17 @@ $(document).ready(function () { type: "GET", dataType: "jsonp", jsonp: "callback", - success: function (data) { + success (data) { ggResults = data.items; }, - complete: function () { + complete () { ggDone = true; showResult(); } }); } - function get_meta (source, id) { + function getMeta (source, id) { var meta; var tags; if (source === "google") { @@ -134,6 +138,26 @@ $(document).ready(function () { } } + function dbSearchBook (title) { + var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10"; + $.ajax({ + url: url, + type: "GET", + dataType: "jsonp", + jsonp: "callback", + success (data) { + dbResults = data.books; + }, + error () { + $("#meta-info").html('

    '+ msg.search_error+"!

    "); + }, + complete () { + dbDone = true; + showResult(); + } + }); + } + function doSearch (keyword) { showFlag = 0; $("#meta-info").text(msg.loading); @@ -144,26 +168,6 @@ $(document).ready(function () { } } - function dbSearchBook (title) { - var url = douban + dbSearch + "?q=" + title + "&fields=all&count=10"; - $.ajax({ - url: url, - type: "GET", - dataType: "jsonp", - jsonp: "callback", - success: function (data) { - dbResults = data.books; - }, - error: function () { - $("#meta-info").html('

    '+ msg.search_error+"!

    "); - }, - complete: function () { - dbDone = true; - showResult(); - } - }); - } - $("#do-search").click(function () { var keyword = $("#keyword").val(); if (keyword) { diff --git a/cps/web.py b/cps/web.py index 8178ead2..3b3597e9 100755 --- a/cps/web.py +++ b/cps/web.py @@ -2688,13 +2688,15 @@ def upload(): author_names.append(author.name) if config.config_use_google_drive: updateGdriveCalibreFromLocal() - cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() - if current_user.role_edit() or current_user.role_admin(): - return render_title_template('book_edit.html', book=db_book, authors=author_names, cc=cc, - title=_(u"edit metadata")) - book_in_shelfs = [] - return render_title_template('detail.html', entry=db_book, cc=cc, title=db_book.title, - books_shelfs=book_in_shelfs, ) + cc = db.session.query(db.Custom_Columns).filter(db.Custom_Columns.datatype.notin_(db.cc_exceptions)).all() + if current_user.role_edit() or current_user.role_admin(): + return render_title_template('book_edit.html', book=db_book, authors=author_names, cc=cc, + title=_(u"edit metadata")) + book_in_shelfs = [] + return render_title_template('detail.html', entry=db_book, cc=cc, title=db_book.title, + books_shelfs=book_in_shelfs, ) + else: + return redirect(url_for("index")) def start_gevent(): from gevent.wsgi import WSGIServer