(targetId, items, groupName)
| 561 | } |
| 562 | |
| 563 | function renderChoiceList(targetId, items, groupName) { |
| 564 | const target = $(targetId); |
| 565 | if (!target) return; |
| 566 | if (!items.length) { |
| 567 | target.className = "choice-list empty"; |
| 568 | target.textContent = "没有可用来源。"; |
| 569 | return; |
| 570 | } |
| 571 | target.className = "choice-list"; |
| 572 | target.innerHTML = items.map((item) => { |
| 573 | const disabled = item.enabled === false ? " disabled" : ""; |
| 574 | const checked = item.enabled === false ? "" : " checked"; |
| 575 | const group = item.group ? `<span>${escapeHtml(item.group)}</span>` : ""; |
| 576 | return ` |
| 577 | <label class="source-choice"> |
| 578 | <input type="checkbox" name="${groupName}" value="${escapeHtml(item.id)}"${checked}${disabled}> |
| 579 | <span>${escapeHtml(item.label || item.id)}</span> |
| 580 | ${group} |
| 581 | </label> |
| 582 | `; |
| 583 | }).join(""); |
| 584 | } |
| 585 | |
| 586 | function selectedSourceValues(name) { |
| 587 | return [...document.querySelectorAll(`input[name="${name}"]:checked`)] |
no test coverage detected