add i18n message for getmeta feature.

pull/128/head
idalin 8 years ago
parent f8e4bed8bf
commit a6b2977286

@ -6,6 +6,7 @@
*/ */
$(document).ready(function () { $(document).ready(function () {
var msg = i18n_msg;
var douban = 'https://api.douban.com'; var douban = 'https://api.douban.com';
var db_search = '/v2/book/search'; var db_search = '/v2/book/search';
var db_get_info = '/v2/book/'; var db_get_info = '/v2/book/';
@ -74,7 +75,7 @@ $(document).ready(function () {
} }
do_search = function (keyword) { do_search = function (keyword) {
show_flag = 0; show_flag = 0;
$('#meta-info').text('Loading...'); $('#meta-info').text(msg.loading);
var keyword = $('#keyword').val(); var keyword = $('#keyword').val();
if (keyword) { if (keyword) {
db_search_book(keyword); db_search_book(keyword);
@ -93,7 +94,7 @@ $(document).ready(function () {
db_results = data.books; db_results = data.books;
}, },
error: function () { error: function () {
$('#meta-info').html('<p class="text-danger">Search error!</p>'); $('#meta-info').html('<p class="text-danger">'+ msg.search_error+'!</p>');
}, },
complete: function () { complete: function () {
db_done = true; db_done = true;
@ -108,8 +109,8 @@ $(document).ready(function () {
$('#meta-info').html('<ul id="book-list" class="media-list"></ul>'); $('#meta-info').html('<ul id="book-list" class="media-list"></ul>');
} }
if (gg_done && db_done) { if (gg_done && db_done) {
if (gg_results.length < 1 && db_results.length < 1) { if (!gg_results || !db_results) {
$('#meta-info').html('<p class="text-danger">No Result! Please try anonther keyword.</p>'); $('#meta-info').html('<p class="text-danger">'+ msg.no_result +'</p>');
return; return;
} }
} }
@ -129,10 +130,10 @@ $(document).ready(function () {
'<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>' +
'<p>Author' + book.volumeInfo.authors + '</p>' + '<p>'+ msg.author +'' + book.volumeInfo.authors + '</p>' +
'<p>Publisher' + book.volumeInfo.publisher + '</p>' + '<p>'+ msg.publisher + '' + book.volumeInfo.publisher + '</p>' +
'<p>Description:' + book.volumeInfo.description + '</p>' + '<p>'+ msg.description + ':' + book.volumeInfo.description + '</p>' +
'<p>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(book_html); $("#book-list").append(book_html);
@ -149,10 +150,10 @@ $(document).ready(function () {
'<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>' +
'<p>Author' + book.author + '</p>' + '<p>' + msg.author + '' + book.author + '</p>' +
'<p>Publisher' + book.publisher + '</p>' + '<p>' + msg.publisher + '' + book.publisher + '</p>' +
'<p>Description:' + book.summary + '</p>' + '<p>' + msg.description + ':' + book.summary + '</p>' +
'<p>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(book_html); $("#book-list").append(book_html);

@ -1,9 +1,13 @@
{% extends "layout.html" %} {% block body %} {% if book %} {% extends "layout.html" %}
{% block body %}
{% if book %}
<div class="col-sm-3 col-lg-3 col-xs-12"> <div class="col-sm-3 col-lg-3 col-xs-12">
<div class="cover"> <div class="cover">
{% if book.has_cover %} {% if book.has_cover %}
<img src="{{ url_for('get_cover', cover_path=book.path.replace('\\','/')) }}" /> {% else %} <img src="{{ url_for('get_cover', cover_path=book.path.replace('\\','/')) }}" />
<img src="{{ url_for('static', filename='generic_cover.jpg') }}" /> {% endif %} {% else %}
<img src="{{ url_for('static', filename='generic_cover.jpg') }}" />
{% endif %}
</div> </div>
</div> </div>
<div class="col-sm-8"> <div class="col-sm-8">
@ -25,43 +29,54 @@
<input type="text" class="form-control typeahead" name="tags" id="tags" value="{% for tag in book.tags %}{{tag.name.strip()}}, {% endfor %}"> <input type="text" class="form-control typeahead" name="tags" id="tags" value="{% for tag in book.tags %}{{tag.name.strip()}}, {% endfor %}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="series">{{_('Series')}}</label> <label for="series">{{_('Series')}}</label>
<input type="text" class="form-control typeahead" name="series" id="series" value="{% if book.series %}{{book.series[0].name}}{% endif %}"> <input type="text" class="form-control typeahead" name="series" id="series" value="{% if book.series %}{{book.series[0].name}}{% endif %}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="series_index">{{_('Series id')}}</label> <label for="series_index">{{_('Series id')}}</label>
<input type="text" class="form-control" name="series_index" id="series_index" value="{{book.series_index}}"> <input type="text" class="form-control" name="series_index" id="series_index" value="{{book.series_index}}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="rating">{{_('Rating')}}</label> <label for="rating">{{_('Rating')}}</label>
<input type="number" min="0" max="5" step="1" class="form-control" name="rating" id="rating" value="{% if book.ratings %}{{book.ratings[0].rating / 2}}{% endif %}"> <input type="number" min="0" max="5" step="1" class="form-control" name="rating" id="rating" value="{% if book.ratings %}{{book.ratings[0].rating / 2}}{% endif %}">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="cover_url">{{_('Cover URL (jpg)')}}</label> <label for="cover_url">{{_('Cover URL (jpg)')}}</label>
<input type="text" class="form-control" name="cover_url" id="cover_url" value=""> <input type="text" class="form-control" name="cover_url" id="cover_url" value="">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="languages">{{_('Language')}}</label> <label for="languages">{{_('Language')}}</label>
<input type="text" class="form-control typeahead" name="languages" id="languages" value="{% for language in book.languages %}{{language.language_name.strip()}}, {% endfor %}"> <input type="text" class="form-control typeahead" name="languages" id="languages" value="{% for language in book.languages %}{{language.language_name.strip()}}, {% endfor %}">
</div> </div>
{% if cc|length > 0 %} {% for c in cc %} {% if cc|length > 0 %}
<div class="form-group"> {% for c in cc %}
<label for="{{ 'custom_column_' ~ c.id }}">{{ c.name }}</label> {% if c.datatype == 'bool' %} <div class="form-group">
<select name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" class="form-control"> <label for="{{ 'custom_column_' ~ c.id }}">{{ c.name }}</label>
{% if c.datatype == 'bool' %}
<select name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" class="form-control">
<option value="None" {% if book['custom_column_' ~ c.id]|length == 0 %} selected {% endif %}></option> <option value="None" {% if book['custom_column_' ~ c.id]|length == 0 %} selected {% endif %}></option>
<option value="True" {% if book['custom_column_' ~ c.id]|length > 0 %}{% if book['custom_column_' ~ c.id][0].value ==true %}selected{% endif %}{% endif %} >{{_('Yes')}}</option> <option value="True" {% if book['custom_column_' ~ c.id]|length > 0 %}{% if book['custom_column_' ~ c.id][0].value ==true %}selected{% endif %}{% endif %} >{{_('Yes')}}</option>
<option value="False" {% if book['custom_column_' ~ c.id]|length > 0 %}{% if book['custom_column_' ~ c.id][0].value ==false %}selected{% endif %}{% endif %}>{{_('No')}}</option> <option value="False" {% if book['custom_column_' ~ c.id]|length > 0 %}{% if book['custom_column_' ~ c.id][0].value ==false %}selected{% endif %}{% endif %}>{{_('No')}}</option>
</select> {% endif %} {% if c.datatype in ['text', 'series'] and not c.is_multiple %} </select>
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" {% if book[ {% endif %}
'custom_column_' ~ c.id]|length> 0 %} value="{{ book['custom_column_' ~ c.id][0].value }}" {% endif %}> {% endif %} {% if c.datatype {% if c.datatype in ['text', 'series'] and not c.is_multiple %}
in ['text', 'series'] and c.is_multiple %} <input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" {% if book[ {% if book['custom_column_' ~ c.id]|length > 0 %}
'custom_column_' ~ c.id]|length> 0 %} value="{% for column in book['custom_column_' ~ c.id] %}{{ column.value.strip() }}{% if value="{{ book['custom_column_' ~ c.id][0].value }}"
not loop.last %}, {% endif %}{% endfor %}"{% endif %}> {% endif %} {% if c.datatype == 'enumeration' %} {% endif %}>
<select class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"> {% endif %}
{% if c.datatype in ['text', 'series'] and c.is_multiple %}
<input type="text" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"
{% if book['custom_column_' ~ c.id]|length > 0 %}
value="{% for column in book['custom_column_' ~ c.id] %}{{ column.value.strip() }}{% if not loop.last %}, {% endif %}{% endfor %}"{% endif %}>
{% endif %}
{% if c.datatype == 'enumeration' %}
<select class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}">
<option></option> <option></option>
{% for opt in c.get_display_dict().enum_values %} {% for opt in c.get_display_dict().enum_values %}
<option <option
@ -70,20 +85,26 @@
{% endif %} {% endif %}
>{{ opt }}</option> >{{ opt }}</option>
{% endfor %} {% endfor %}
</select> {% endif %} {% if c.datatype == 'rating' %} </select>
<input type="number" min="1" max="5" step="1" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}" {% endif %}
{% if book[ 'custom_column_' ~ c.id]|length> 0 %} value="{{ '%d' % (book['custom_column_' ~ c.id][0].value /
2) }}" {% endif %}> {% endif %}
</div>
{% endfor %} {% endif %}
{% if c.datatype == 'rating' %}
<input type="number" min="1" max="5" step="1" class="form-control" name="{{ 'custom_column_' ~ c.id }}" id="{{ 'custom_column_' ~ c.id }}"
{% if book['custom_column_' ~ c.id]|length > 0 %}
value="{{ '%d' % (book['custom_column_' ~ c.id][0].value / 2) }}"
{% endif %}>
{% endif %}
</div>
{% endfor %}
{% endif %}
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input name="detail_view" type="checkbox" checked> {{_('view book after edit')}} <input name="detail_view" type="checkbox" checked> {{_('view book after edit')}}
</label> </label>
</div> </div>
<a href="#" id="get_meta" class="btn btn-default" data-toggle="modal" data-target="#metaModal">{{_('Get Meta Data')}}</a> <a href="#" id="get_meta" class="btn btn-default" data-toggle="modal" data-target="#metaModal">{{_('Get Metadata')}}</a>
<button type="submit" class="btn btn-default">{{_('Submit')}}</button> <button type="submit" class="btn btn-default">{{_('Submit')}}</button>
<a href="{{ url_for('show_book',id=book.id) }}" class="btn btn-default">{{_('Back')}}</a> <a href="{{ url_for('show_book',id=book.id) }}" class="btn btn-default">{{_('Back')}}</a>
</form> </form>
@ -94,14 +115,14 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="metaModalLabel">{{_('Get meta data')}}</h4> <h4 class="modal-title" id="metaModalLabel">{{_('Get metadata')}}</h4>
<form class="form-inline"> <form class="form-inline">
<div class="form-group"> <div class="form-group">
<label class="sr-only" for="keyword">Keyword</label> <label class="sr-only" for="keyword">{{_('Keyword')}}</label>
<input type="text" class="form-control" id="keyword" placeholder="{{_(" Search keyword ")}}"> <input type="text" class="form-control" id="keyword" placeholder="{{_(" Search keyword ")}}">
</div> </div>
<button type="button" class="btn btn-default" id="do-search">{{_("Go!")}}</button> <button type="button" class="btn btn-default" id="do-search">{{_("Go!")}}</button>
<span>{{_('Click the cover to load meta data to the form')}}</span> <span>{{_('Click the cover to load metadata to the form')}}</span>
</form> </form>
</div> </div>
<div class="modal-body" id="meta-info"> <div class="modal-body" id="meta-info">
@ -113,13 +134,24 @@
</div> </div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{% block js %} {% block js %}
<script>
var i18n_msg = {
'loading': {{_('Loading...')|safe|tojson}},
'search_error': {{_('Search error!')|safe|tojson}},
'no_result': {{_('No Result! Please try anonther keyword.')|safe|tojson}},
'author': {{_('Author')|safe|tojson}},
'publisher': {{_('Publisher')|safe|tojson}},
'description': {{_('Description')|safe|tojson}},
'source': {{_('Source')|safe|tojson}},
};
</script>
<script src="{{ url_for('static', filename='js/libs/typeahead.bundle.js') }}"></script> <script src="{{ url_for('static', filename='js/libs/typeahead.bundle.js') }}"></script>
<script src="{{ url_for('static', filename='js/edit_books.js') }}"></script> <script src="{{ url_for('static', filename='js/edit_books.js') }}"></script>
<script src="{{ url_for('static', filename='js/get_meta.js') }}"></script> <script src="{{ url_for('static', filename='js/get_meta.js') }}"></script>
{% endblock %} {% endblock %}
{% block header %} {% block header %}
<link href="{{ url_for('static', filename='css/libs/typeahead.css') }}" rel="stylesheet" media="screen"> <link href="{{ url_for('static', filename='css/libs/typeahead.css') }}" rel="stylesheet" media="screen">
{% endblock %} {% endblock %}

Loading…
Cancel
Save