687 |
687 |
});
|
688 |
688 |
}
|
689 |
689 |
|
|
690 |
function getInputParaId(input) {
|
|
691 |
return `${input.name} ${input.value}`;
|
|
692 |
}
|
|
693 |
|
|
694 |
function replaceButKeepInput(targetId, newData) {
|
|
695 |
if (!targetId)
|
|
696 |
return;
|
|
697 |
let element = document.getElementById(targetId);
|
|
698 |
if (!element)
|
|
699 |
return;
|
|
700 |
let tmpElement = document.createElement("p");
|
|
701 |
tmpElement.innerHTML = newData;
|
|
702 |
let oldMap = new Map(
|
|
703 |
Array.from(element.querySelectorAll("input"))
|
|
704 |
.map(node => [getInputParaId(node), node.checked])
|
|
705 |
)
|
|
706 |
let newMap = new Map(
|
|
707 |
Array.from(tmpElement.querySelectorAll("input"))
|
|
708 |
.map(node => [getInputParaId(node), node.checked])
|
|
709 |
)
|
|
710 |
for (let input of element.querySelectorAll("input")) {
|
|
711 |
if (newMap.get(getInputParaId(input)) === undefined) {
|
|
712 |
// remember the checked state in a hidden input
|
|
713 |
input.type = "hidden";
|
|
714 |
// hidden input has to be additionally disabled to not get sent
|
|
715 |
input.disabled = !input.checked;
|
|
716 |
tmpElement.append(input);
|
|
717 |
}
|
|
718 |
}
|
|
719 |
element.innerHTML = tmpElement.innerHTML;
|
|
720 |
for (let input of element.querySelectorAll("input")) {
|
|
721 |
if (oldMap.get(getInputParaId(input)))
|
|
722 |
input.checked = true;
|
|
723 |
}
|
|
724 |
}
|
|
725 |
|
690 |
726 |
function observeSearchfield(fieldId, targetId, url) {
|
691 |
727 |
$('#'+fieldId).each(function() {
|
692 |
728 |
var $this = $(this);
|
... | ... | |
700 |
736 |
url: url,
|
701 |
737 |
type: 'get',
|
702 |
738 |
data: {q: $this.val()},
|
703 |
|
success: function(data){ if(targetId) $('#'+targetId).html(data); },
|
|
739 |
success: function(data){ replaceButKeepInput(targetId, data); },
|
704 |
740 |
beforeSend: function(){ $this.addClass('ajax-loading'); },
|
705 |
741 |
complete: function(){ $this.removeClass('ajax-loading'); }
|
706 |
742 |
});
|