From d800f68b62360f64ab0416f8dad257c2d3b0d47c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 13 Feb 2016 17:20:11 +0530 Subject: [PATCH] Button to refresh random book --- src/pyj/book_list/book_details.pyj | 4 ++++ src/pyj/book_list/top_bar.pyj | 7 +++++++ src/pyj/book_list/ui.pyj | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/pyj/book_list/book_details.pyj b/src/pyj/book_list/book_details.pyj index 8bb8f9f2ac..b716ac23da 100644 --- a/src/pyj/book_list/book_details.pyj +++ b/src/pyj/book_list/book_details.pyj @@ -48,6 +48,10 @@ class BookDetailsPanel: self.render_book(book_id) else: 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): self.container.appendChild(E.div( diff --git a/src/pyj/book_list/top_bar.pyj b/src/pyj/book_list/top_bar.pyj index f139e2a85c..4f2bbda715 100644 --- a/src/pyj/book_list/top_bar.pyj +++ b/src/pyj/book_list/top_bar.pyj @@ -107,6 +107,13 @@ class TopBar: if action is not None: 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): self.set_left(**left) for bar in self.bar, self.dummy_bar: diff --git a/src/pyj/book_list/ui.pyj b/src/pyj/book_list/ui.pyj index 5e8806e479..07116228e6 100644 --- a/src/pyj/book_list/ui.pyj +++ b/src/pyj/book_list/ui.pyj @@ -104,7 +104,8 @@ class UI: 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['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): 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): 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): pass