feat: inherit most logic from wuttaweb, for GridAction
This commit is contained in:
parent
09612b1921
commit
1b78bd617c
9 changed files with 65 additions and 61 deletions
|
@ -38,6 +38,7 @@ from pyramid.renderers import render
|
|||
from webhelpers2.html import HTML, tags
|
||||
from paginate_sqlalchemy import SqlalchemyOrmPage
|
||||
|
||||
from wuttaweb.grids import GridAction as WuttaGridAction
|
||||
from . import filters as gridfilters
|
||||
from tailbone.db import Session
|
||||
from tailbone.util import raw_datetime
|
||||
|
@ -1801,18 +1802,20 @@ class Grid:
|
|||
return False
|
||||
|
||||
|
||||
class GridAction(object):
|
||||
class GridAction(WuttaGridAction):
|
||||
"""
|
||||
Represents an action available to a grid. This is used to construct the
|
||||
'actions' column when rendering the grid.
|
||||
Represents a "row action" hyperlink within a grid context.
|
||||
|
||||
:param key: Key for the action (e.g. ``'edit'``), unique within
|
||||
the grid.
|
||||
This is a subclass of
|
||||
:class:`wuttaweb:wuttaweb.grids.base.GridAction`.
|
||||
|
||||
:param label: Label to be displayed for the action. If not set,
|
||||
will be a capitalized version of ``key``.
|
||||
.. warning::
|
||||
|
||||
:param icon: Icon name for the action.
|
||||
This class remains for now, to retain compatibility with
|
||||
existing code. But at some point the WuttaWeb class will
|
||||
supersede this one entirely.
|
||||
|
||||
:param target: HTML "target" attribute for the ``<a>`` tag.
|
||||
|
||||
:param click_handler: Optional JS click handler for the action.
|
||||
This value will be rendered as-is within the final grid
|
||||
|
@ -1824,41 +1827,23 @@ class GridAction(object):
|
|||
* ``$emit('do-something', props.row)``
|
||||
"""
|
||||
|
||||
def __init__(self, key, label=None, url='#', icon=None, target=None,
|
||||
link_class=None, click_handler=None):
|
||||
self.key = key
|
||||
self.label = label or prettify(key)
|
||||
self.icon = icon
|
||||
self.url = url
|
||||
def __init__(
|
||||
self,
|
||||
request,
|
||||
key,
|
||||
target=None,
|
||||
click_handler=None,
|
||||
**kwargs,
|
||||
):
|
||||
# TODO: previously url default was '#' - but i don't think we
|
||||
# need that anymore? guess we'll see..
|
||||
#kwargs.setdefault('url', '#')
|
||||
|
||||
super().__init__(request, key, **kwargs)
|
||||
|
||||
self.target = target
|
||||
self.link_class = link_class
|
||||
self.click_handler = click_handler
|
||||
|
||||
def get_url(self, row, i):
|
||||
"""
|
||||
Returns an action URL for the given row.
|
||||
"""
|
||||
if callable(self.url):
|
||||
return self.url(row, i)
|
||||
return self.url
|
||||
|
||||
def render_icon(self):
|
||||
"""
|
||||
Render the HTML snippet for the action link icon.
|
||||
"""
|
||||
return HTML.tag('i', class_='fas fa-{}'.format(self.icon))
|
||||
|
||||
def render_label(self):
|
||||
"""
|
||||
Render the label "text" within the actions column of a grid
|
||||
row. Most actions have a static label that never varies, but
|
||||
you can override this to add e.g. HTML content. Note that the
|
||||
return value will be treated / rendered as HTML whether or not
|
||||
it contains any, so perhaps be careful that it is trusted
|
||||
content.
|
||||
"""
|
||||
return self.label
|
||||
|
||||
|
||||
class URLMaker(object):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue