-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
91 lines (73 loc) · 2.24 KB
/
scripts.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
83
84
85
86
87
88
89
90
91
document.getElementById("submit").onclick = function() {submitForm()};
document.getElementById("clear").onclick = function() {clearTable()};
var table = document.getElementById("table").getElementsByTagName('tbody')[0];
var animateBut = document.getElementById("animate");
var process_array = [];
var pressedAnimate = false;
//SELECT ALGORITM
$("#select").change(function() {
if ($("#select").val() == "FCFS") {
$("#time").prop( "disabled", true )
} else if ($("#select").val() == "SJF") {
$("#time").prop( "disabled", false )
}
});
function submitForm() {
//VARIABLES
var process = document.getElementById("process").value;
var time = document.getElementById("time").value;
var spurta = document.getElementById("spurta").value;
var animateBut = document.getElementById("animate");
document.getElementById("process").value = '';
document.getElementById("time").value = '';
document.getElementById("spurta").value = '';
//FILL ARRAY
if (pressedAnimate == 0) {
process_array.push({
process: process,
time: time
});
} else if (pressedAnimate == 1) {
process_array = [];
process_array.push({
process: process,
time: time
});
process_array = false;
}
//INSERT INTO TABLE
var row = table.insertRow(table.rows.length);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = process;
cell2.innerHTML = time;
cell3.innerHTML = spurta;
animateButton(process_array);
}
// SORT
// array.sort(function(a, b){
// return a.y - b.y;
// });
function animateButton(array) {
var process_array = array;
// console.log(process_array);
animateBut.onclick = function() {
$("#table_animation").show()
var count = array.length;
pressedAnimate = true;
array.forEach(function(item,index,array) {
// console.log(count);
//FCFS RESULT ANIMATION
var row = document.getElementById("result");
var x = row.insertCell(array.length - count);
x.innerHTML = item.process;
count--;
});
};
}
function clearTable() {
table.remove();
$("#table_animation").hide();
$("#table_animation tr").empty();
}