-
Notifications
You must be signed in to change notification settings - Fork 0
/
elements.js
151 lines (112 loc) · 4.6 KB
/
elements.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function makeLegend(_xyz, layer) { // make legend obvs
let container_id = 'xyz_legend';
document.getElementById(container_id).innerHTML = '';
if (layer.style.theme) {
document.getElementById(container_id).appendChild(_xyz.utils.wire()
`<div>${layer.name || ''}`);
document.getElementById(container_id).appendChild(_xyz.utils.wire()
`<small>${layer.style.theme.label || ''}`);
document.getElementById(container_id).appendChild(layer.style.legend);
}
}
function createRegionList(_xyz) { // create region dropdown
// selectors
const dropdown_1_id = 'xyz_locale_dropdown_1';
document.getElementById(dropdown_1_id).innerHTML = '';
document.getElementById('xyz_locale_dropdown_subtext').style.display = 'none';
//document.getElementById(dropdown_2_id).innerHTML = '';
let locale_dropdown_1 = _xyz.utils.dropdownCustom({
entries: [
{ "E15000006": "Eastern" },
{ "E15000004": "East Midlands" },
{ "E15000007": "London" },
{ "E15000001": "North East" },
{ "N08000001": "Northern Ireland" },
{ "E15000002": "North West" },
{ "S92000003": "Scotland" },
{ "E15000008": "South East" },
{ "E15000009": "South West" },
{ "W08000001": "Wales" },
{ "E15000005": "West Midlands" },
{ "E15000003": "Yorkshire and The Humber" }
],
singleSelect: true,
placeholder: 'Select region',
callback: e => {
e.stopPropagation();
document.querySelector('.gazetteer input').value = '';
//document.getElementById(dropdown_2_id).innerHTML = '';
locale_dropdown_1.querySelector('.head').textContent = e.target.textContent;
createSecondaryList(_xyz, {
layer: "Local Authority",
table: "Overview",
label: "lad_name",
placeholder: "Select Local Authority District",
target_id: 'xyz_locale_dropdown_2',
callback: () => {
document.querySelector('#xyz_locale_dropdown_3 .head').textContent = "Select Constituency";
}
}, e);
document.getElementById('xyz_locale_dropdown_subtext').style.display = 'block';
createSecondaryList(_xyz, {
layer: "Constituencies",
table: "Overview",
label: "constituency_name",
placeholder: "Select Constituency",
target_id: 'xyz_locale_dropdown_3',
callback: () => {
document.querySelector('#xyz_locale_dropdown_2 .head').textContent = "Select Local Authority District";
}
}, e);
}
});
return locale_dropdown_1;
}
function createSecondaryList(_xyz, params, _e){
document.getElementById(params.target_id).innerHTML = '';
let layer = _xyz.layers.list[params.layer];
layer.filter = {};
layer.filter.current = {};
layer.filter.current["regioncode"] = {};
layer.filter.current["regioncode"].match = _e.target.dataset.field;
const _xhr = new XMLHttpRequest();
_xhr.open('GET', _xyz.host + '/api/layer/table?' + _xyz.utils.paramString({
locale: _xyz.workspace.locale.key,
layer: params.layer,
table: params.table,
orderby: params.label,
filter: JSON.stringify(layer.filter.current),
token: _xyz.token
}));
_xhr.setRequestHeader('Content-Type', 'application/json');
_xhr.responseType = 'json';
_xhr.onload = e => {
if (e.target.status !== 200) return;
let entries = [];
e.target.response.forEach(each => {
entries.push({
[each.qid]: each[params.label]
});
});
const locale_dropdown = _xyz.utils.dropdownCustom({
entries: entries,
singleSelect: true,
placeholder: params.placeholder,
callback: __e => {
__e.stopPropagation();
document.querySelector('.gazetteer input').value = '';
selectArea(_xyz, {
layer: layer.key,
table: layer.table,
id: __e.target.dataset.field
});
locale_dropdown.querySelector('.head').textContent = __e.target.textContent;
if(params.callback) params.callback();
}
});
document.getElementById(params.target_id).appendChild(locale_dropdown);
}
_xhr.send();
}
function resetList(_xyz, params){
}