Button to refresh random book

This commit is contained in:
Kovid Goyal 2016-02-13 17:20:11 +05:30
parent c1b41b14fc
commit d800f68b62
3 changed files with 16 additions and 1 deletions

View File

@ -48,6 +48,10 @@ class BookDetailsPanel:
self.render_book(book_id) self.render_book(book_id)
else: else:
self.fetch_metadata(book_id) self.fetch_metadata(book_id)
get_boss().ui.set_button_visibility('random', not book_id or book_id == '0')
def show_random(self):
self.fetch_metadata('0')
def no_book(self, book_id): def no_book(self, book_id):
self.container.appendChild(E.div( self.container.appendChild(E.div(

View File

@ -107,6 +107,13 @@ class TopBar:
if action is not None: if action is not None:
right.lastChild.addEventListener('click', def(event): event.preventDefault(), action();) right.lastChild.addEventListener('click', def(event): event.preventDefault(), action();)
def set_button_visibility(self, icon_name, visible):
for bar in self.bar, self.dummy_bar:
right = bar.firstChild.nextSibling
elem = right.querySelector('i.fa.fa-fw.fa-' + icon_name)
if elem:
elem.parentNode.style.display = 'inline' if visible else 'none'
def apply_state(self, left, buttons): def apply_state(self, left, buttons):
self.set_left(**left) self.set_left(**left)
for bar in self.bar, self.dummy_bar: for bar in self.bar, self.dummy_bar:

View File

@ -104,7 +104,8 @@ class UI:
bss.add_button(icon_name='cogs', tooltip=_('Configure Tag Browser'), action=show_panel_action('booklist-config-tb')) bss.add_button(icon_name='cogs', tooltip=_('Configure Tag Browser'), action=show_panel_action('booklist-config-tb'))
self.panel_map['booklist-search'] = UIState(bss, main_panel=self.search_panel) self.panel_map['booklist-search'] = UIState(bss, main_panel=self.search_panel)
self.panel_map['book-details'] = UIState(ClosePanelBar(_('Book Details')), main_panel=self.book_details_panel) self.panel_map['book-details'] = bd = UIState(ClosePanelBar(_('Book Details')), main_panel=self.book_details_panel)
bd.add_button(icon_name='random', tooltip=_('Pick another random book'), action=self.book_details_panel.show_random.bind(self.book_details_panel))
def create_prefences_panel(self, title, close_callback=None, panel_data=None): def create_prefences_panel(self, title, close_callback=None, panel_data=None):
ans = UIState(ClosePanelBar(title), close_callback=close_callback, main_panel=self.prefs_panel, panel_data=panel_data) ans = UIState(ClosePanelBar(title), close_callback=close_callback, main_panel=self.prefs_panel, panel_data=panel_data)
@ -114,6 +115,9 @@ class UI:
def set_title(self, text): def set_title(self, text):
self.top_bar.set_title(text) self.top_bar.set_title(text)
def set_button_visibility(self, icon_name, visible):
self.top_bar.set_button_visibility(icon_name, visible)
def on_resize(self): def on_resize(self):
pass pass