forked from BYUI-CIT-262/stedi-content
-
Notifications
You must be signed in to change notification settings - Fork 0
/
managecustomer.js
107 lines (90 loc) · 2.49 KB
/
managecustomer.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
//© 2021 Sean Murdock
let customerName = "";
let phone = "";
let bday = "";
let form = "";
let elements = "";
function setcustomername(){
customerName = $("#cn").val();
}
function setemail(){
email = $("#email").val();
}
function setphone(){
phone = $("#phone").val().replace(/\D+/g, "");
}
function setbday(){
bday = $("#bday").val();
}
function readonlyforms(formid){
form = document.getElementById(formid);
elements = form.elements;
for (i = 0, len = elements.length; i < len; ++i) {
elements[i].readOnly = true;
}
createbutton();
}
function pwsDisableInput( element, condition ) {
if ( condition == true ) {
element.disabled = true;
} else {
element.removeAttribute("disabled");
}
}
function createbutton(){
var button = document.createElement("input");
button.type = "button";
button.value = "OK";
button.onclick = window.location.href = "/index.html";
context.appendChild(button);
}
function findcustomer(email){
var headers = { "suresteps.session.token": localStorage.getItem("token")};
$.ajax({
type: 'GET',
url: `/customer/${email}`,
contentType: 'application/text',
dataType: 'text',
headers: headers,
success: function(data) {
localStorage.setItem("customer",data);
window.location.href="/timer.html";
}
});
}
function createcustomer(){
//in case they hit the back/forward buttons and our in memory variables got reset
setusername();
setuserpassword();
setverifypassword();
setcustomername();
setemail();
setphone();
setbday();
var customer = {
customerName : customerName,
email : email,
phone : phone,
birthDay: bday
}
$.ajax({
type: 'POST',
url: '/customer',
data: JSON.stringify(customer),
contentType: 'application/text',
dataType: 'text',
success: function(data) {
localStorage.setItem("customer",JSON.stringify(customer));
window.location.href=data
}
});
$.ajax({
type: 'POST',
url: '/user',
data: JSON.stringify({'userName':email, email, password, phone, "birthDate":bday, 'verifyPassword':verifypassword}),//we are using the email as the user name
success: function(data) { alert(data);
window.location.href = "/index.html"},
contentType: "application/text",
dataType: 'text'
});
}