Skip to content

Commit

Permalink
Added ability to select custom class on action links (#329)
Browse files Browse the repository at this point in the history
* Added ability to select custom class on action links

* Changed the way action classes are added

* Flake8

* Included translation change. Fixed mismatch
  • Loading branch information
VolodiaKhl authored and mmarcos committed Dec 21, 2018
1 parent 7db345e commit a95ab35
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion arctic/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def _get_field_actions(self, obj):
{
"label": field_action["label"],
"icon": field_action["icon"],
"class": field_action['class'],
"url": self.in_modal(
reverse_url(
field_action["url"], obj, self.primary_key
Expand Down Expand Up @@ -713,14 +714,17 @@ def get_action_links(self):

def _build_action_link(self, action_link):
icon, attributes = None, None
attributes_class = generate_id('action', action_link[0])
if len(action_link) == 3:
# icon can be 3-rd arg of link or specified inside inside dict with same index
if isinstance(action_link[2], str):
icon = action_link[2]
elif isinstance(action_link[2], dict):
icon = action_link[2].get('icon_class', None)
attributes = action_link[2].get('attributes', None)
return {"label": action_link[0], "url": action_link[1],
if attributes and attributes.get('class', None) and isinstance(attributes.get('class', None), list):
attributes_class = " ".join(attributes.get('class'))
return {"label": action_link[0], "url": action_link[1], 'class': attributes_class,
"icon": icon, "attributes": attributes}

def get_tool_links(self):
Expand Down
2 changes: 1 addition & 1 deletion arctic/templates/arctic/partials/base_data_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ <h4 class="arctic-card__title">
{% block list_actions %}
<div class="list-actions">
{% for action in row.actions %}
<a href="{{ action.url }}" class="action-{{ action.label }} btn btn-secondary btn-sm show-on-hover" title="{{ action.label|capfirst }}"
<a href="{{ action.url }}" class="{{ action.class }} btn btn-secondary btn-sm show-on-hover" title="{{ action.label|capfirst }}"
{% include 'arctic/partials/modal_attributes.html' with modal=action.modal %}
{% if action.attributes %}
{% for attr_name, attr_value in action.attributes.items %}
Expand Down
5 changes: 3 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ optional list of `('name', 'base_url', 'optional icon class')` links, that
appear on the last column of the table and can apply a certain action, such
as delete.
In case if some custom attributes required, they can be specified as last argument in form of dict. In this case
optional icon class can be provided as part of that argument dict
`('name', 'base_url', 'optional icon class', {'icon_class': 'fa', 'attributes': {'custom_attr_name': 'custom_attr_value'}})`
optional icon class can be provided as part of that argument dict.
Classes for action link can be specified as a list.
`('name', 'base_url', 'optional icon class', {'icon_class': 'fa', 'attributes': {'class': ['class0', 'class1'], 'custom_attr_name': 'custom_attr_value'}})`

### `get_field_actions(row)`

Expand Down

0 comments on commit a95ab35

Please sign in to comment.