From dfd166403d21f2cf3074ce331832d772abf7bc8a Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Tue, 17 Nov 2020 22:40:49 +0100 Subject: [PATCH 01/11] Merged start and finish time validation --- cara/apps/calculator/static/js/form.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index f26cfa16..2b1a117d 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -1,4 +1,4 @@ -/* ------- HTML structure ------- */ +/* -------HTML structure------- */ function getChildElement(elem) { // Get the element named in the given element's data-enables attribute. return $("#" + elem.data("enables")); @@ -301,19 +301,6 @@ function validateFinishTime(obj) { return true; } -//TODO: Merge with validateFinishTime() -function validateStartTime() { - $(this).next().removeClass("red_border"); - $(this).next().next().hide(); - - var startTime = parseValToNumber($(this).val()); - var finishTime = parseValToNumber($(this).next().val()); - if (startTime > finishTime) { - $(this).next().addClass("red_border"); - $(this).next().next().show(); - } -} - function parseValToNumber(val) { return parseInt(val.replace(':',''), 10); } @@ -350,7 +337,7 @@ $(document).ready(function () { //Validate all finish times $("input[required].finish_time").each(function() {validateFinishTime(this)}); $(".finish_time").change(function() {validateFinishTime(this)}); - $(".start_time").change(validateStartTime); + $(".start_time").change(function() {validateFinishTime(this.nextSibling.nextSibling)}); var radioValue = $("input[name='event_type']:checked"); if (radioValue.val()) { From e6a4194633e12116135531ec9fed5a144b48577e Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Tue, 17 Nov 2020 22:51:31 +0100 Subject: [PATCH 02/11] Keep # near IDs --- cara/apps/calculator/static/js/form.js | 37 +++++++++++++------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index 2b1a117d..fdf1348c 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -83,45 +83,45 @@ function unrequire_fields(obj) { } function require_room_volume(option) { - require_nonzero_field("room_volume", option); + require_input_field("#room_volume", option); } function require_room_dimensions(option) { - require_nonzero_field("floor_area", option); - require_nonzero_field("ceiling_height", option); + require_input_field("#floor_area", option); + require_input_field("#ceiling_height", option); } function require_mechanical_ventilation(option) { $("#air_type_changes").prop('required', option); $("#air_type_supply").prop('required', option); if (!option) { - removeInvalid("air_changes"); - removeInvalid("air_supply"); + removeInvalid("#air_changes"); + removeInvalid("#air_supply"); } } function require_natural_ventilation(option) { - require_nonzero_field("windows_number", option); - require_nonzero_field("window_height", option); - require_nonzero_field("opening_distance", option); + require_input_field("#windows_number", option); + require_input_field("#window_height", option); + require_input_field("#opening_distance", option); $("#always").prop('required', option); $("#interval").prop('required', option); } function require_air_changes(option) { - require_nonzero_field("air_changes", option); + require_input_field("#air_changes", option); } function require_air_supply(option) { - require_nonzero_field("air_supply", option); + require_input_field("#air_supply", option); } function require_single_event(option) { - require_nonzero_field("single_event_date", option); + require_input_field("#single_event_date", option); } -function require_nonzero_field(id, option) { - $("#"+id).prop('required', option); +function require_input_field(id, option) { + $(id).prop('required', option); if (!option) removeInvalid(id); } @@ -155,7 +155,7 @@ function require_mask(option) { } function require_hepa(option) { - require_nonzero_field("hepa_amount", option); + require_input_field("#hepa_amount", option); } function setMaxInfectedPeople() { @@ -171,11 +171,10 @@ function setMaxInfectedPeople() { } function removeInvalid(id) { - var obj = document.getElementById(id) - if (obj.classList.contains("red_border")) { - obj.value = ""; - $(obj).removeClass("red_border"); - $(obj).next('span').remove(); + if ($(id).hasClass("red_border")) { + $(id).val(""); + $(id).removeClass("red_border"); + $(id).next('span').remove(); } } From e8db077e263f15995c09f1857141bddc6beae4bf Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Wed, 18 Nov 2020 19:33:11 +0100 Subject: [PATCH 03/11] Added ACH placeholder --- cara/apps/calculator/templates/calculator.form.html.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cara/apps/calculator/templates/calculator.form.html.j2 b/cara/apps/calculator/templates/calculator.form.html.j2 index 91c90c4a..1ed5ff3a 100644 --- a/cara/apps/calculator/templates/calculator.form.html.j2 +++ b/cara/apps/calculator/templates/calculator.form.html.j2 @@ -62,7 +62,7 @@ Air supply flow rate   
- Air changes per hour   
+ Air changes per hour   

- Room volume:   
+    +
- Floor area:   
-       Ceiling height:   
+    +
+          +

@@ -54,15 +57,17 @@ ?
Ventilation type: - No ventilation - Mechanical - Natural
+ +    + +    +
HEPA filtration: - +    - +   
@@ -89,11 +94,15 @@ ?
Are masks worn when occupants are at workstations? - Yes - No
+ +    + +
Type of masks used: - Type 1 - FFP2
+ +    + +

@@ -130,12 +139,11 @@ ?
- -    - +    +
- + - +    -
+
Start:    @@ -166,25 +174,24 @@
- Coffee Breaks - - - - - - -
- Duration (minutes):
- Coffee breaks are spread evenly throughout the day. -
-
+ Coffee Breaks:   + +    + +    + +
+ + Duration (minutes):
+ Coffee breaks are spread evenly throughout the day.
+
From 445f927db0c34105578bae9773868aaa66a0b34d Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Wed, 18 Nov 2020 20:22:26 +0100 Subject: [PATCH 05/11] Added clickable input fields for radio buttons --- cara/apps/calculator/static/js/form.js | 4 ++++ .../templates/calculator.form.html.j2 | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index fdf1348c..835e6fda 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -218,6 +218,10 @@ function show_disclaimer() { } } +function check_radio(id) { + $(id).click(); +} + /* -------Form validation------- */ function validate_form(form) { var submit = true; diff --git a/cara/apps/calculator/templates/calculator.form.html.j2 b/cara/apps/calculator/templates/calculator.form.html.j2 index 93e76727..ef73ba12 100644 --- a/cara/apps/calculator/templates/calculator.form.html.j2 +++ b/cara/apps/calculator/templates/calculator.form.html.j2 @@ -43,12 +43,12 @@

   -
+
   -
+
         -
+

@@ -65,9 +65,11 @@
   -
+
   -
+
         -
+

@@ -66,10 +66,10 @@
Are masks worn when occupants are at workstations? - +    - +
Type of masks used: - +    - +

@@ -115,12 +116,12 @@
?

- Total number of occupants:
- Number of infected people:
+ Total number of occupants:
+ Number of infected people:

- Activity type: @@ -129,24 +130,24 @@
- Start:    - Finish:
+ Start:    + Finish:
Infected person(s) presence:
- Start:    - Finish:
+ Start:    + Finish:

When is the event?
?

- +    -
- +
+ - @@ -165,26 +166,26 @@ Activity breaks:
Lunch break:   - +    - +
- Start:    - Finish:
+ Start:    + Finish:
Coffee Breaks:   - +    - +    - +
- Duration (minutes): @@ -230,7 +231,7 @@ Refer to COVID Calculator user-guide for more detailed explanations on how to use this tool.
-



+



@@ -244,7 +245,7 @@ We do not assume responsibility for any injury or damage to persons or property arising out of or related to any use of this app.

Code License:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


-

+

From 3ebef5b5b4d21599ef087e6ffb2b1b4444cf2ef5 Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Wed, 18 Nov 2020 23:20:05 +0100 Subject: [PATCH 08/11] Added check that break time < activity time --- cara/apps/calculator/static/js/form.js | 31 +++++++++++++++++++ .../templates/calculator.form.html.j2 | 4 +-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index de32ed7d..d1f4b584 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -277,6 +277,30 @@ function validate_form(form) { submit = false; }); + //Check if breaks length >= activity length + var button = document.getElementById("activity_breaks"); + $(button).next('span').remove(); + + var lunch_mins = 0; + if (document.getElementById('lunch_option_yes').checked) { + var lunch_start = document.getElementById("lunch_start"); + var lunch_finish = document.getElementById("lunch_finish"); + lunch_mins = parseTimeToMins(lunch_finish.value) - parseTimeToMins(lunch_start.value); + } + + var coffee_breaks = parseInt(document.querySelector('input[name="coffee_breaks"]:checked').value); + var coffee_duration = parseInt(document.getElementById("break_duration").value); + var coffee_mins = coffee_breaks * coffee_duration; + + var activity_start = document.getElementById("activity_start"); + var activity_finish = document.getElementById("activity_finish"); + var activity_mins = parseTimeToMins(activity_finish.value) - parseTimeToMins(activity_start.value); + + if ((lunch_mins + coffee_mins) >= activity_mins) { + insertSpanAfter(button, "Length of breaks >= Length of activity"); + submit = false; + } + return submit; } @@ -341,6 +365,13 @@ function parseValToNumber(val) { return parseInt(val.replace(':',''), 10); } +function parseTimeToMins(cTime) +{ + var d = new Date(); + var time = cTime.match(/(\d+)(:(\d\d))?\s*(p?)/); + return parseInt(time[1]*60) + parseInt(time[3]); +} + /* -------On Load------- */ $(document).ready(function () { // When the document is ready, deal with the fact that we may be here diff --git a/cara/apps/calculator/templates/calculator.form.html.j2 b/cara/apps/calculator/templates/calculator.form.html.j2 index 2e33fbdc..2b4a6730 100644 --- a/cara/apps/calculator/templates/calculator.form.html.j2 +++ b/cara/apps/calculator/templates/calculator.form.html.j2 @@ -163,7 +163,7 @@

- Activity breaks:
+ Activity breaks:
Lunch break:   @@ -231,7 +231,7 @@ Refer to COVID Calculator user-guide for more detailed explanations on how to use this tool.
-



+



From 75ffc84357b409a85376539574e5f49b17338846 Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Thu, 19 Nov 2020 19:57:23 +0100 Subject: [PATCH 09/11] Minor code changes --- cara/apps/calculator/static/js/form.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index d1f4b584..d8fc1bcf 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -365,10 +365,8 @@ function parseValToNumber(val) { return parseInt(val.replace(':',''), 10); } -function parseTimeToMins(cTime) -{ - var d = new Date(); - var time = cTime.match(/(\d+)(:(\d\d))?\s*(p?)/); +function parseTimeToMins(cTime) { + var time = cTime.match(/(\d+)(:(\d+))/); return parseInt(time[1]*60) + parseInt(time[3]); } From f302267bbe173d72acb169564dd7318e80a1f58e Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Thu, 19 Nov 2020 19:59:18 +0100 Subject: [PATCH 10/11] Minor code changes --- cara/apps/calculator/templates/calculator.form.html.j2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cara/apps/calculator/templates/calculator.form.html.j2 b/cara/apps/calculator/templates/calculator.form.html.j2 index 2b4a6730..3a4705dc 100644 --- a/cara/apps/calculator/templates/calculator.form.html.j2 +++ b/cara/apps/calculator/templates/calculator.form.html.j2 @@ -163,7 +163,9 @@

- Activity breaks:
+
+ Activity breaks: +
Lunch break:   From 78eeb9e7add6fb413fbdb12046994bfcf36e55d2 Mon Sep 17 00:00:00 2001 From: gaazzopa Date: Thu, 19 Nov 2020 22:53:32 +0100 Subject: [PATCH 11/11] Grayed-out unused inputs in form UI --- cara/apps/calculator/static/css/form.css | 6 +- cara/apps/calculator/static/js/form.js | 32 ++++++-- .../templates/calculator.form.html.j2 | 80 +++++++++---------- 3 files changed, 66 insertions(+), 52 deletions(-) diff --git a/cara/apps/calculator/static/css/form.css b/cara/apps/calculator/static/css/form.css index bbc7f767..24781792 100644 --- a/cara/apps/calculator/static/css/form.css +++ b/cara/apps/calculator/static/css/form.css @@ -1,9 +1,5 @@ .disabled { - color: gray; -} - -.disabled { - color: black; + background-color: silver; } .red_border { diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index d8fc1bcf..8c9a9256 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -84,11 +84,14 @@ function unrequire_fields(obj) { function require_room_volume(option) { require_input_field("#room_volume", option); + disable_input_field("#room_volume", option); } function require_room_dimensions(option) { require_input_field("#floor_area", option); require_input_field("#ceiling_height", option); + disable_input_field("#floor_area", option); + disable_input_field("#ceiling_height", option); } function require_mechanical_ventilation(option) { @@ -110,24 +113,22 @@ function require_natural_ventilation(option) { function require_air_changes(option) { require_input_field("#air_changes", option); + disable_input_field("#air_changes", option); } function require_air_supply(option) { require_input_field("#air_supply", option); + disable_input_field("#air_supply", option); } function require_single_event(option) { require_input_field("#single_event_date", option); -} - -function require_input_field(id, option) { - $(id).prop('required', option); - if (!option) - removeInvalid(id); + disable_input_field("#single_event_date", option); } function require_recurrent_event(option) { $("#recurrent_event_month").prop('required', option); + disable_input_field("#recurrent_event_month", option); } function require_lunch(option) { @@ -156,6 +157,20 @@ function require_mask(option) { function require_hepa(option) { require_input_field("#hepa_amount", option); + disable_input_field("#hepa_amount", option); +} + +function require_input_field(id, option) { + $(id).prop('required', option); + if (!option) + removeInvalid(id); +} + +function disable_input_field(id, option) { + if (option) + $(id).removeClass("disabled"); + else + $(id).addClass("disabled"); } function setMaxInfectedPeople() { @@ -382,8 +397,11 @@ $(document).ready(function () { // Call the function now to handle forward/back button presses in the browser. on_ventilation_type_change(); - //Same for lunch option + //Same for other options require_fields($("input[name='lunch_option']:checked")); + require_fields($("input[name='volume_type']:checked")); + require_fields($("input[name='mechanical_ventilation_type']:checked")); + require_fields($("input[name='hepa_option']:checked")); // Setup the maximum number of people at page load (to handle back/forward), // and update it when total people is changed. diff --git a/cara/apps/calculator/templates/calculator.form.html.j2 b/cara/apps/calculator/templates/calculator.form.html.j2 index 3a4705dc..c06cbf59 100644 --- a/cara/apps/calculator/templates/calculator.form.html.j2 +++ b/cara/apps/calculator/templates/calculator.form.html.j2 @@ -34,8 +34,8 @@
- Simulation name:
- Room number:
+ Simulation name:
+ Room number:

Room data:
@@ -43,12 +43,12 @@

   -
+
   -
+
         -
+

@@ -57,39 +57,39 @@ ?

Ventilation type: - +    - +    - +
HEPA filtration: - +    - +    - +
Face masks: @@ -97,14 +97,14 @@ ?
Are masks worn when occupants are at workstations? - +    - +
Type of masks used: - +    - +

@@ -116,12 +116,12 @@
?

- Total number of occupants:
- Number of infected people:
+ Total number of occupants:
+ Number of infected people:

- Activity type: @@ -130,11 +130,11 @@
- Start:    - Finish:
+ Start:    + Finish:
Infected person(s) presence:
- Start:    - Finish:
+ Start:    + Finish:

When is the event? @@ -144,10 +144,10 @@    -
+
- @@ -168,26 +168,26 @@ Lunch break:   - +    - +
- Start:    - Finish:
+ Start:    + Finish:
Coffee Breaks:   - +    - +    - +
- Duration (minutes): @@ -233,7 +233,7 @@ Refer to COVID Calculator user-guide for more detailed explanations on how to use this tool.
-



+