Exemple #1
0
    def layout(item):
        """ Layout for popup link """

        if not item.authorized:
            return None

        if current.deployment_settings.get_ui_use_button_icons():
            from s3.s3widgets import ICON
            label = (ICON("add"), item.label)
        else:
            label = item.label

        popup_link = A(
            label,
            _href=item.url(format="popup"),
            _class="s3_add_resource_link",
            _id="%s_add" % item.function,
            _target="top",
            _title=item.opts.info,
        )

        tooltip = item.opts.tooltip
        if tooltip is not None:
            ttip = DIV(_class="tooltip",
                       _title="%s|%s" % (item.opts.title, tooltip))
        else:
            ttip = ""

        return TAG[""](popup_link, ttip)
Exemple #2
0
    def layout(item):
        """ Layout Method (Item Renderer) """

        # Manage flags: hide any disabled/unauthorized items
        if not item.authorized and not item.opts.always_display:
            item.enabled = False
            item.visible = False
        elif item.enabled is None or item.enabled:
            item.enabled = True
            item.visible = True

        if item.enabled and item.visible:
            items = item.render_components()

            if item.parent is None:
                # The menu itself

                number_of_links = 0

                components = []
                append = components.append
                for submenu in items:
                    append(submenu)
                    number_of_links += len(submenu.elements("a"))

                # Hide the entire menu if it doesn't contain any links
                if not number_of_links:
                    return None

                title = H3(item.label) if item.label else ""
                menu = DIV(
                    title,
                    DIV(
                        TAG[""](components),
                        _class="icon-bar four-up",
                    ),
                    _id=item.attr._id,
                    _class=item.attr._class,
                )

                return menu

            else:
                # A menu item
                _class = item.attr._class
                if _class:
                    _class = "%s item" % _class
                else:
                    _class = "item"
                _id = item.attr._id

                icon = item.opts.icon
                if icon:
                    return A(
                        LABEL(ICON(icon), item.label),
                        _class=_class,
                        _href=item.url(),
                        _id=_id,
                    )
                else:
                    return A(
                        LABEL(item.label),
                        _class=_class,
                        _href=item.url(),
                        _id=_id,
                    )
        else:
            return None
Exemple #3
0
    def layout(item):
        """ Layout Method (Item Renderer) """

        # Manage flags: hide any disabled/unauthorized items
        if not item.authorized and not item.opts.always_display:
            item.enabled = False
            item.visible = False
        elif item.enabled is None or item.enabled:
            item.enabled = True
            item.visible = True

        if item.enabled and item.visible:

            items = item.render_components()
            if item.parent is not None:

                if item.attr._class:
                    classes = item.attr._class.split(" ")
                else:
                    classes = []

                if item.parent.parent is None:
                    # Item at the top-level?
                    toplevel = True
                    if item.opts.right:
                        classes.append("menu-right")
                else:
                    toplevel = False

                if item.components:
                    classes.append("has-dropdown not-click")
                    _class = " ".join(classes)
                    # Menu item with Dropdown
                    if item.get_first(enabled=True):
                        _href = item.url()
                        return LI(
                            A(item.label, _href=_href, _id=item.attr._id),
                            UL(items, _class="dropdown"),
                            _class=_class,
                        )
                else:
                    # Menu item without Drop-Down
                    if toplevel:
                        item_url = item.url()
                        if item_url == URL(c="default", f="index"):
                            classes.append("menu-home")
                        if item.selected:
                            classes.append("active")
                        _class = " ".join(classes)
                        icon = item.opts.icon
                        if icon:
                            label = LABEL(ICON(icon), item.label)
                        else:
                            label = item.label
                        return LI(
                            A(
                                label,
                                _href=item_url,
                                _id=item.attr._id,
                                _target=item.attr._target,
                            ),
                            _class=_class,
                        )
                    else:
                        # Submenu item
                        if isinstance(item.label, dict):
                            if "id" in item.label:
                                return S3MainMenuDefaultLayout.checkbox_item(
                                    item)
                            elif "name" in item.label:
                                label = item.label["name"]
                            else:
                                return None
                        else:
                            label = item.label
                        link = A(
                            label,
                            _href=item.url(),
                            _id=item.attr._id,
                            _target=item.attr._target,
                        )
                        _class = " ".join(classes)
                        return LI(link, _class=_class)
            else:
                # The main menu itself
                T = current.T
                settings = current.deployment_settings

                if item.opts.title_area:
                    # Custom override
                    title_area = item.opts.title_area
                else:
                    # Standard: render a menu logo
                    logo = settings.get_ui_menu_logo()
                    if logo is None:
                        # Render an icon
                        logo = SPAN(
                            settings.get_system_name_short(),
                            _class="logo",
                        )
                    elif isinstance(logo, str):
                        # Assume image-URL
                        logo = IMG(
                            _src=logo,
                            _class="logo",
                            _alt=settings.get_system_name_short(),
                        )
                    #else:
                    # use as-is (assume HTML or T())
                    title_area = A(
                        logo,
                        _href=URL(c="default", f="index"),
                        _title=T("Homepage"),
                    )

                # Arrange items left/right
                right = []
                left = []
                for item in items:
                    if "menu-right" in item["_class"]:
                        item.remove_class("menu-right")
                        right.append(item)
                    else:
                        left.append(item)
                right.reverse()

                # Reverse if right-to-left
                if current.response.s3.rtl:
                    right, left = left, right

                # Build top-bar HTML
                return NAV(
                    UL(
                        LI(
                            title_area,
                            _class="name",
                        ),
                        LI(
                            A(SPAN(T("Menu"))),
                            _class="toggle-topbar menu-icon",
                        ),
                        _class="title-area",
                    ),
                    SECTION(
                        UL(
                            right,
                            _class="right",
                        ),
                        UL(
                            left,
                            _class="left",
                        ),
                        _class="top-bar-section",
                    ),
                    _class="top-bar",
                    data={"topbar": " "},
                )
        else:
            return None