mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Content server: Add Next/Previous buttons to the book details page
This commit is contained in:
parent
768774a7be
commit
6fc6abc263
@ -11,7 +11,7 @@ from book_list.delete_book import refresh_after_delete, start_delete_book
|
||||
from book_list.globals import get_session_data
|
||||
from book_list.item_list import create_item, create_item_list
|
||||
from book_list.library_data import (
|
||||
all_libraries, book_metadata, cover_url, current_library_id,
|
||||
all_libraries, book_after, book_metadata, cover_url, current_library_id,
|
||||
current_virtual_library, download_url, library_data, load_status,
|
||||
set_book_metadata
|
||||
)
|
||||
@ -465,6 +465,21 @@ def render_book(container_id, book_id):
|
||||
table = E.table(class_='metadata')
|
||||
container.appendChild(md)
|
||||
md.appendChild(table)
|
||||
|
||||
def next_book(delta):
|
||||
next_book_id = book_after(book_id, delta)
|
||||
if next_book_id:
|
||||
q = parse_url_params()
|
||||
q.book_id = next_book_id + ''
|
||||
show_panel('book_details', query=q)
|
||||
|
||||
md.appendChild(E.div(
|
||||
style='margin-top: 1.5ex',
|
||||
create_button(_('Previous'), 'arrow-left', next_book.bind(None, -1)),
|
||||
'\xa0\xa0\xa0',
|
||||
create_button(_('Next'), 'arrow-right', next_book.bind(None, 1)),
|
||||
))
|
||||
|
||||
render_metadata(metadata, table, book_id)
|
||||
|
||||
|
||||
|
@ -106,14 +106,14 @@ def current_book_ids():
|
||||
return library_data.previous_book_ids.concat(library_data.search_result.book_ids)
|
||||
|
||||
|
||||
def book_after(book_id):
|
||||
def book_after(book_id, delta):
|
||||
if not delta:
|
||||
delta = 1
|
||||
ids = current_book_ids()
|
||||
idx = ids.indexOf(int(book_id))
|
||||
if idx > -1:
|
||||
if idx < ids.length - 1:
|
||||
return ids[idx + 1]
|
||||
if idx > 0: # wrap around
|
||||
return ids[0]
|
||||
new_idx = (idx + ids.length + delta) % ids.length
|
||||
return ids[new_idx]
|
||||
|
||||
|
||||
def on_data_loaded(end_type, xhr, ev):
|
||||
|
Loading…
x
Reference in New Issue
Block a user