-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
82 lines (77 loc) · 3.03 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function onSubmission()
{
//check that all mandatory fields are filled out
var elements = document.getElementById("form").elements;
if (document.getElementById("name").value == "" || document.getElementById("datetime").value == "" || document.getElementById("objectdescription").value == "" || document.getElementById("objectcolour").value == "" || document.getElementById("objectnumber").value == "" || (elements[5].checked == false && elements[6].checked == false) || document.getElementById("objectcondition").value == "" || document.getElementById("file").value == "")
{
alert("Not all required fields filled in. Please fill in the missing fields");
return;
}
document.getElementById("formdiv").style.display = 'none';
document.getElementById("waitdiv").style.display = 'inline';
//Fetch whether the user sees a defect or not
var visibleDefect = elements[5].checked;
//Random chance of a defect
var defect = 0;
var defectType = "";
if (Math.floor(Math.random()*100) > 60)
{
defect = 1;
}
if (visibleDefect == true)
{
defect = 1;
}
if (defect == 1)
{
//need to classify defect
var defectChance = Math.floor(Math.random()*100)
if ( defectChance > 66)
{
defectType = "Minor Defect - Unrepairable"
}
else if (defectChance > 33)
{
defectType = "Major Defect - Unrepairable"
}
else if (defectChance > 0)
{
defectType = "Repairable Defect"
}
}
else{
defectType = "Not Defective";
}
//Pause for a certian number of seconds
var x = 5000;
var adjustment = Math.floor(Math.random()*5000)+1-2500;
var x = x-adjustment;
setTimeout(function() {displayResult(defectType);}, x);
}
function startClassification()
{
document.getElementById("welcomediv").style.display = 'none';
document.getElementById("objectclassificationdiv").style.display = 'none';
resetForm();
document.getElementById("formdiv").style.display = 'inline';
}
function displayResult(defectType)
{
//activate object defect classified page
document.getElementById("waitdiv").style.display = 'none';
document.getElementById("objectclassificationdiv").style.display = 'inline';
document.getElementById("objectclassificationtext").innerHTML = defectType;
}
function resetForm()
{
document.getElementById("name").value = "";
document.getElementById("datetime").value = "";
document.getElementById("objectdescription").value = "";
document.getElementById("objectcolour").value = "";
document.getElementById("objectnumber").value = "";
var elements = document.getElementById("form").elements;
elements[5].checked = false;
elements[6].checked = false;
document.getElementById("objectcondition").value = "";
document.getElementById("file").value = "";
}