Content server: Implement search

This commit is contained in:
Kovid Goyal 2015-12-04 18:42:02 +05:30
parent 2adf2d324e
commit faea3a7564
2 changed files with 32 additions and 2 deletions

View File

@ -2,6 +2,9 @@
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net> # License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
from elementmaker import E from elementmaker import E
from gettext import gettext as _
from widgets import create_button, BUTTON_VPADDING
from book_list.globals import get_boss
sp_counter = 0 sp_counter = 0
@ -15,10 +18,31 @@ class SearchPanel:
style = '' style = ''
div = E.div( div = E.div(
id=self.container_id, style='display:none', id=self.container_id, style='display:none',
E.style(style, type='text/css') E.style(style, type='text/css'),
E.div(style="text-align:center; padding:1ex 1em; border-bottom: solid 1px currentColor; margin-bottom: 0.5ex"), # search input container
E.div(
E.div(),
E.div()
)
) )
book_list_container.appendChild(div) book_list_container.appendChild(div)
# Build search input
search_container = div.firstChild.nextSibling
search_container.appendChild(E.div(style="display: flex; width: 100%;",
E.input(
type='text', autocomplete='on', autosave='search', inputmode='latin', name='search-books',
title=_('Search for books'), placeholder=_('Enter the search query'), spellcheck='false',
style=str.format("flex-grow: 10; padding: {} 0.5em; margin-right: 0.5em", BUTTON_VPADDING)
),
create_button(_('Search'), icon='search', action=self.execute_search.bind(self), tooltip=_('Do the search'))
))
search_container.firstChild.firstChild.addEventListener('keypress', def(event):
if event.keyCode == 13:
self.execute_search()
event.preventDefault(), event.stopPropagation()
)
@property @property
def container(self): def container(self):
return document.getElementById(self.container_id) return document.getElementById(self.container_id)
@ -30,3 +54,7 @@ class SearchPanel:
@is_visible.setter @is_visible.setter
def is_visible(self, val): def is_visible(self, val):
self.container.style.display = 'block' if val else 'none' self.container.style.display = 'block' if val else 'none'
def execute_search(self):
text = self.container.querySelector('input[name="search-books"]').value or ''
get_boss().ui.books_view.change_search(text)

View File

@ -6,6 +6,8 @@ from elementmaker import E
from book_list.theme import get_color from book_list.theme import get_color
BUTTON_VPADDING = '0.5ex'
def create_button(text, icon=None, action=None, tooltip=None): def create_button(text, icon=None, action=None, tooltip=None):
cls = '' cls = ''
if icon: if icon:
@ -19,7 +21,7 @@ def create_button(text, icon=None, action=None, tooltip=None):
create_button.style = build_rule('button.calibre-push-button', create_button.style = build_rule('button.calibre-push-button',
border_radius='1em', background_clip='padding-box', background_color=get_color('button-start'), border_radius='1em', background_clip='padding-box', background_color=get_color('button-start'),
background_image=str.format('linear-gradient(to bottom, {}, {})', get_color('button-start'), get_color('button-end')), background_image=str.format('linear-gradient(to bottom, {}, {})', get_color('button-start'), get_color('button-end')),
padding='1ex 1em', color=get_color('button-text'), cursor='pointer', font_size='inherit' padding=BUTTON_VPADDING + ' 1em', color=get_color('button-text'), cursor='pointer', font_size='inherit'
) )
create_button.style += build_rule('button.calibre-push-button:hover', transform='scale(1.2)') create_button.style += build_rule('button.calibre-push-button:hover', transform='scale(1.2)')
create_button.style += build_rule('button.calibre-push-button:active', transform='scale(2)') create_button.style += build_rule('button.calibre-push-button:active', transform='scale(2)')