Skip to content

Commit

Permalink
fix #363: Better UX in versioning listview
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Dec 29, 2023
1 parent 08c48a5 commit 6ca5b35
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ class VersionAdmin(ChangeListActionsMixin, admin.ModelAdmin, metaclass=MediaDefi
# def get_queryset(self, request):
# return super().get_queryset(request).prefetch_related('content')

class Media:
js = ["djangocms_versioning/js/versioning.js"]

def get_changelist(self, request, **kwargs):
return VersionChangeList

Expand Down
28 changes: 28 additions & 0 deletions djangocms_versioning/static/djangocms_versioning/js/versioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(function() {
var firstChecked, lastChecked;

function handleVersionSelection(event) {
if (firstChecked instanceof HTMLInputElement && firstChecked.checked) {
firstChecked.checked = false;
firstChecked.closest('tr').classList.remove('selected');
firstChecked = lastChecked;
}
if (event.target instanceof HTMLInputElement) {
if (event.target.checked) {
firstChecked = lastChecked;
lastChecked = event.target;
} else if (firstChecked === event.target) {
firstChecked = null;
} else {
lastChecked = null;
}
}
}

document.addEventListener('DOMContentLoaded', function(){
var selectedVersions = document.querySelectorAll('#result_list input[type="checkbox"].action-select');
selectedVersions.forEach(function(selectedVersion){
selectedVersion.addEventListener('change', handleVersionSelection);
});
});
})();

0 comments on commit 6ca5b35

Please sign in to comment.