forked from hr-john/elektrilevi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hobu.html
138 lines (120 loc) · 5.32 KB
/
hobu.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html lang="et-EE">
<head>
<TITLE>
Koolisõidu protokoll
</TITLE>
<style>
body {
// background-image: url("https://hr-john.github.io/elektrilevi/ressources/horse.jpg") ;
// background-size: cover;
}
</style>
<script>
function display(msg) {
var p = document.createElement('p');
p.innerHTML = String(msg);
document.body.appendChild(p);
}
function loe(){
var container = document.getElementById("SKEEM"),
cTable = document.createElement("table");
cTable.setAttribute('border', '1');
cTable.id = "SKEEM";
container.innerHTML = "";
container.appendChild(cTable);
var cRow = document.createElement("tr"),
cCell = null, cHinne = null,
headline = ["Nr", "", "Harjutus", "Hinne", "K", "Kokku", "Direktiivid","Kommentaarid"];
cRow.classList.add("head");
for (var d of headline) {
cCell = document.createElement("th");
cCell.innerHTML = d;
cRow.appendChild(cCell);
}
cTable.appendChild(cRow);
var skeemif = new XMLHttpRequest(), fnimi=document.forms[0].file.value;
skeemif.onreadystatechange = handleStateChange;
skeemif.open('GET', 'https://hr-john.github.io/elektrilevi/hobu/'+fnimi);
skeemif.send();
function handleStateChange() {
if (skeemif.readyState == 4 &&
skeemif.status >= 200 &&
skeemif.status < 300) {
insertTable(skeemif.responseText);
}
} // handleStateChange
function csvToArray(text) {
let p = '', row = [''], ret = [row], i = 0, r = 0, s = !0, l;
for (l of text) {
if ('"' === l) {
if (s && l === p) row[i] += l;
s = !s;
} else // if (',' === l && s) l = row[++i] = '';
// else
if ('\n' === l && s) {
if ('\r' === p) row[i] = row[i].slice(0, -1);
row = ret[++r] = [l = '']; i = 0;
} else row[i] += l;
p = l;
} //for l to text
return ret;
}; // csvToArray
function insertTable(data) {
// var rows = data.split(/\s+/); var rows = data.split("\n");
var nr=[],mark=[],harjutus=[],koefitsent=[],direktiiv=[],rowspan=[] ;
var rows = csvToArray(data);
var rowNum,reanr=1,ridu=0;
var cells; // var cellNum;
for (rowNum = 0; rowNum < rows.length-1; ++rowNum) {
cells = rows[rowNum][0].split(";") ;
nr.push(cells[0]);mark.push(cells[1]);harjutus.push(cells[2]);koefitsent.push(cells[3]);direktiiv.push(cells[4]);
if ( reanr === nr[nr.length-1] ) { ridu++ }
else { rowspan[reanr]=ridu+1; ridu=0 ; reanr = cells[0]; }
}// for rowNum
rowspan[reanr]=ridu+1;
var total = rowNum;
// alert("NR " + rowspan[1] + " "+ rowspan[2] + " " + rowspan[3]);
for (var i=0; i<total; i++) {
cCell = document.createElement("td");
cCell.rowspan=rowspan[nr[i]] ;
// cCell.classList.add("hinne");
cCell.innerHTML="<INPUT TYPE='text' size='3' MAXLENGTH='3'>" ;
cRow = document.createElement("tr");
cRow.classList.add("sisu");
// cRow.appendChild(cCell);
// cRow.innerHTML = (rowspan[nr[i]]>0?"<TD rowspan=\""+rowspan[nr[i]]+"\">"+nr[i]+"</TD><TD>"+mark[i]+"</TD><TD>"+harjutus[i]+"</TD><TD rowspan=\""+rowspan[nr[i]]+"\">"+"<INPUT class='hinne' TYPE='text' size='3' MAXLENGTH='3'>"+"</TD><TD><DIV class='koef'>"+koefitsent[i]+"</DIV></TD><TD><div class='lopphinne'>LOPPHINNE</div></TD><TD>"+direktiiv[i]+"</TD><TD rowspan=\""+rowspan[nr[i]]+"\"><TEXTAREA rows=\""+rowspan[nr[i]]+"\">KOMMENTAAR</TEXTAREA></TD>":
cRow.innerHTML = (rowspan[nr[i]]>0?"<TD rowspan=\""+rowspan[nr[i]]+"\">"+nr[i]+"</TD><TD>"+mark[i]+"</TD><TD>"+harjutus[i]+"</TD><div class='hinne'></div><TD><DIV class='koef'>"+koefitsent[i]+"</DIV></TD><TD><div class='lopphinne'>LOPPHINNE</div></TD><TD>"+direktiiv[i]+"</TD><TD rowspan=\""+rowspan[nr[i]]+"\"><TEXTAREA rows=\""+rowspan[nr[i]]+"\">KOMMENTAAR</TEXTAREA></TD>":
"<TD>"+mark[i]+"</TD><TD>"+harjutus[i]+"</TD><TD>"+koefitsent[i]+"</TD><TD>"+""+"</TD><TD>"+direktiiv[i]+"</TD>");
cRow.addEventListener("change", function(){
alert(this.getElementsByClassName("lopphinne")[0].innerHTML = this.getElementsByClassName("hinne")[0].value * this.getElementsByClassName("koef")[0].innerHTML);
});
rowspan[nr[i]]=0;
cTable.appendChild(cRow);
cRow.getElementsByClassName("hinne")[0]=cCell;
// cHinne.appendChild(cCell);
} // for i to total
cRow = document.createElement("tr");
cRow.classList.add("lopp");
cRow.innerHTML = ("<TD></TD><TD></TD><TD>Lahkumine väljakult läbi A pika ratsmega</TD><TD></TD><TD></TD>");
cTable.appendChild(cRow);
// display(rowNum + " : " + cells[1] + " - " + cells[2]);
}; // insertTable
}; // loe
</script>
</head>
<body>
<H1>TERE READING</H1>
<FORM>
<SELECT id="file" name="file">
<OPTION VALUE="st1.txt">ST1</OPTION>
<OPTION VALUE="ABC1.txt">ABC1</OPTION>
<OPTION VALUE="M1.txt">M1</OPTION>
<OPTION VALUE="LK2.txt">LK2</OPTION>
<OPTION VALUE="LK3.txt">LK3</OPTION>
<OPTION VALUE="A3.txt">A3</OPTION>
</SELECT>
<button type="button" onclick="loe()">LOE</button>
<div id="SKEEM"></div>
</body>
</html>