Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/unfold/static/unfold/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ const moveRecords = (e) => {
}
};

/*************************************************************
* Change list filters
*************************************************************/
function changeList(hasFilters = false) {
return {
hasFilters,
filterOpen: false,
applyShortcut(event) {
if (
this.hasFilters &&
event.key.toLowerCase() === "f" &&
document.activeElement.tagName.toLowerCase() !== "input" &&
document.activeElement.tagName.toLowerCase() !== "textarea" &&
!document.activeElement.isContentEditable
) {
event.preventDefault();
this.filterOpen = true;
}
},
};
}

/*************************************************************
* Search form
*************************************************************/
Expand Down
6 changes: 4 additions & 2 deletions src/unfold/templates/admin/change_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% endblock %}

{% block content %}
<div id="content-main" x-data="{ filterOpen: false }">
<div id="content-main" x-data="changeList({% if cl.has_filters %}true{% else %}false{% endif %})" x-on:keydown.window="applyShortcut($event)" x-on:keydown.escape.window="filterOpen = false">
{% if cl.formset and cl.formset.errors %}
{% include "unfold/helpers/messages/errornote.html" with errors=cl.formset.errors %}

Expand Down Expand Up @@ -61,9 +61,11 @@

{% block filters %}
{% if cl.has_filters %}
<a class="{% if cl.has_active_filters %}bg-primary-600 border-primary-600 text-white{% else %}bg-white border-base-200 hover:text-primary-600 dark:bg-base-900 dark:border-base-700 dark:hover:text-primary-500{% endif %} border cursor-pointer flex font-medium gap-2 group items-center px-3 py-2 rounded-default shadow-xs text-sm lg:ml-auto md:mt-0 {% if not cl.model_admin.list_filter_sheet %}2xl:hidden{% endif %}" x-on:click="filterOpen = true" x-on:keydown.escape.window="filterOpen = false">
<a class="{% if cl.has_active_filters %}bg-primary-600 border-primary-600 text-white{% else %}bg-white border-base-200 hover:text-primary-600 dark:bg-base-900 dark:border-base-700 dark:hover:text-primary-500{% endif %} border cursor-pointer flex font-medium gap-2 group items-center px-3 py-2 rounded-default shadow-xs text-sm lg:ml-auto md:mt-0 {% if not cl.model_admin.list_filter_sheet %}2xl:hidden{% endif %}" x-on:click="filterOpen = true">
{% trans "Filters" %}

{% include "unfold/helpers/shortcut.html" with shortcut="f" %}

<span class="material-symbols-outlined md-18 ml-auto">filter_list</span>
</a>
{% endif %}
Expand Down