def top_heading( writer: HTMLWriter, request: Request, title: str, breadcrumb: Breadcrumb, page_menu: Optional[PageMenu] = None, page_state: Optional[PageState] = None, *, browser_reload: float, ) -> None: writer.open_div(id_="top_heading") writer.open_div(class_="titlebar") # HTML() is needed here to prevent a double escape when we do self._escape_attribute # here and self.a() escapes the content (with permissive escaping) again. We don't want # to handle "title" permissive. html_title = HTML(escaping.escape_attribute(title)) writer.a( html_title, class_="title", href="#", onfocus="if (this.blur) this.blur();", onclick="this.innerHTML='%s'; document.location.reload();" % _("Reloading..."), ) if breadcrumb: BreadcrumbRenderer().show(breadcrumb) if page_state is None: page_state = _make_default_page_state( writer, request, browser_reload=browser_reload, ) if page_state: PageStateRenderer().show(page_state) writer.close_div() # titlebar if page_menu: PageMenuRenderer().show( page_menu, hide_suggestions=not user.get_tree_state("suggestions", "all", True), ) writer.close_div() # top_heading if page_menu: PageMenuPopupsRenderer().show(page_menu) if active_config.debug: _dump_get_vars( writer, request, )
def header( title: str, isopen: bool = True, table_id: str = "", narrow: bool = False, css: Optional[str] = None, show_table_head: bool = True, show_more_toggle: bool = False, show_more_mode: bool = False, help_text: Union[str, HTML, None] = None, ) -> None: global g_header_open, g_section_open if g_header_open: end() id_ = base64.b64encode(title.encode()).decode() treename = html.form_name or "nform" isopen = user.get_tree_state(treename, id_, isopen) container_id = foldable_container_id(treename, id_) class_ = ["nform"] if narrow: class_.append("narrow") if css: class_.append(css) class_.append("open" if isopen else "closed") if user.get_show_more_setting("foldable_%s" % id_) or show_more_mode: class_.append("more") html.open_table( id_=table_id if table_id else None, class_=class_, ) if show_table_head: _table_head( treename=treename, id_=id_, isopen=isopen, title=title, show_more_toggle=show_more_toggle, help_text=help_text, ) html.open_tbody(id_=container_id, class_=["open" if isopen else "closed"]) html.tr(HTMLWriter.render_td("", colspan=2)) g_header_open = True g_section_open = False
def _show_dropdown_area(self, dropdown: PageMenuDropdown) -> None: id_ = "menu_%s" % dropdown.name show_more = user.get_tree_state("more_buttons", id_, isopen=False) or user.show_more_mode html.open_div(class_=["menu", ("more" if show_more else "less")], id_=id_) if dropdown.any_show_more_entries: html.open_div(class_=["more_container"]) html.more_button(id_, dom_levels_up=2) html.close_div() for topic in dropdown.topics: if not topic.entries: continue # Do not display empty topics self._show_topic(topic) html.close_div()
def grouped_row_title(index, group_spec, num_rows, trclass, num_cells): is_open = user.get_tree_state("grouped_rows", index, False) html.open_tr(class_=[ "data", "grouped_row_header", "closed" if not is_open else "", "%s0" % trclass ]) html.open_td( colspan=num_cells, onclick="cmk.views.toggle_grouped_rows('grouped_rows', '%s', this, %d)" % (index, num_rows), ) html.img( theme.url("images/tree_closed.svg"), align="absbottom", class_=["treeangle", "nform", "open" if is_open else "closed"], ) html.write_text("%s (%d)" % (group_spec["title"], num_rows)) html.close_td() html.close_tr() return not is_open
def foldable_container( *, treename: str, id_: str, isopen: bool, title: HTMLContent, indent: Union[str, None, bool] = True, icon: Optional[str] = None, fetch_url: Optional[str] = None, title_url: Optional[str] = None, title_target: Optional[str] = None, padding: int = 15, save_state: bool = True, ) -> Iterator[bool]: isopen = user.get_tree_state(treename, id_, isopen) onclick = foldable_container_onclick(treename, id_, fetch_url, save_state) img_id = foldable_container_img_id(treename, id_) container_id = foldable_container_id(treename, id_) html.open_div(class_=["foldable", "open" if isopen else "closed"]) html.open_div(class_="foldable_header", onclick=None if title_url else onclick) if isinstance(title, HTML): # custom HTML code html.write_text(title) else: html.open_b(class_=["treeangle", "title"]) if title_url: html.a(title, href=title_url, target=title_target) else: html.write_text(title) html.close_b() if icon: html.img( id_=img_id, # Although foldable_sidebar is given via the argument icon it should not be displayed as big as an icon. class_=(["treeangle", "title"] + (["icon"] if icon != "foldable_sidebar" else []) + ["open" if isopen else "closed"]), src=theme.detect_icon_path(icon, "icon_"), onclick=onclick if title_url else None, ) else: html.img( id_=img_id, class_=["treeangle", "open" if isopen else "closed"], src=theme.url("images/tree_closed.svg"), onclick=onclick if title_url else None, ) html.close_div() indent_style = "padding-left: %dpx; " % (padding if indent else 0) if indent == "form": html.close_td() html.close_tr() html.close_table() indent_style += "margin: 0; " html.open_ul(id_=container_id, class_=["treeangle", "open" if isopen else "closed"], style=indent_style) yield isopen html.close_ul() html.close_div()