Add extra button functionality to list and detail views
This commit is contained in:
parent
3d7c3504aa
commit
96dc21019b
|
@ -39,6 +39,23 @@
|
|||
</span>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% for button in extra_buttons %}
|
||||
<button
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
hx-delete="{{ button.url }}"
|
||||
hx-trigger="click"
|
||||
hx-target="#modals-here"
|
||||
hx-swap="innerHTML"
|
||||
{% if button.confirm %}hx-confirm="Are you sure you wish to {{ button.action }}?"{% endif %}
|
||||
class="button">
|
||||
<span class="icon-text">
|
||||
<span class="icon">
|
||||
<i class="{{ button.icon }}"></i>
|
||||
</span>
|
||||
<span>{{ button.label }}</span>
|
||||
</span>
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% include detail_template %}
|
||||
|
|
|
@ -39,6 +39,23 @@
|
|||
</span>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% for button in extra_buttons %}
|
||||
<button
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
hx-delete="{{ button.url }}"
|
||||
hx-trigger="click"
|
||||
hx-target="#modals-here"
|
||||
hx-swap="innerHTML"
|
||||
{% if button.confirm %}hx-confirm="Are you sure you wish to {{ button.action }}?"{% endif %}
|
||||
class="button">
|
||||
<span class="icon-text">
|
||||
<span class="icon">
|
||||
<i class="{{ button.icon }}"></i>
|
||||
</span>
|
||||
<span>{{ button.label }}</span>
|
||||
</span>
|
||||
</button>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% include list_template %}
|
||||
|
|
|
@ -50,6 +50,8 @@ class ObjectList(RestrictedViewMixin, ObjectNameMixin, ListView):
|
|||
delete_all_url_name = None
|
||||
widget_options = None
|
||||
|
||||
extra_buttons = None
|
||||
|
||||
def queryset_mutate(self, queryset):
|
||||
pass
|
||||
|
||||
|
@ -130,6 +132,8 @@ class ObjectList(RestrictedViewMixin, ObjectNameMixin, ListView):
|
|||
context["delete_all_url"] = reverse(self.delete_all_url_name)
|
||||
if self.widget_options:
|
||||
context["widget_options"] = self.widget_options
|
||||
if self.extra_buttons is not None:
|
||||
context["extra_buttons"] = self.extra_buttons
|
||||
|
||||
# Return partials for HTMX
|
||||
if self.request.htmx:
|
||||
|
@ -261,6 +265,8 @@ class ObjectRead(RestrictedViewMixin, ObjectNameMixin, DetailView):
|
|||
|
||||
request = None
|
||||
|
||||
extra_buttons = None
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
type = kwargs.get("type", None)
|
||||
if not type:
|
||||
|
@ -306,6 +312,9 @@ class ObjectRead(RestrictedViewMixin, ObjectNameMixin, DetailView):
|
|||
self.detail_url_name, kwargs=detail_url_args
|
||||
)
|
||||
|
||||
if self.extra_buttons is not None:
|
||||
context["extra_buttons"] = self.extra_buttons
|
||||
|
||||
# Return partials for HTMX
|
||||
if self.request.htmx:
|
||||
if request.headers["HX-Target"] == self.context_object_name + "-info":
|
||||
|
|
Loading…
Reference in New Issue