Content server: Fix Esc ky not working in several views. Fixes #1849958 [[Enhancement] Go back by clicking Esc on server](https://bugs.launchpad.net/calibre/+bug/1849958)

This commit is contained in:
Kovid Goyal 2020-08-18 13:03:13 +05:30
parent 12e64d6e8b
commit ff67af8312
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 22 additions and 6 deletions

View File

@ -16,7 +16,7 @@ from file_uploads import (
) )
from session import get_interface_data from session import get_interface_data
from utils import safe_set_inner_html from utils import safe_set_inner_html
from widgets import create_button from widgets import create_button, enable_escape_key
state = { state = {
'in_progress': False, 'in_progress': False,
@ -175,6 +175,7 @@ def add_books_panel(container_id):
state.in_progress = True state.in_progress = True
state.container_id = container_id state.container_id = container_id
state.fake_send = False state.fake_send = False
enable_escape_key(container, on_close)
return upload_files_widget(container, files_chosen) return upload_files_widget(container, files_chosen)

View File

@ -15,7 +15,7 @@ from book_list.ui import set_panel_handler
from dom import add_extra_css, build_rule, clear from dom import add_extra_css, build_rule, clear
from modals import error_dialog from modals import error_dialog
from utils import conditional_timeout, human_readable, parse_url_params from utils import conditional_timeout, human_readable, parse_url_params
from widgets import create_button from widgets import create_button, enable_escape_key
CLASS_NAME = 'convert-book-panel' CLASS_NAME = 'convert-book-panel'
current_state = 'initializing' current_state = 'initializing'
@ -243,6 +243,7 @@ def create_configuring_markup():
conversion_data.configuring_group_title = group_title conversion_data.configuring_group_title = group_title
current_state = 'configure-group' current_state = 'configure-group'
apply_state_to_markup() apply_state_to_markup()
document.getElementById(overall_container_id).focus()
def is_group_configurable(name): def is_group_configurable(name):
if entry_points[name]: if entry_points[name]:
@ -475,6 +476,7 @@ def init(container_id):
conditional_timeout(container_id, 5, check_for_data_loaded) conditional_timeout(container_id, 5, check_for_data_loaded)
q = parse_url_params() q = parse_url_params()
fetch_conversion_data(q.book_id) fetch_conversion_data(q.book_id)
enable_escape_key(container, on_close.bind(None, container_id))
set_panel_handler('convert_book', init) set_panel_handler('convert_book', init)

View File

@ -13,7 +13,7 @@ from book_list.views import DEFAULT_MODE, get_view_mode, setup_view_mode
from dom import clear, ensure_id from dom import clear, ensure_id
from modals import create_custom_dialog, error_dialog from modals import create_custom_dialog, error_dialog
from utils import conditional_timeout, safe_set_inner_html from utils import conditional_timeout, safe_set_inner_html
from widgets import create_button from widgets import create_button, enable_escape_key
CLASS_NAME = 'local-books-list' CLASS_NAME = 'local-books-list'
@ -221,7 +221,8 @@ def show_recent():
def init(container_id): def init(container_id):
container = document.getElementById(container_id) container = document.getElementById(container_id)
create_top_bar(container, title=_('Downloaded books'), action=home, icon='home') on_close = home
create_top_bar(container, title=_('Downloaded books'), action=on_close, icon='home')
add_button(container, 'trash', confirm_delete_all, _('Delete all downloaded books')) add_button(container, 'trash', confirm_delete_all, _('Delete all downloaded books'))
# book list # book list
recent = E.div(class_=CLASS_NAME) recent = E.div(class_=CLASS_NAME)
@ -232,6 +233,7 @@ def init(container_id):
_('Loading downloaded books from local storage, please wait...') _('Loading downloaded books from local storage, please wait...')
)) ))
conditional_timeout(recent_container_id, 5, show_recent) conditional_timeout(recent_container_id, 5, show_recent)
enable_escape_key(container, on_close)

View File

@ -40,7 +40,7 @@ from dom import add_extra_css, build_rule, clear, ensure_id, set_css
from modals import error_dialog from modals import error_dialog
from session import get_interface_data from session import get_interface_data
from utils import conditional_timeout, parse_url_params, safe_set_inner_html from utils import conditional_timeout, parse_url_params, safe_set_inner_html
from widgets import create_button, create_spinner from widgets import create_button, create_spinner, enable_escape_key
CLASS_NAME = 'book-list-container' CLASS_NAME = 'book-list-container'
ITEM_CLASS_NAME = 'book-list-item' ITEM_CLASS_NAME = 'book-list-item'
@ -377,6 +377,7 @@ def create_sort_panel(container_id):
items.push(create_item(name, subtitle=subtitle, icon=icon_name, action=action)) items.push(create_item(name, subtitle=subtitle, icon=icon_name, action=action))
container.appendChild(E.div()) container.appendChild(E.div())
create_item_list(container.lastChild, items, _('Change how the list of books is sorted')) create_item_list(container.lastChild, items, _('Change how the list of books is sorted'))
enable_escape_key(container, close_action)
# }}} # }}}
# Searching {{{ # Searching {{{
@ -468,7 +469,7 @@ def create_more_actions_panel(container_id):
)) ))
container.appendChild(E.div()) container.appendChild(E.div())
create_item_list(container.lastChild, items) create_item_list(container.lastChild, items)
enable_escape_key(container, back)
# }}} # }}}
# Adding books {{{ # Adding books {{{

View File

@ -216,3 +216,13 @@ add_extra_css(def():
ans += Breadcrumbs.STYLE_RULES + '\n' ans += Breadcrumbs.STYLE_RULES + '\n'
return ans return ans
) )
def enable_escape_key(container, action):
container.setAttribute('tabindex', '0')
container.addEventListener('keydown', def(ev):
if ev.key is 'Escape':
ev.stopPropagation(), ev.preventDefault()
action()
, {'passive': False})
container.focus()