diff --git a/assets/js/validation.js b/assets/js/validation.js index 1881c8a67..5211f79fc 100644 --- a/assets/js/validation.js +++ b/assets/js/validation.js @@ -1,21 +1,31 @@ -const axios = require('axios'); +window.addEventListener("load",() => { + const axios = require('axios'); -let name = document.getElementById('name'); -let validationResult = document.getElementById('validation-result'); -const validateName = function () { - validationResult.innerText = '...'; - axios.post(validationResult.dataset.path, {input: name.value}) - .then(function(response) { - if (response.data.valid) { - validationResult.innerHTML = ":)"; - } else { - validationResult.innerHTML = ":("; - } - }) - .catch(function (error) { - validationResult.innerText = 'Error: ' + error; - }); -}; + let name = document.getElementById('name'); + let validationResultStudent = document.getElementById('validation-result-name'); + let team = document.getElementById('team'); + let validationResultTeam = document.getElementById('validation-result-team'); -name.onkeyup = validateName; -name.onchange = validateName; + if (!(name && validationResultStudent && team && validationResultTeam)) { + console.log("Didn't find HTML elements :("); + } else { + const validate = function (validationResult, input) { + validationResult.innerText = '...'; + axios.post(validationResult.dataset.path, {input: input.value}) + .then(function (response) { + if (response.data.valid) { + validationResult.innerHTML = ":)"; + } else { + validationResult.innerHTML = ":("; + } + }) + .catch(function (error) { + validationResult.innerText = 'Error: ' + error; + }); + }; + name.onkeyup = ()=>validate(validationResultStudent, name); + name.onchange = ()=>validate(validationResultStudent, name); + team.onkeyup = ()=>validate(validationResultTeam, team); + team.onchange = ()=>validate(validationResultTeam, team); + } +}) \ No newline at end of file diff --git a/src/Controller/PeopleController.php b/src/Controller/PeopleController.php index bb86b5f8e..e6ceabba6 100644 --- a/src/Controller/PeopleController.php +++ b/src/Controller/PeopleController.php @@ -37,9 +37,12 @@ public function validate(Request $request, string $element) } $students = $this->getStudents(); + $teams = $this->getTeams(); switch ($element) { case 'name': return new JsonResponse(['valid' => in_array(strtolower($input), $students)]); + case 'team': + return new JsonResponse(['valid' => in_array(strtolower($input), $teams)]); } return new JsonResponse(['error' => 'Invalid arguments'], Response::HTTP_BAD_REQUEST); @@ -242,4 +245,13 @@ private function getStudents(): array } return $students; } + private function getTeams(): array + { + $teams = []; + $storage = json_decode($this->getStorage(), true); + foreach ($storage as $projectName => $projects) { + $teams[] = strtolower($projectName); + } + return $teams; + } } diff --git a/templates/people/index.html.twig b/templates/people/index.html.twig index cd18cf87f..a2d1903de 100644 --- a/templates/people/index.html.twig +++ b/templates/people/index.html.twig @@ -8,10 +8,19 @@
Versijuojamas JavaScript failas: ...
+ Vardas: - - -{% endblock %} + + + +
+ Komanda: + + + + {% endblock %} {% block javascripts %}