basxsoftwareassociation / bread

Engine to create database applications based on Django and the IBM Carbon Design System
BSD 3-Clause "New" or "Revised" License
19 stars 2 forks source link

Feature/rowaction modals #79

Closed wipascal closed 2 years ago

wipascal commented 3 years ago

I know you were against the lambda parameter for the shortcut... But in this case I didn't find a better solution. I am open for suggestions.

saemideluxe commented 3 years ago

Right, row-click-modal issue :D

In this PR I find more the additional attribute Link.modal problematic. It is changing the Link API in a very specific way for a rather limited use case. For such cases my idea (and recent change) was to have the additional attributes on the Link class to specify special behaviour via HTML attributes.

I would also treat the row-click-modal issue as "experimental" until we learn a bit more how and where we use it. What I mean with that is that I would not yet make permanent changes inside bread itself, especially when we need to extend an API.

But I see the problem here, I tried to implement the modal myself and for a clean implementation there was at least something missing: The id of the modal could not be set dynamically. I fixed that, because id is a normal HTML attribute and should therefore be allowed to use hg.Lazy value. Now, with that we can make a more or less clean implementation without changing bread core:

class CaBrowseView(BrowseView):
    # define the modal with lazy values only and a custom id
    rowedit_modal = layout.modal.Modal.with_ajax_content(
        "Edit",
        ModelHref(
            certmodels.Ca,
            "edit",
            kwargs={"pk": hg.C("row.pk")},
            query={"asajax": True},
        ),
        submitlabel="Save",
        id=hg.format("row-modal-{}", hg.C("row.pk")),
    )
    # add an empty column for the modal
    # the modal could also be attached to an existing column
    # instead of creating a new one
    columns = [
        "name",
        "key_length",
        "digest",
        "created",
        "modified",
        layout.datatable.DataTableColumn("", rowedit_modal),
    ]
    # set the row action
    # it is mostly empty and only needs the openerattributes
    # onclick and onauxclick are set to none for aesthetic reasons ;)
    rowclickaction = Link(
        "#",
        "",
        attributes={
            **rowedit_modal.openerattributes,
            "onclick": None,
            "onauxclick": None,
        },
    )
saemideluxe commented 3 years ago

Adding a shortcut at some point might be usefull though...