Created
January 6, 2025 11:45
-
-
Save pawnhearts/a4c9dad082fbde2a3687f3b873579b45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function () { | |
const $=window.django.jQuery | |
$( "#changelist-search" ).on( "submit", function( event ) { | |
let new_url = location.href.split('?')[0] +'?' + $( this ).serialize() | |
window.sel=[] | |
$('input.action-select').each(function(){ | |
if(this.checked) { | |
window.sel.push(this.value) | |
} | |
}) | |
$.ajax({ | |
url: new_url, | |
success: (data) => { | |
let res = $(data) | |
console.log(res.find('.results')) | |
$('.results').children().remove() | |
$('.results').html(res.find('.results').html()) | |
$('.paginator').children().remove() | |
$('.paginator').html(res.find('.paginator').html()) | |
window.history.pushState({"html":data,"pageTitle":document.title},"", new_url); | |
list_selection() | |
// window.document.dispatchEvent(new Event("DOMContentLoaded", { | |
// bubbles: true, | |
// cancelable: true | |
// })); | |
$('input.action-select').each(function(){ | |
$(this).prop('checked', window.sel.indexOf(this.value) !== -1) | |
}) | |
}, | |
}); | |
event.preventDefault(); | |
}); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function () { | |
// django.jQuery('#result_list tr').click(function () { | |
// django.jQuery(this).find('.action-select').prop('checked', !django.jQuery(this).hasClass('selected')) | |
// }) | |
let last_selected = null; | |
list_selection() | |
}) | |
function list_selection(){ | |
document.querySelectorAll('#result_list tbody tr').forEach(row => | |
row.addEventListener('click', (e) => { | |
if(e.target.tagName.toLowerCase() === 'input' || e.target.tagName.toLowerCase() === 'a') return | |
let input = row.querySelector('input') | |
if (e.shiftKey) { | |
let found = false; | |
document.querySelectorAll('#result_list input.action-select').forEach(inp => { | |
if(inp === last_selected || inp === input) { | |
found = !found | |
} | |
if(found) { | |
inp.checked=true | |
} | |
}) | |
window.getSelection().empty() | |
} else if (e.ctrlKey || e.metaKey) { | |
input.checked = !input.checked | |
last_selected = input | |
} else { | |
document.querySelectorAll('#result_list input.action-select').forEach(inp => { | |
inp.checked = false | |
}) | |
input.checked = true | |
last_selected = input | |
} | |
document.querySelectorAll('#result_list tbody tr').forEach(trtr => { | |
trtr.className = trtr.querySelector('input').checked?'selected': ''; | |
}) | |
e.preventDefault() | |
return false | |
}) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment