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

Feature/381-accordion-display #482

Merged
merged 6 commits into from
Jan 23, 2025
Merged
Changes from 3 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
50 changes: 47 additions & 3 deletions src/rard/templates/research/partials/ordered_work_area.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
</ul>
</div>

<button type='button' class="btn btn-outline-secondary btn-sm mb-2" data-toggle="collapse" data-target=".multi-collapse" aria-expanded="false" aria-controls="{% for work in object.ordered_works.all %}list_{{ work.pk }} {% endfor %}">{% trans "Expand all" %}</button>

{% for work in object.ordered_works.all %}

<div class='drop-target' data-pos='{{ forloop.counter0 }}' data-objecttype='work'>
Expand All @@ -31,10 +33,12 @@
<div>
{% if work.unknown == True and not flinks and not tlinks and not alinks %}
{% elif work.unknown == True %}
<b class='my-3 mr-3'><a href='{% url "work:detail" work.pk %}'>{{ work.name }}</a></b>
<b class='my-3 mr-1'><a href='{% url "work:detail" work.pk %}' >{{ work.name }}</a></b>
tcouch marked this conversation as resolved.
Show resolved Hide resolved
<button type='button' class="btn btn-text text-primary pl-2 collapse-button" data-toggle="collapse" data-target="#list_{{work.pk}}" role="button" aria-expanded="false" aria-controls="list_{{work.pk}}"><i class='fas fa-chevron-down'><small class='ml-1 text-muted'>{% trans "Expand" %}</small></i></button>
acholyn marked this conversation as resolved.
Show resolved Hide resolved

{% else %}
<b class='my-3 mr-3'><a href='{% url "work:detail" work.pk %}'>{{ work.name }}</a></b>
<b class='my-3 mr-1'><a href='{% url "work:detail" work.pk %}'>{{ work.name }}</a></b>
<button type='button' class="btn btn-text text-primary collapse-button" data-toggle="collapse" data-target="#list_{{work.pk}}" role="button" aria-expanded="false" aria-controls="list_{{work.pk}}"><i class='fas fa-chevron-down'><small class='ml-1 text-muted'>{% trans "Expand" %}</small></i></button>

{% if can_edit and has_object_lock %}
<button type='button' class='drag-handle btn btn-light btn-sm' style='cursor: move;' data-pos='{{ forloop.counter0 }}'><i class='fas fa-bars'></i></button>
Expand All @@ -59,7 +63,7 @@
{% endif %}


<ul>
<ul class="collapse multi-collapse" id="list_{{work.pk}}">
<div class='ordered-list'>

{% if tlinks %}
Expand Down Expand Up @@ -105,3 +109,43 @@
</div>

{% endwith %}

<script>
document.addEventListener('DOMContentLoaded', (event) => {
acholyn marked this conversation as resolved.
Show resolved Hide resolved
var collapseElementList = [].slice.call(document.querySelectorAll('ul.collapse'));
var collapseButtonList = [].slice.call(document.querySelectorAll('.collapse-button'));

function onClassChange(mutationList, observer) {
mutationList.forEach((mutation) => {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
let targetElement = mutation.target;
if (targetElement.classList.contains('show')) {
// Find the button that controls this collapsible element and update the content
var btn = collapseButtonList.find(btn => btn.getAttribute('data-target') === '#' + targetElement.id);
if (btn) {
btn.innerHTML = "<i class='fas fa-chevron-up'><small class='ml-1 text-muted'>{% trans 'Collapse' %}</small></i>";
}
} else {
var btn = collapseButtonList.find(btn => btn.getAttribute('data-target') === '#' + targetElement.id);
if (btn) {
btn.innerHTML = "<i class='fas fa-chevron-down'><small class='ml-1 text-muted'>{% trans 'Expand' %}</small></i>";
}
}
}
});
}

// for each collapse element, attach a mutation observer
collapseElementList.forEach( (collapseEl)=> {
const observer = new MutationObserver(onClassChange);

// Start observing for changes to class
observer.observe(collapseEl, {
attributes: true,
attributeFilter: ['class']
});

});

});
</script>
Loading