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

fix #363: Better UX in versioning listview #364

Merged
merged 2 commits into from
Mar 5, 2024
Merged
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
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
37 changes: 37 additions & 0 deletions djangocms_versioning/static/djangocms_versioning/js/versioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(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');
var selectElement = document.querySelector('#changelist-form select[name="action"]');
if (selectElement instanceof HTMLSelectElement) {
for (var i = 0; i < selectElement.options.length; i++) {
if (selectElement.options[i].value && selectElement.options[i].value !== 'compare_versions') {
// for future safety: do not restrict on two selected versions, since there might be other actions
return;
}
}
}
selectedVersions.forEach(function(selectedVersion){
selectedVersion.addEventListener('change', handleVersionSelection);
});
});
})();
Loading