Content server: Start work on adding books

This commit is contained in:
Kovid Goyal 2018-01-21 14:00:44 +05:30
parent ae112c1009
commit 537fe84aac
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 63 additions and 0 deletions

View File

@ -35,6 +35,7 @@ from book_list.search import (
from book_list.top_bar import add_button, create_top_bar from book_list.top_bar import add_button, create_top_bar
from book_list.ui import query_as_href, set_panel_handler, show_panel from book_list.ui import query_as_href, set_panel_handler, show_panel
from dom import add_extra_css, build_rule, clear, ensure_id, set_css from dom import add_extra_css, build_rule, clear, ensure_id, set_css
from file_uploads import upload_files_widget
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
@ -450,6 +451,13 @@ def create_more_actions_panel(container_id):
# }}} # }}}
# Adding books {{{
def implement_me():
upload_files_widget()
# }}}
set_panel_handler('book_list', init) set_panel_handler('book_list', init)
set_panel_handler('book_list^sort', create_sort_panel) set_panel_handler('book_list^sort', create_sort_panel)
set_panel_handler('book_list^vl', create_vl_panel) set_panel_handler('book_list^vl', create_vl_panel)

55
src/pyj/file_uploads.pyj Normal file
View File

@ -0,0 +1,55 @@
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
from __python__ import bound_methods, hash_literals
from elementmaker import E
from gettext import gettext as _
from utils import safe_set_inner_html
def upload_files_widget(container, proceed, msg):
container_id = container.id
def files_selected():
files = this.files
container = document.getElementById(container_id)
container.removeChild(container.lastChild)
if callable(proceed):
proceed(container, files)
msg = msg or _('Upload books by <a>selecting the book files</a> or drag and drop of the files here')
c = E.div(E.span(), E.input(type='file', multiple=True, style='display:none', onchange=files_selected))
c.style.minHeight = '40vh'
c.style.borderBottom = 'solid 1px currentColor'
safe_set_inner_html(c.firstChild, msg)
a = c.getElementsByTagName('a')[0]
a.setAttribute('href', 'javascript: void(0)')
a.classList.add('simple-link')
a.style.color = 'blue'
a.addEventListener('click', def():
document.getElementById(container_id).querySelector('input[type=file]').click()
, False)
container.appendChild(c)
def stop(e):
e.stopPropagation(), e.preventDefault()
def drop(e):
stop(e)
dt = e.dataTransfer
files_selected.call(dt)
c.addEventListener('dragenter', stop, False)
c.addEventListener('dragover', stop, False)
c.addEventListener('drop', drop, False)
return c
def start_send(container, files):
pass
def develop(container):
upload_files_widget(container)