Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to select custom class on action links #329

Merged
merged 4 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions 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 @@ -712,15 +713,16 @@ def get_action_links(self):
return self._allowed_action_links

def _build_action_link(self, action_link):
icon, attributes = None, None
icon, action_class, attributes = None, None, None
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)
action_class = action_link[2].get('action_class', None)
attributes = action_link[2].get('attributes', None)
return {"label": action_link[0], "url": action_link[1],
return {"label": action_link[0], "url": action_link[1], 'class': action_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-{% if action.class %}{{ action.class }}{% else %}{{ action.label }}{% endif %} btn btn-secondary btn-sm show-on-hover" title="{{ action.label|capfirst }}"
VolodiaKhl marked this conversation as resolved.
Show resolved Hide resolved
{% include 'arctic/partials/modal_attributes.html' with modal=action.modal %}
{% if action.attributes %}
{% for attr_name, attr_value in action.attributes.items %}
Expand Down
2 changes: 1 addition & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ 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'}})`
`('name', 'base_url', 'optional icon class', {'icon_class': 'fa', 'action_class': 'name', 'attributes': {'custom_attr_name': 'custom_attr_value'}})`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is already an icon_class, why do we need an action_class? I don't see the icon_class in the code however...


### `get_field_actions(row)`

Expand Down