-
Notifications
You must be signed in to change notification settings - Fork 0
/
select2.js
76 lines (65 loc) · 2.18 KB
/
select2.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
import { getDataAndLoadSelect2 } from "./getDataAndLoadSelect2.js";
import { composeGraphData } from "./dataForGraphs.js";
import { renderChart } from "./renderChart.js";
$("#families")
.select2({
placeholder: "Select an option",
allowClear: true,
minimumResultsForSearch: Infinity,
data: [
{ id: "cn", text: "Combined Nomenclature" },
{ id: "prodcom", text: "Community Production" },
],
})
.on("select2:select", function (e) {
$("#versions").empty();
$("#concepts").empty().prop("disabled", true);
$("#visualization").empty();
const family = e.params.data.id;
getDataAndLoadSelect2(e.target.id, family);
})
.on("select2:clear", function (e) {
$("#versions").empty().prop("disabled", true);
$("#concepts").empty().prop("disabled", true);
$("#submit-button").prop("disabled", true);
$("#errorContainer").empty();
$("#visualization").empty();
});
$("#versions")
.select2()
.on("select2:select", function (e) {
$("#concepts").empty().prop("disabled", true);
$("#submit-button").prop("disabled", true);
$("#visualization").empty();
$("#errorContainer").empty();
const version = e.params.data.id;
const family = $("#families").val();
const conceptSchemeUri = e.params.data.data.conceptSchemeUri;
getDataAndLoadSelect2(e.target.id, family, conceptSchemeUri, version);
})
.on("select2:clear", function (e) {
$("#concepts").empty().prop("disabled", true);
$("#submit-button").prop("disabled", true);
$("#visualization").empty();
$("#errorContainer").empty();
});
$("#concepts").select2()
.on("select2:select", function (e) {
$("#submit-button").prop("disabled", false);
$("#visualization").empty();
$("#errorContainer").empty();
})
$("#submit-button").on("click", async function () {
$("#visualization").empty();
$("#errorContainer").empty();
const family = $("#families").val();
const baseYear = Number($("#versions").val());
const conceptId = $("#concepts").select2('data')[0].id;
const conceptLabel = $("#concepts").select2('data')[0].code;
try {
const graphData = await composeGraphData("concepts", family, baseYear, conceptId, conceptLabel);
renderChart(graphData);
} catch (error) {
console.error("Error:", error.message);
}
});