コード例 #1
0
ファイル: _frm.py プロジェクト: pytsite/plugin-auth_admin
    def _on_setup_widgets(self):
        e_type = self.attr('e_type')
        eids = self.attr('eids', [])
        ol = htmler.Ol()
        for eid in eids:
            if e_type == 'role':
                ol.append_child(htmler.Li(auth.get_role(uid=eid).name))
            elif e_type == 'user':
                ol.append_child(htmler.Li(auth.get_user(uid=eid).login))

        self.add_widget(
            widget.static.Text(
                uid='confirmation_text',
                text=lang.t('auth_admin@delete_{}_confirmation'.format(
                    self.attr('e_type'))),
            ))

        self.add_widget(widget.static.HTML(
            uid='uids_text',
            em=ol,
        ))

        self.add_widget(
            widget.button.Link(uid='action_cancel',
                               weight=100,
                               form_area='footer',
                               href=self.referer or self.redirect
                               or router.base_url(),
                               value=lang.t('auth_admin@cancel'),
                               icon='fa fas fa-ban'))

        self.submit_button.color = 'btn btn-danger'
        self.submit_button.icon = 'fa fas fa-trash'
        self.submit_button.value = lang.t('auth_admin@delete')
コード例 #2
0
    def _render_sidebar(sidebar: admin.SideBar) -> htmler.Aside:
        """Render admin's sidebar
        """
        aside = htmler.Aside(css='main-sidebar')
        sidebar_section_em = htmler.Section(css='sidebar')
        aside.append_child(sidebar_section_em)

        root_menu_ul = htmler.Ul(css='sidebar-menu')
        sidebar_section_em.append_child(root_menu_ul)

        sections, menus = sidebar.items

        # Do actual rendering
        for section in sections:
            li = htmler.Li(lang.t(section['title']),
                           css='header',
                           data_section_weight=section['weight'])
            root_menu_ul.append_child(li)

            # Building top level menu item
            for menu in menus[section['sid']]:
                # Link
                a = htmler.A(
                    href=router.url(menu['path'], lang=lang.get_current()))

                # Icon
                if menu['icon']:
                    a.append_child(htmler.I(css=menu['icon']))

                # Title
                a.append_child(htmler.Span(lang.t(menu['title'])))

                # Label
                if menu['label']:
                    label_class = 'label pull-right label-' + menu[
                        'label_class']
                    a.append_child(
                        htmler.Span(lang.t(menu['label']), css=label_class))

                # List element
                li = htmler.Li(data_menu_weight=menu['weight'])

                # Active state
                if menu['active']:
                    li.set_attr('css', 'active')

                li.append_child(a)
                root_menu_ul.append_child(li)

        return aside
コード例 #3
0
    def _on_setup_widgets(self):
        """Hook.
        """
        from ._api import dispense_entity

        # List of items to process
        ol = htmler.Ol()
        for eid in self.attr('eids', self.attr('ids', [])):
            entity = dispense_entity(self.attr('model'), eid)
            self.add_widget(
                widget.input.Hidden(uid='eids-' + eid, name='eids', value=eid))
            ol.append_child(
                htmler.Li(entity.odm_ui_mass_action_entity_description()))
        self.add_widget(widget.static.HTML(uid='eids-text', em=ol))

        # Submit button
        submit_button = self.get_widget(
            'action_submit')  # type: widget.button.Submit
        submit_button.value = lang.t('odm_ui@continue')
        submit_button.icon = 'angle-double-right'

        # Cancel button
        self.add_widget(
            widget.button.Link(uid='action_cancel',
                               weight=100,
                               value=lang.t('odm_ui@cancel'),
                               href=self.referer or self.redirect
                               or router.base_url(),
                               icon='fa fas fa-ban',
                               form_area='footer'))
コード例 #4
0
    def _render_item(self, entity: _model.Menu) -> Optional[htmler.Li]:
        if not entity.enabled:
            return

        root = htmler.Li(css='nav-item {}'.format('active' if self._is_item_active(entity) else ''))
        a = root.append_child(htmler.A(entity.title, href=self._item_url(entity), css='nav-link'))

        if entity.new_window:
            a.set_attr('target', '_blank')

        return root
コード例 #5
0
    def _render_dropdown(self, entity: _model.Menu) -> Optional[htmler.Li]:
        if not entity.enabled:
            return

        # Dropdown's root
        root = htmler.Li(css='nav-item dropdown')

        # Toggler
        root.append_child(htmler.A(entity.title, id=entity.ref, href='#', css='nav-link dropdown-toggle', role='button',
                                   data_toggle='dropdown', aria_haspopup='true', aria_expanded='false'))

        # Dropdown
        dropdown = root.append_child(htmler.Div(css='dropdown-menu', aria_labelledby=entity.ref))
        for e in entity.children:  # type: _model.Menu
            if e.enabled:
                a_css = 'dropdown-item {}'.format('active' if self._is_item_active(e) else '')
                a = dropdown.append_child(htmler.A(e.title, href=self._item_url(e), css=a_css))

                if e.new_window:
                    a.set_attr('target', '_blank')

        return root