mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Work on editor for notes in content server
This commit is contained in:
parent
79a88fa17c
commit
2dafa01321
@ -96,9 +96,9 @@ def show_note_url(book_id, field, item_id, item_value, library_id=None, close_ac
|
|||||||
return ans + encode_query(q, '#')
|
return ans + encode_query(q, '#')
|
||||||
|
|
||||||
|
|
||||||
def show_note(book_id, field, item_id, item_value, replace=False, library_id=None, close_action='back'):
|
def show_note(book_id, field, item_id, item_value, replace=False, library_id=None, close_action='back', panel='show_note'):
|
||||||
lid = library_id or current_library_id()
|
lid = library_id or current_library_id()
|
||||||
q = {'book_id':book_id, 'field': field, 'item':item_value, 'item_id': item_id, 'panel': 'show_note', 'close_action': close_action}
|
q = {'book_id':book_id, 'field': field, 'item':item_value, 'item_id': item_id, 'panel': panel, 'close_action': close_action}
|
||||||
if lid:
|
if lid:
|
||||||
q.library_id = lid
|
q.library_id = lid
|
||||||
push_state(q, replace=replace)
|
push_state(q, replace=replace)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# License: GPL v3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2023, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
from __python__ import bound_methods, hash_literals
|
from __python__ import bound_methods, hash_literals
|
||||||
|
|
||||||
|
from elementmaker import E
|
||||||
from ajax import ajax
|
from ajax import ajax
|
||||||
from book_list.details_list import sandbox_css
|
from book_list.details_list import sandbox_css
|
||||||
from book_list.router import back, home
|
from book_list.router import back, home
|
||||||
@ -18,16 +19,27 @@ def make_iframe(html):
|
|||||||
return iframe
|
return iframe
|
||||||
|
|
||||||
|
|
||||||
|
current_note_markup = None
|
||||||
|
|
||||||
|
|
||||||
def on_notes_fetched(load_type, xhr, ev):
|
def on_notes_fetched(load_type, xhr, ev):
|
||||||
|
nonlocal current_note_markup
|
||||||
|
q = parse_url_params()
|
||||||
if load_type is 'load':
|
if load_type is 'load':
|
||||||
html = xhr.responseText
|
html = xhr.responseText
|
||||||
|
q.html = xhr.responseText
|
||||||
|
current_note_markup = q
|
||||||
else:
|
else:
|
||||||
html = xhr.error_html
|
html = xhr.error_html
|
||||||
iframe = make_iframe(html)
|
iframe = make_iframe(html)
|
||||||
container = document.getElementById(this)
|
container = document.getElementById(this)
|
||||||
old = container.getElementsByTagName('iframe')[0]
|
old = container.querySelector('div.loading')
|
||||||
old.parentNode.appendChild(iframe)
|
p = old.parentNode
|
||||||
old.parentNode.removeChild(old)
|
p.removeChild(old)
|
||||||
|
if q.panel is 'show_note':
|
||||||
|
p.appendChild(iframe)
|
||||||
|
elif q.panel is 'edit_note':
|
||||||
|
create_editor(container, current_note_markup.html)
|
||||||
|
|
||||||
|
|
||||||
def init(container_id):
|
def init(container_id):
|
||||||
@ -38,14 +50,44 @@ def init(container_id):
|
|||||||
if ca is 'home':
|
if ca is 'home':
|
||||||
close_action, close_icon = def(): home();, 'home'
|
close_action, close_icon = def(): home();, 'home'
|
||||||
create_top_bar(container, title=q.item, action=close_action, icon=close_icon)
|
create_top_bar(container, title=q.item, action=close_action, icon=close_icon)
|
||||||
url = 'get-note/' + encodeURIComponent(q.field) + '/' + encodeURIComponent(q.item_id)
|
|
||||||
if q.library_id:
|
|
||||||
url += '/' + encodeURIComponent(q.library_id)
|
|
||||||
container.style.height = '100vh'
|
container.style.height = '100vh'
|
||||||
container.style.display = 'flex'
|
container.style.display = 'flex'
|
||||||
container.style.flexDirection = 'column'
|
container.style.flexDirection = 'column'
|
||||||
container.appendChild(make_iframe(_('Loading') + '…'))
|
if current_note_markup and current_note_markup.library_id is q.library_id and current_note_markup.field is q.field and current_note_markup.item_id is q.item_id:
|
||||||
|
html = current_note_markup.html
|
||||||
|
container.appendChild(make_iframe(html))
|
||||||
|
else:
|
||||||
|
container.appendChild(E.div(_('Loading') + '…', style='margin: 0.5rem', class_='loading'))
|
||||||
|
url = 'get-note/' + encodeURIComponent(q.field) + '/' + encodeURIComponent(q.item_id)
|
||||||
|
if q.library_id:
|
||||||
|
url += '/' + encodeURIComponent(q.library_id)
|
||||||
ajax(url, on_notes_fetched.bind(container_id), bypass_cache=False).send()
|
ajax(url, on_notes_fetched.bind(container_id), bypass_cache=False).send()
|
||||||
|
|
||||||
|
|
||||||
|
def init_edit(container_id):
|
||||||
|
container = document.getElementById(container_id)
|
||||||
|
close_action, close_icon = back, 'close'
|
||||||
|
q = parse_url_params()
|
||||||
|
ca = q.close_action
|
||||||
|
if ca is 'home':
|
||||||
|
close_action, close_icon = def(): home();, 'home'
|
||||||
|
create_top_bar(container, title=_('Edit notes for:') + ' ' + q.item, action=close_action, icon=close_icon)
|
||||||
|
container.style.height = '100vh'
|
||||||
|
container.style.display = 'flex'
|
||||||
|
container.style.flexDirection = 'column'
|
||||||
|
if current_note_markup and current_note_markup.library_id is q.library_id and current_note_markup.field is q.field and current_note_markup.item_id is q.item_id:
|
||||||
|
create_editor(container, current_note_markup.html)
|
||||||
|
else:
|
||||||
|
container.appendChild(E.div(_('Loading') + '…', style='margin: 0.5rem', class_='loading'))
|
||||||
|
url = 'get-note/' + encodeURIComponent(q.field) + '/' + encodeURIComponent(q.item_id)
|
||||||
|
if q.library_id:
|
||||||
|
url += '/' + encodeURIComponent(q.library_id)
|
||||||
|
ajax(url, on_notes_fetched.bind(container_id), bypass_cache=False).send()
|
||||||
|
|
||||||
|
|
||||||
|
def create_editor(container, html):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
set_panel_handler('show_note', init)
|
set_panel_handler('show_note', init)
|
||||||
|
set_panel_handler('edit_note', init_edit)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user