コード例 #1
0
    def wrapWidget(self, editable, cls=E):
        """Wrap the field value.

        A widget shows the value and may have additional controls to

        *   edit the value
        *   refresh the value

        Refresh fields are those fields that change if other fields are updated,
        typically fields that record the moment on which something happened.
        These fields will get a refresh button automatically.

        Fields may have three conditions relevant for rendering:

        condition | rendering
        --- | ---
        not editable | readonly
        editable in readonly view | readonly with button for editable view
        editable in edit view | editable with button for readonly view

        Parameters
        ----------
        editable: boolean
            Whether the field should be presented in editable form
        cls
            See `Field.wrap()`

        Returns
        -------
        button: string(html)
        representation: string(html)

        They are packaged as a tuple.
        """

        atts = self.atts
        mayEdit = self.mayEdit
        withRefresh = self.withRefresh

        button = (H.iconx(N.ok, cls="small", action=N.view, **atts) if editable
                  else (H.iconx(N.edit, cls="small", action=N.edit, **atts)
                        if mayEdit else H.iconx(
                            N.refresh,
                            cls="small",
                            action=N.view,
                            title=REFRESH,
                            **atts,
                        ) if withRefresh else E))

        return (button, self.wrapValue(editable, cls=cls))
コード例 #2
0
ファイル: value.py プロジェクト: Dans-labs/dariah-contrib
    def widget(self, val, multiple, extensible, constrain):
        context = self.context
        db = context.db
        table = self.name

        valueRecords = db.getValueRecords(table, constrain=constrain)

        filterControl = (
            [
                H.input(
                    E,
                    type=N.text,
                    placeholder=G(MESSAGES, N.filter, default=E),
                    cls="wfilter",
                ),
                H.iconx(N.add, cls="small wfilter add", title="add value")
                if extensible
                else E,
                H.iconx(N.clear, cls="small wfilter clear", title="clear filter"),
            ]
            if len(valueRecords) > FILTER_THRESHOLD
            else []
        )
        atts = dict(
            markup=True,
            clickable=True,
            multiple=multiple,
            active=val,
            hideInActual=True,
            hideBlockedUsers=True,
        )
        return H.div(
            filterControl
            + [
                formatted
                for (text, formatted) in (
                    ([] if multiple else [self.title(record={}, **atts)])
                    + sorted(
                        (self.title(record=record, **atts) for record in valueRecords),
                        key=lambda x: x[0].lower(),
                    )
                )
            ],
            cls="wvalue",
        )
コード例 #3
0
ファイル: bool.py プロジェクト: Dans-labs/dariah-contrib
    def widget(self, val):
        values = G(BOOLEAN_TYPES, self.name)
        noneValue = False if len(values) == 2 else None
        refV = G(values, val, default=G(values, noneValue))

        return H.div(
            [
                H.iconx(
                    values[w],
                    bool=str(w).lower(),
                    cls=(("active" if values[w] is refV else E) + " medium"),
                )
                for w in values
            ],
            cls="wvalue",
        )
コード例 #4
0
ファイル: record.py プロジェクト: Dans-labs/dariah-contrib
    def deleteButton(self):
        """Show the delete button and/or the number of dependencies.

        Check the permissions in order to not show a delete button if the user
        cannot delete the record.

        Returns
        -------
        string(html)
        """

        mayDelete = self.mayDelete

        if not mayDelete:
            return E

        record = self.record
        table = self.table
        itemSingle = self.itemLabels[0]

        dependencies = self.getDependencies()

        nCas = G(dependencies, N.cascade, default=0)
        cascadeMsg = (H.span(
            f"""{nCas} detail record{E if nCas == 1 else S}""",
            title="""Detail records will be deleted with the master record""",
            cls="label small warning-o right",
        ) if nCas else E)
        cascadeMsgShort = (
            f""" and {nCas} dependent record{E if nCas == 1 else S}"""
            if nCas else E)

        nRef = G(dependencies, N.reference, default=0)

        if nRef:
            plural = E if nRef == 1 else S
            return H.span([
                H.icon(
                    N.chain,
                    cls="medium right",
                    title=
                    f"""Cannot delete because of {nRef} dependent record{plural}""",
                ),
                H.span(
                    f"""{nRef} dependent record{plural}""",
                    cls="label small warning-o right",
                ),
            ])

        if table in TO_MASTER:
            masterTable = G(TO_MASTER, table)
            masterId = G(record, masterTable)
        else:
            masterTable = None
            masterId = None

        url = (
            f"""/api/{table}/{N.delete}/{G(record, N._id)}"""
            if masterTable is None or masterId is None else
            f"""/api/{masterTable}/{masterId}/{table}/{N.delete}/{G(record, N._id)}"""
        )
        return H.span([
            cascadeMsg,
            H.iconx(
                N.delete,
                cls="medium right warning",
                deleteurl=url,
                title=f"""delete this {itemSingle}{cascadeMsgShort}""",
            ),
        ])