mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix CS note editing not updating the book details view after edit
This commit is contained in:
parent
1bbd823c32
commit
bbf85a760b
@ -13,7 +13,7 @@ from book_list.book_details import (
|
||||
from book_list.comments_editor import (
|
||||
create_comments_editor, focus_comments_editor, get_comments_html, set_comments_html
|
||||
)
|
||||
from book_list.globals import get_current_query
|
||||
from book_list.globals import get_current_query, book_whose_metadata_is_being_edited
|
||||
from book_list.library_data import (
|
||||
book_metadata, cover_url, current_library_id, field_names_for, library_data,
|
||||
load_status, loaded_book_ids, set_book_metadata
|
||||
@ -1197,6 +1197,8 @@ def init(container_id):
|
||||
|
||||
|
||||
def init_select_item_for_edit_notes(container_id):
|
||||
q = parse_url_params()
|
||||
book_whose_metadata_is_being_edited(int(q.book_id))
|
||||
container = document.getElementById(container_id)
|
||||
create_top_bar(container, title=_('Edit metadata'), action=on_close.bind(None, container_id), icon='close')
|
||||
container.appendChild(E.div(class_=CLASS_NAME, tabindex='0', onkeydown=handle_keypress.bind(None, container_id)))
|
||||
|
@ -33,3 +33,11 @@ def get_translations(val):
|
||||
if val:
|
||||
get_translations.ans = val
|
||||
return get_translations.ans
|
||||
|
||||
|
||||
def book_whose_metadata_is_being_edited(set_book_id=''):
|
||||
if jstype(set_book_id) is 'number':
|
||||
book_whose_metadata_is_being_edited.ans = set_book_id
|
||||
elif set_book_id is None:
|
||||
book_whose_metadata_is_being_edited.ans = None
|
||||
return book_whose_metadata_is_being_edited.ans
|
||||
|
@ -10,6 +10,8 @@ from book_list.comments_editor import (
|
||||
set_comments_html
|
||||
)
|
||||
from book_list.details_list import sandbox_css
|
||||
from book_list.globals import book_whose_metadata_is_being_edited
|
||||
from book_list.library_data import book_metadata
|
||||
from book_list.router import back, home, show_note
|
||||
from book_list.top_bar import add_button, create_top_bar
|
||||
from book_list.ui import set_panel_handler
|
||||
@ -179,7 +181,7 @@ def init_display_note(container_id):
|
||||
ajax(url, on_notes_fetched.bind(container_id), bypass_cache=False).send()
|
||||
|
||||
|
||||
def save(container_id):
|
||||
def save(container_id, book_id):
|
||||
c = document.getElementById(container_id)
|
||||
if not c:
|
||||
return
|
||||
@ -201,6 +203,15 @@ def save(container_id):
|
||||
q.html = xhr.responseText
|
||||
current_note_markup = q
|
||||
destroy_editor(c)
|
||||
if book_id:
|
||||
mi = book_metadata(book_id)
|
||||
if mi:
|
||||
mi.items_with_notes = mi.items_with_notes or {}
|
||||
mi.items_with_notes[q.field] = mi.items_with_notes[q.field] or {}
|
||||
if q.html:
|
||||
mi.items_with_notes[q.field][q.item] = int(q.item_id)
|
||||
else:
|
||||
v'delete mi.items_with_notes[q.field][q.item]'
|
||||
close_action()
|
||||
|
||||
def on_got_html(html, extra_data):
|
||||
@ -230,9 +241,11 @@ def init_edit(container_id):
|
||||
|
||||
|
||||
def create_editor(container, html):
|
||||
book_id = book_whose_metadata_is_being_edited()
|
||||
book_whose_metadata_is_being_edited(None)
|
||||
bar_container = document.getElementById(current_container_id)
|
||||
if bar_container:
|
||||
add_button(bar_container, 'check', action=save.bind(None, bar_container.id), tooltip=_('Save the changes'))
|
||||
add_button(bar_container, 'check', action=save.bind(None, bar_container.id, book_id), tooltip=_('Save the changes'))
|
||||
c = container.appendChild(E.div(style='flex-grow:10'))
|
||||
editor = create_comments_editor(c, {'insert_image_files': True})
|
||||
set_comments_html(c, html)
|
||||
|
Loading…
x
Reference in New Issue
Block a user