-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
210 lines (179 loc) · 5.69 KB
/
script.js
File metadata and controls
210 lines (179 loc) · 5.69 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
var $TABLE = $('#table');
var $BTN = $('#export-btn');
var $EXPORT = $('#export');
// var $SUBMIT = $('#submit-btn')
var $SUBMIT = $('#submit-btn')
$('.table-add').click(function() {
var $clone = $TABLE.find('tr.hide').clone(true).removeClass('hide table-line');
$TABLE.find('table').append($clone);
});
$('.table-remove').click(function() {
$(this).parents('tr').detach();
});
$('.table-up').click(function() {
var $row = $(this).parents('tr');
if ($row.index() === 1) return; // Don't go above the header
$row.prev().before($row.get(0));
});
$('.table-down').click(function() {
var $row = $(this).parents('tr');
$row.next().after($row.get(0));
});
// A few jQuery helpers for exporting only
jQuery.fn.pop = [].pop;
jQuery.fn.shift = [].shift;
$BTN.click(function() {
var $rows = $TABLE.find('tr:not(:hidden)');
var headers = [];
var data = [];
var email = $("#email-input").val();
if (email == "") {
alert("Please enter your email id");
return;
}
var reeamil = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,6})?$/;
if (!reeamil.test(email)) {
alert("Please enter valid email address");
return;
}
data.push({ "Email": email })
var refloat = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
$("tr:not(.hide) td#buying-price").each(function() {
let val = $(this).text();
if (val == "") {
alert("Please enter your stock buying price");
location.reload([true])
return;
}
if (!refloat.test(val)) {
alert("Please enter valid price");
location.reload([true]);
return;
}
console.log(val)
});
$("tr:not(.hide) td#percent").each(function() {
let val = $(this).text();
if (val == "") {
alert("Please enter your notice percent");
location.reload([true])
return;
}
if (!refloat.test(val)) {
alert("Please enter valid percent");
location.reload([true]);
return;
}
console.log(val)
});
// Get the headers (add special header logic here)
$($rows.shift()).find('th:not(:empty)').each(function() {
headers.push($(this).text().split(" ")[0]);
});
// Turn all existing rows into a loopable array
$rows.each(function() {
var $td = $(this).find('td');
var h = {};
// Use the headers from earlier to name our hash keys
headers.forEach(function(header, i) {
if (i == 0 | i == 2) {
h[header] = $td.eq(i).find('select').val();
} else {
h[header] = $td.eq(i).text();
}
});
data.push(h);
});
var data_json = {
"Email": data[0]["Email"],
"Information": data.slice(1)
}
// Output the result
$EXPORT.text(JSON.stringify(data_json));
});
$SUBMIT.click(function() {
var $rows = $TABLE.find('tr:not(:hidden)');
var headers = [];
var data = [];
var email = $("#email-input").val();
if (email == "") {
alert("Please enter your email id");
return;
}
var reeamil = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,6})?$/;
if (!reeamil.test(email)) {
alert("Please enter valid email address");
return;
}
data.push({ "Email": email })
var refloat = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
$("tr:not(.hide) td#buying-price").each(function() {
let val = $(this).text();
if (val == "") {
alert("Please enter your stock buying price");
location.reload([true])
return;
}
if (!refloat.test(val)) {
alert("Please enter valid price");
location.reload([true]);
return;
}
console.log(val)
});
$("tr:not(.hide) td#percent").each(function() {
let val = $(this).text();
if (val == "") {
alert("Please enter your notice percent");
location.reload([true])
return;
}
if (!refloat.test(val)) {
alert("Please enter valid percent");
location.reload([true]);
return;
}
console.log(val)
});
// Get the headers (add special header logic here)
$($rows.shift()).find('th:not(:empty)').each(function() {
headers.push($(this).text().split(" ")[0]);
});
// Turn all existing rows into a loopable array
$rows.each(function() {
var $td = $(this).find('td');
var h = {};
// Use the headers from earlier to name our hash keys
headers.forEach(function(header, i) {
if (i == 0 | i == 2) {
h[header] = $td.eq(i).find('select').val();
} else {
h[header] = $td.eq(i).text();
}
});
data.push(h);
});
var data_json = {
"Email": data[0]["Email"],
"Information": data.slice(1)
}
$.ajax({
type: "POST",
// url: "https://qjhw6kk28f.execute-api.us-east-2.amazonaws.com/1/teach",
url: "https://nt2ytxwlx7.execute-api.us-east-2.amazonaws.com/test3/stock-monitor",
dataType: "json",
crossDomain: "true",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(data_json),
success: function() {
// clear form and show a success message
alert("Successfull");
document.getElementById("contact-form").reset();
location.reload();
},
error: function() {
// show an error message
alert("UnSuccessfull");
}
});
});