forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipListDataSource.js
More file actions
38 lines (31 loc) · 1.25 KB
/
ipListDataSource.js
File metadata and controls
38 lines (31 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { parseAndSortIpLists } from './helpers';
// Populates the "Data Source" select with various IP lists on the New IP List page
export default function handleIpListDataSource() {
const dataSourceSelect = document.querySelector('.js-datasource-select');
if (!dataSourceSelect) {
return;
}
// Parse IP lists from HTML and sort them alphabetically
const countryIpLists = parseAndSortIpLists(dataSourceSelect.dataset.countryIplists);
const blacklistIpLists = parseAndSortIpLists(dataSourceSelect.dataset.blacklistIplists);
// Add IP lists to the "Data Source" select
addIPListsToSelect(dataSourceSelect, Alpine.store('globals').BLACKLIST, blacklistIpLists);
addIPListsToSelect(dataSourceSelect, Alpine.store('globals').IPVERSE, countryIpLists);
}
function addIPListsToSelect(dataSourceSelect, label, ipLists) {
// Add a disabled option as a label
addOption(dataSourceSelect, label, '', true);
// Add IP lists to the select element
ipLists.forEach((ipList) => {
addOption(dataSourceSelect, ipList.name, ipList.source, false);
});
}
function addOption(element, text, value, disabled) {
const option = document.createElement('option');
option.text = text;
option.value = value;
if (disabled) {
option.disabled = true;
}
element.append(option);
}