Skip to content

Commit

Permalink
added ability to specify not required parameter for action link. Fixe… (
Browse files Browse the repository at this point in the history
#321)

* added ability to specify not required parameter for action link. Fixed `title` attribute fr links.

* updated according to comment
  • Loading branch information
wolendranh authored and mmarcos committed Nov 14, 2018
1 parent c6b482a commit 187e289
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
13 changes: 11 additions & 2 deletions arctic/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ def _get_field_actions(self, obj):
)
),
"modal": self.get_modal_link(field_action["url"], obj),
'attributes': field_action["attributes"]
}
)
return actions
Expand Down Expand Up @@ -711,8 +712,16 @@ def get_action_links(self):
return self._allowed_action_links

def _build_action_link(self, action_link):
icon = action_link[2] if len(action_link) == 3 else None
return {"label": action_link[0], "url": action_link[1], "icon": icon}
icon, attributes = 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)
attributes = action_link[2].get('attributes', None)
return {"label": action_link[0], "url": action_link[1],
"icon": icon, "attributes": attributes}

def get_tool_links(self):
if not self.tool_links:
Expand Down
7 changes: 6 additions & 1 deletion arctic/templates/arctic/partials/base_data_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@ <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="{{ link.label|capfirst }}"
<a href="{{ action.url }}" class="action-{{ action.label }} 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 %}
{{ attr_name }}="{{ attr_value }}"
{% endfor %}
{% endif %}
>
{% if action.icon %}
<i class="fa {{ action.icon }} fa-lg"></i>
Expand Down
3 changes: 3 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ standard notation by prepending a minus to the field, for example `-name`.
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'}})`

### `get_field_actions(row)`

Expand Down

0 comments on commit 187e289

Please sign in to comment.