From 75ccf857ecf2b778991fea2dfbf15fd7d802f4be Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Thu, 28 Jul 2022 11:41:18 +0200 Subject: [PATCH 1/3] Handled coffee breaks duration #273 --- cara/apps/calculator/static/js/form.js | 23 +++++++++++++ .../templates/base/calculator.form.html.j2 | 34 +++++++++++-------- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index 26e72eea..568f2c45 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -287,6 +287,22 @@ function on_short_range_option_change() { }) } +function on_coffee_break_option_change() { + all_coffee_breaks = [$('input[type=radio][name=exposed_coffee_break_option]'), $('input[type=radio][name=infected_coffee_break_option]')]; + for (coffee_breaks of all_coffee_breaks) { + coffee_breaks.each(function() { + children = getChildElement($(this)); + if (this.checked && children.length) { + children.show(); + return false; + } + else { + children.hide(); + } + }) + } +} + /* -------UI------- */ function show_disclaimer() { @@ -743,6 +759,13 @@ $(document).ready(function () { // Call the function now to handle forward/back button presses in the browser. on_short_range_option_change(); + // When the coffee_break_option changes we want to make its respective + // children show/hide + $("input[type=radio][name=exposed_coffee_break_option]").change(on_coffee_break_option_change); + $("input[type=radio][name=infected_coffee_break_option]").change(on_coffee_break_option_change); + // Call the function now to handle forward/back button presses in the browser. + on_coffee_break_option_change(); + // Setup the maximum number of people at page load (to handle back/forward), // and update it when total people is changed. setMaxInfectedPeople(); diff --git a/cara/apps/templates/base/calculator.form.html.j2 b/cara/apps/templates/base/calculator.form.html.j2 index 3b494d0f..78d0114f 100644 --- a/cara/apps/templates/base/calculator.form.html.j2 +++ b/cara/apps/templates/base/calculator.form.html.j2 @@ -476,25 +476,27 @@
- - + + - +

- Duration (minutes): -
+
@@ -525,17 +527,18 @@
- + - +

+
From a5ce61c8dc2b98f1851fdd4736d3bebbba7836ec Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Fri, 29 Jul 2022 11:49:06 +0200 Subject: [PATCH 2/3] Hide lunch break time when option is no --- cara/apps/calculator/static/js/form.js | 20 ++++++++++-- .../templates/base/calculator.form.html.j2 | 32 +++++++++++-------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index 568f2c45..655ff5ac 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -160,8 +160,6 @@ function require_lunch(id, option) { require_input_field(startID, option); require_input_field(finishID, option); - set_disabled_status(startID, !option); - set_disabled_status(finishID, !option); if (!option) { $(finishID).removeClass("red_border finish_time_error lunch_break_error"); @@ -287,6 +285,17 @@ function on_short_range_option_change() { }) } +function on_lunch_break_option_change() { + all_lunch_breaks = [$('input[type=radio][name=exposed_lunch_option]'), $('input[type=radio][name=infected_lunch_option]')]; + for (lunch_break of all_lunch_breaks) { + lunch_break.each(function() { + children = getChildElement($(this)); + this.checked ? children.show() : children.hide(); + require_fields(this); + }) + } +} + function on_coffee_break_option_change() { all_coffee_breaks = [$('input[type=radio][name=exposed_coffee_break_option]'), $('input[type=radio][name=infected_coffee_break_option]')]; for (coffee_breaks of all_coffee_breaks) { @@ -759,6 +768,13 @@ $(document).ready(function () { // Call the function now to handle forward/back button presses in the browser. on_short_range_option_change(); + // When a lunch_option changes we want to make its respective children + // to show/hide + $("input[type=radio][name=exposed_lunch_option]").change(on_lunch_break_option_change); + $("input[type=radio][name=infected_lunch_option]").change(on_lunch_break_option_change); + // Call the function now to handle forward/back button presses in the browser. + on_lunch_break_option_change(); + // When the coffee_break_option changes we want to make its respective // children show/hide $("input[type=radio][name=exposed_coffee_break_option]").change(on_coffee_break_option_change); diff --git a/cara/apps/templates/base/calculator.form.html.j2 b/cara/apps/templates/base/calculator.form.html.j2 index 78d0114f..2c9cb081 100644 --- a/cara/apps/templates/base/calculator.form.html.j2 +++ b/cara/apps/templates/base/calculator.form.html.j2 @@ -452,21 +452,25 @@
-
+
- Lunch break: - - - -
+
Lunch break:
- Start: + + + +
-
- Finish:
+
+
+ Start: +
+
+ Finish:
+
@@ -501,21 +505,21 @@
-
+
Infected person(s) breaks:
Lunch break: - +
-
+
- Start: + Start:
- Finish:
+ Finish:
From de2bb5fd37bb48d36e386180fb6c3e11f7f0caa7 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Fri, 12 Aug 2022 16:17:51 +0100 Subject: [PATCH 3/3] handled radio button positions and mobile version for the breaks --- .../templates/base/calculator.form.html.j2 | 119 +++++++++--------- 1 file changed, 62 insertions(+), 57 deletions(-) diff --git a/cara/apps/templates/base/calculator.form.html.j2 b/cara/apps/templates/base/calculator.form.html.j2 index 2c9cb081..0329d845 100644 --- a/cara/apps/templates/base/calculator.form.html.j2 +++ b/cara/apps/templates/base/calculator.form.html.j2 @@ -452,17 +452,17 @@

-
+
-
Lunch break:
-
- - - -
-
+
Lunch break:
+
+ + + +
+
@@ -475,45 +475,48 @@
-
- Coffee Breaks: +
Coffee Breaks:
+
+ + + + + +
+
-
- - - - - -
-
-
-
-

-
+
Infected person(s) breaks:
- Lunch break: - - - -
- +
+
Lunch break:
+
+ + + +
+
+
Start: @@ -525,31 +528,33 @@
-
- Coffee Breaks: -
-
- - - - - -
-
+
Coffee Breaks:
+
+ + + + + +
+