From f98a96f546246498b043b03bcce7b59f612354f6 Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Thu, 5 Nov 2020 11:36:36 +0100 Subject: [PATCH] Finalised input validation and updated form with new fields --- cara/apps/calculator/static/form.html | 52 +++++++++----------- cara/apps/calculator/static/js/form.js | 68 ++++++++++++-------------- 2 files changed, 55 insertions(+), 65 deletions(-) diff --git a/cara/apps/calculator/static/form.html b/cara/apps/calculator/static/form.html index 47206719..71d824d4 100644 --- a/cara/apps/calculator/static/form.html +++ b/cara/apps/calculator/static/form.html @@ -14,8 +14,8 @@ -

CARA Covid Airborne Risk Assessment tool (beta)

-

Please send feedback to CARA-dev@cern.ch

+Beta v1.0.0 Please send feedback to CARA-dev@cern.ch +

CARA Covid Airborne Risk Assessment tool

@@ -26,22 +26,22 @@ Room data:
Room volume:   
- or Floor area:   
-      Ceiling height:   
-
+       Ceiling height:   
+
+ Ventilation type: - Mechanical - Natural + Mechanical + Natural
+ -
- HEPA filtration: - - - - - - -
+ HEPA filtration: + + + + +
@@ -74,8 +71,8 @@ Event data:
Attendees:
- Total number of occupants:
- Number of infected people:
+ Total number of occupants:
+ Number of infected people:

Activity type:    Finish:
-
-When is the event?
+
+ When is the event?
Single event Date:
Recurrent usage @@ -110,8 +107,10 @@ When is the event?

Lunch break: - -
+ + + +
Start:    @@ -142,10 +141,7 @@ When is the event?
Face masks:
Are masks worn when occupants are at workstations?
Yes - No - - - + No
@@ -230,7 +226,7 @@ function objectifyForm(formArray) { var value = Number(formArray[i]['value']); - if (formArray[i]['name'] === "simulation_name") + if (formArray[i]['name'] === "simulation_name" || formArray[i]['name'] === "room_number") returnArray[formArray[i]['name']] = formArray[i]['value'].toString(); else if(isNaN(value) || !formArray[i]['value'].trim()) returnArray[formArray[i]['name']] = formArray[i]['value']; diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index ca15b3d0..dedf29e2 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -2,6 +2,9 @@ function clear_form(){ document.covid_calculator.reset(); } +function test() { +} + /* -------Show/Hide DIVs------- */ function show(show, var_id, obj) { var show = document.getElementById(show); @@ -16,30 +19,21 @@ function show(show, var_id, obj) { } function show_hide(show, hide, obj) { + var show = document.getElementById(show); var hide = document.getElementById(hide); - - if (show.style.display === "none") { - show.style.display = "block"; - hide.style.display = "none"; - }// else { - // show.style.display = "none"; - //} + var no_ventilation = document.getElementById("no_ventilation"); - require_fields(obj); - -} - -/*$(document).on("click", "input[name='ventilation_type']", function(){ - thisRadio = $(this); - if (thisRadio.hasClass("imChecked")) { - thisRadio.removeClass("imChecked"); - thisRadio.prop('checked', false); - } else { - thisRadio.prop('checked', true); - thisRadio.addClass("imChecked"); - }; - })*/ + if (show.style.display === "block") { + show.style.display = "none"; + obj.checked = false; + no_ventilation.checked = true; + unrequire_fields(obj); + } else if (show.style.display === "none") { + show.style.display = "block"; + hide.style.display = "none"; + require_fields(obj); +} } /* -------Required fields------- */ function require_fields(obj){ @@ -74,19 +68,23 @@ function require_fields(obj){ case "event_type_recurrent": require_single_event(false); break; - case "BUTTON_lunch": - var button = document.getElementById("lunch_option"); - if (button.value == 0) - require_lunch(false); - else if (button.value == 1) - require_lunch(true); + case "lunch_option_no": + require_lunch(false); break; - case "BUTTON_coffee": - var button = document.getElementById("coffee_option"); - if (button.value == 0) - require_coffee(false); - else if (button.value == 1) - require_coffee(true); + case "lunch_option_yes": + require_lunch(true); + break; + default: + break; +} } + +function unrequire_fields(obj){ + switch(obj.id) { + case "mechanical": + require_mechanical_ventilation(false); + break; + case "natural": + require_natural_ventilation(false); break; default: break; @@ -132,10 +130,6 @@ function require_lunch(option) { $("#lunch_finish").prop('required',option); } -function require_coffee(option) { - $("#coffee_breaks").prop('required',option); -} - /* -------UI------- */ $(function() { $("#datepicker").datepicker();