diff --git a/src/pyj/book_list/views.pyj b/src/pyj/book_list/views.pyj index 1c7581d65b..e74decb853 100644 --- a/src/pyj/book_list/views.pyj +++ b/src/pyj/book_list/views.pyj @@ -35,6 +35,7 @@ from book_list.search import ( 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 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 session import get_interface_data 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^sort', create_sort_panel) set_panel_handler('book_list^vl', create_vl_panel) diff --git a/src/pyj/file_uploads.pyj b/src/pyj/file_uploads.pyj new file mode 100644 index 0000000000..56f3a189a5 --- /dev/null +++ b/src/pyj/file_uploads.pyj @@ -0,0 +1,55 @@ +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2018, Kovid Goyal +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 selecting the book files 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)