Added check that break time < activity time

This commit is contained in:
gaazzopa 2020-11-18 23:20:05 +01:00
parent cd4d8e5d4e
commit 3ebef5b5b4
2 changed files with 33 additions and 2 deletions

View file

@ -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

View file

@ -163,7 +163,7 @@
</select><br>
<hr width="80%">
<b>Activity breaks:</b><br>
<span id="activity_breaks"><b>Activity breaks:</b></span><br>
<!-- Lunch Options -->
Lunch break:&nbsp;&nbsp;
<input type="radio" id="lunch_option_no" name="lunch_option" value=0 onclick="require_fields(this)" tabindex="0">
@ -231,7 +231,7 @@
Refer to <a href="/calculator/user-guide"> COVID Calculator user-guide </a> for more detailed explanations on how to use this tool. <br>
</div>
<button type='submit' tabindex="0">Generate report</button><br><br><br><br>
<button type='submit' id="generate_report" tabindex="0">Generate report</button><br><br><br><br>
</form>
<!-- Dialog boxes -->