-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSWave.js
111 lines (102 loc) · 3.56 KB
/
JSWave.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*jshint esversion: 6 */
/*global console*/
$(function () {
"use strict";
function isNumeric(n){
let x = !isNaN(parseFloat(n)) && isFinite(n);
console.log(x);
return x;
}
function validateX(){
if ($('.x-checkbox').is(':checked')){
$('xbox-label').removeClass('box-error');
return true;
} else {
$('xbox-label').addClass('box-error');
return false;
}
}
function validateY(){
const Y_MAX = 3;
const Y_MIN = -3;
let yField = $('#y-value');
let numY = yField.val().replace(',','.');
if (isNumeric(numY) && numY >= Y_MIN && numY <= Y_MAX){
yField.removeClass('text-error');
return true;
} else {
yField.addClass('text-error');
return false;
}
}
function validateR(){
const R_MAX = 5;
const R_MIN = 2;
let rField = $('#r-value');
let numR = rField.val().replace(',', '.');
if (isNumeric(numR) && numR >= R_MIN && numR <= R_MAX){
rField.removeClass('text-error');
return true;
} else {
rField.addClass('text-error');
return false;
}
}
function validateForm(){
console.log("Validating...");
return validateR() && validateX() && validateY();
}
$(".x-checkbox").change(function (){
$(".x-checkbox").prop('checked', false);
$(this).prop('checked', true);
$(".x-checkbox").not(this).prop('checked', false);
});
$('#inputForm').on('reset', function (event){
event.preventDefault();
localStorage.clear();
const rows = document.querySelectorAll(".resultRow");
$("#resultTable tbody tr").remove();
});
$('#inputForm').on('submit', function(event) {
event.preventDefault();
let timeZoneOffset = new Date().getTimezoneOffset();
if(!validateForm()) {
return;
}
$.ajax({
url: 'script.php',
type: 'POST',
data: $(this).serialize() + '&timezone=' + timeZoneOffset,
dataType: "json",
beforeSend: function(){
$('#submit-button').attr('disabled','disabled');
console.log(this.data);
},
error : function(error) {
console.log("exception",error);
},
success: function(data){
console.log("sent");
$('#submit-button').attr('disabled',false);
console.log(data);
let newRow;
if (data.validate) {
newRow = '<tr>';
newRow += '<td>' + data.xval + '</td>';
newRow += '<td>' + data.yval + '</td>';
newRow += '<td>' + data.rval + '</td>';
newRow += '<td>' + data.cTime + '</td>';
newRow += '<td>' + data.exTime + '</td>';
newRow += '<td>' + data.hitRes + '</td>';
const table = $('#resultTable tbody').append(newRow);
table.find('td').addClass("resultRow");
let key = localStorage.length+1;
localStorage.setItem(key.toString(), newRow);
}
}
});
});
});
for (let i = 1; i <= localStorage.length; i++){
$('#resultTable').append(localStorage.getItem(i.toString()));
}