ui_selector.py 5.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# -*- coding: utf-8 -*-
"""User Interface for selectors

"""
from gluon.html import URL
from gluon.storage import Storage
import plugin_dbui as dbui


fieldsModifier = dbui.FieldsModifier
formModifier = dbui.FormModifier
gridModifier = dbui.GridModifier
storeModifier = dbui.StoreModifier


16
class SelectorUi(object):
17

18 19 20
    @staticmethod
    def define(virtdb, db, T):
        """Tune the user interface for the selector.
21

22 23 24 25
        Args:
            virtdb (pyDAL.DAL): connection to the virtual database
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator
26

27 28
        """
        SelectorUi.selector(virtdb, db, T)
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    @staticmethod
    def selector(virtdb, db, T):
        """UI for the selector table

        Args:
            virtdb (pyDAL.DAL): connection to the virtual database
            db (pyDAL.DAL): database connection
            T (gluon.languages.translator): language translator

        Returns:
            gluon.storage.Storage:
                the configuration of the PanelWithUrlSelector.

        """
        #.....................................................................
        #
        # Fields
        #
        mdf = fieldsModifier("selector")

        mytype = "xcomboboxuserreset"
        text = T("select...")

        mdf.configure_field("id_categories", emptyText=text, xtype=mytype)
        mdf.configure_field("id_domains", emptyText=text, xtype=mytype)
        mdf.configure_field("id_fundings", emptyText=text, xtype=mytype)

57
        # to have an unique key use xcomboboxmaster instead of userreset
58 59
        mdf.configure_field("id_object_categories",
                            emptyText=text,
60 61 62
                            refStore="alias_object_categoriesStore",
                            userReset=True,
                            xtype="xcomboboxmaster")
63 64 65

        mdf.configure_field("id_object_code", emptyText=text, xtype=mytype)

66
        # to have an unique key use xcomboboxmaster instead of userreset
67 68
        mdf.configure_field("id_people_categories",
                            emptyText=text,
69 70 71
                            refStore="alias_people_categoriesStore",
                            userReset=True,
                            xtype="xcomboboxmaster")
72 73 74 75 76

        mdf.configure_field("id_people_code", emptyText=text, xtype=mytype)
        mdf.configure_field("id_teams", emptyText=text, xtype=mytype)
        mdf.configure_field("id_projects", emptyText=text, xtype=mytype)

77
        mdf.configure_field("query", hideLabel=True)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

        #.....................................................................
        #
        # PanelWithUrlSelector
        #    - configure it once since it is u0sed many times (lists, ...)
        #    - organise fields within an accordion layout
        #

        # map between field name and field configuration
        # keys are the field name or field label for merge fields
        mapfields = Storage()
        for cfgfield in dbui.to_fields(virtdb.selector):
            key = (cfgfield.name if cfgfield.name else cfgfield.fieldLabel)
            mapfields[key] = cfgfield

        # Organise fields within different panels
        # and replace field name by their configuration
        items = [
            {
                "title": T("Period"),
                "items": ["SelectorYear_start",
                          "SelectorYear_end"]
            }, {
                 "title": T("Metadata"),
                 "items": ["SelectorId_domains",
                           "SelectorId_teams",
                           "SelectorId_projects"]
            }, {
                "title": T("People"),
                "collapsed": True,
                "items": ["SelectorId_people_categories",
                          "SelectorId_people_code"]
            }, {
                "title": T("Object"),
                "collapsed": True,
                "items": ["SelectorId_object_categories",
                          "SelectorId_object_code"]
            }, {
                "title": T("Fundings"),
                "collapsed": True,
                "layout": "fit",
                "items": ["SelectorId_fundings"]
120 121 122 123 124
            }, {
                "title": T("Query"),
                "collapsed": False,
                "layout": "fit",
                "items": ["SelectorQuery"]
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
            }
        ]

        for panel in items:
            panelitems = panel["items"]
            for i in xrange(len(panelitems)):
                panelitems[i] = mapfields[panelitems[i]]

        # configure the accordion layout
        # several panel can be open at the same time (multi)
        layout = dict(
            multi=True,
            titleCollapse=True,
            type="accordion")

        # wrap fields within a FieldSet
        fieldset = dbui.FieldSet(
            defaults=dict(frame=True),
            items=items,
            layout=layout,
            plugins=["pFormToolTip"],
            title=T("Select"))

        # configure the PanelWithUrlSelector
        selector_panel = dbui.PanelWithUrlSelector(
            baseUrl=URL("report", "grid"),
            selectorItems=fieldset)

        return selector_panel