dropDownList.js 2.42 KB
Newer Older
1
2
"use strict";

Pithon Kabiro's avatar
Pithon Kabiro committed
3
4
5
6
const dropDownBuilding = document.querySelector("#drop-down--bldg");
const dropDownSensorParent = document.querySelector(
  "#drop-down--sensor-parent"
);
7
8
const dropDownSensor = document.querySelector("#drop-down--sensor");

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const showSensorDropDownListFromBuildingList = function () {
  if (dropDownSensorParent.classList.contains("hidden")) {
    dropDownSensorParent.classList.toggle("hidden");
  }
};

const hideSensorDropDownListFromBuildingList = function () {
  if (!dropDownSensorParent.classList.contains("hidden")) {
    dropDownSensorParent.classList.toggle("hidden");
  }
};

// SET THE INITIAL STATE OF THE DROPDOWN
hideSensorDropDownListFromBuildingList();

Pithon Kabiro's avatar
Pithon Kabiro committed
24
25
26
27
28
29
const selectBuildingFromDropDownList = function () {
  const selectedBuilding =
    dropDownBuilding.options[dropDownBuilding.selectedIndex].value;

  switch (selectedBuilding) {
    case "none":
30
      hideSensorDropDownListFromBuildingList();
Pithon Kabiro's avatar
Pithon Kabiro committed
31
32
33
      break;
    case "101":
      console.log("Building 101");
34
      showSensorDropDownListFromBuildingList();
Pithon Kabiro's avatar
Pithon Kabiro committed
35
36
37
      break;
    case "102":
      console.log("Building 102");
38
      showSensorDropDownListFromBuildingList();
Pithon Kabiro's avatar
Pithon Kabiro committed
39
40
41
      break;
    case "107":
      console.log("Building 107");
42
      showSensorDropDownListFromBuildingList();
Pithon Kabiro's avatar
Pithon Kabiro committed
43
44
45
      break;
    case "112":
      console.log("Building 112");
46
      showSensorDropDownListFromBuildingList();
Pithon Kabiro's avatar
Pithon Kabiro committed
47
48
49
      break;
    case "125":
      console.log("Building 125");
50
      showSensorDropDownListFromBuildingList();
Pithon Kabiro's avatar
Pithon Kabiro committed
51
52
53
      break;
    case "225":
      console.log("Building 225");
54
      showSensorDropDownListFromBuildingList();
Pithon Kabiro's avatar
Pithon Kabiro committed
55
56
57
58
59
60
      break;
    default:
      console.log("Default case");
  }
};

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
const selectSensorFromDropDownList = function () {
  const selectedSensor =
    dropDownSensor.options[dropDownSensor.selectedIndex].value;

  switch (selectedSensor) {
    case "none":
      break;
    case "vorlauf":
      console.log("VORLAUF");
      break;
    case "ruecklauf":
      console.log("RUECKLAUF");
      break;
    case "durchfluss":
      console.log("DURCHFLUSS");
      break;
    case "leistung":
      console.log("LEISTUNG");
      break;
    case "energie":
      console.log("ENERGIE");
      break;
    case "energieVerbr":
      console.log("ENERGIE_VERBR");
      break;
    default:
      console.log("Default case");
  }
};

Pithon Kabiro's avatar
Pithon Kabiro committed
91
dropDownBuilding.addEventListener("change", selectBuildingFromDropDownList);
92
dropDownSensor.addEventListener("change", selectSensorFromDropDownList);