-
Notifications
You must be signed in to change notification settings - Fork 2
/
manager.js
executable file
·174 lines (117 loc) · 5.54 KB
/
manager.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
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
/**
* TODO: Make request to http://www.fakemailgenerator.com/checkemail.php?u=joshuafisher&d=%40dayrep.com to check new emails
*/
var Manager = (function(){
managerElement = document.querySelector('#manager');
function Manager(){
if (localStorage['rows'] === undefined) {
localStorage['rows'] = JSON.stringify({});
}
this.refresh();
}
Manager.prototype.add = function(data) {
var parent = this;
var trElement = document.createElement('tr');
var emailAddressElement = document.createElement('td');
emailAddressElement.classList.add('left');
emailAddressElement.innerHTML = data.emailAddress;
var usernameElement = document.createElement('td');
usernameElement.classList.add('center');
usernameElement.innerHTML = data.username;
var passwordElement = document.createElement('td');
passwordElement.classList.add('center');
passwordElement.innerHTML = data.password;
var firstNameElement = document.createElement('td');
firstNameElement.classList.add('center');
firstNameElement.innerHTML = data.firstName;
var lastNameElement = document.createElement('td');
lastNameElement.classList.add('center');
lastNameElement.innerHTML = data.lastName;
var genderElement = document.createElement('td');
genderElement.classList.add('center');
genderElement.innerHTML = data.gender[0].toUpperCase() + data.gender.substr(1, data.gender.length);
var dateOfBirthElement = document.createElement('td');
dateOfBirthElement.classList.add('center');
dateOfBirthElement.innerHTML = data.dateOfBirthYear + '-' + data.dateOfBirthMonth + '-' + data.dateOfBirthDay;
var addressElement = document.createElement('td');
addressElement.classList.add('center');
addressElement.innerHTML = data.address;
var postcodeElement = document.createElement('td');
postcodeElement.classList.add('center');
postcodeElement.innerHTML = data.postcode;
var phoneNumberElement = document.createElement('td');
phoneNumberElement.classList.add('center');
phoneNumberElement.innerHTML = data.phoneNumber;
var countryElement = document.createElement('td');
countryElement.classList.add('center');
countryElement.innerHTML = data.country.toUpperCase();
var actionsElement = document.createElement('td');
actionsElement.classList.add('center');
var actionsRemoveElement = document.createElement('a');
actionsRemoveElement.classList.add('remove');
actionsRemoveElement.innerHTML = 'Remove';
actionsRemoveElement.href = '#';
actionsRemoveElement.addEventListener('click', function(){
return parent.remove.apply(parent, [this]);
});
var actionsSeparator = document.createTextNode(' | ');
var actionsEmailElement = document.createElement('a');
actionsEmailElement.classList.add('email');
actionsEmailElement.innerHTML = 'Email';
actionsEmailElement.target = '_blank';
actionsEmailElement.href = 'http://www.fakemailgenerator.com/?e=' + data.emailAddress;
// Append actions
actionsElement.appendChild(actionsEmailElement);
actionsElement.appendChild(actionsSeparator);
actionsElement.appendChild(actionsRemoveElement);
// Append elements
trElement.appendChild(emailAddressElement);
trElement.appendChild(usernameElement);
trElement.appendChild(passwordElement);
trElement.appendChild(firstNameElement);
trElement.appendChild(lastNameElement);
trElement.appendChild(genderElement);
trElement.appendChild(dateOfBirthElement);
trElement.appendChild(addressElement);
trElement.appendChild(postcodeElement);
trElement.appendChild(phoneNumberElement);
trElement.appendChild(countryElement);
trElement.appendChild(actionsElement);
managerElement.querySelector('tbody').appendChild(trElement);
};
Manager.prototype.refresh = function() {
var tbody = managerElement.querySelector('tbody');
tbody.innerHTML = '';
var rows = JSON.parse(localStorage['rows']);
if (Object.keys(rows).length > 0) {
for (var index in rows) {
this.add(rows[index]);
}
} else {
var trElement = document.createElement('tr');
var noResultsElement = document.createElement('td');
noResultsElement.colSpan = 8;
noResultsElement.classList.add('center');
noResultsElement.innerHTML = 'No Results';
trElement.appendChild(noResultsElement);
tbody.appendChild(trElement);
}
};
Manager.prototype.remove = function(element) {
var trElement = element.parentElement.parentElement,
tbodyElement = element.parentElement.parentElement.parentElement;
var rows = JSON.parse(localStorage['rows']);
for (var index in rows) {
if (index === 'length') {
continue;
}
if (trElement.children[0].innerText === rows[index].emailAddress) {
delete rows[index];
}
}
localStorage['rows'] = JSON.stringify(rows);
this.refresh();
};
return Manager;
})();
new Manager();