-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
285 lines (262 loc) · 9.89 KB
/
index.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
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html>
<html>
<head>
<title>Updox UI Challenge</title>
<style>
#content{
background-color: #989898;
position: absolute;
width:700px;
height:600px;
}
#create-provider-form{
float:left;
border-radius: 25px;
background: #FFF;
padding: 10px;
width: 305px;
height: 150px;
margin: 30px 0 30px 15px;
overflow-x: hidden;
}
#create-provider-form input{
float:left;
margin-bottom:2px;
}
#validation-message{
display: none;
float:right;
border-radius: 25px;
background: #FFF;
padding: 10px;
width: 205px;
height: 150px;
margin: 30px 80px 30px 0;
overflow-x: hidden;
}
#provider-list{
float:left;
border-radius: 25px;
background: #FFF;
padding: 20px;
width: 625px;
height: 250px;
margin: 30px 15px 30px 15px;
overflow: hidden;
}
#provider-table{
border-collapse:collapse;
border:1px solid #323252;
width:625px;
height: 225px;
margin: 5px 5px 5px 5px;
overflow-y: scroll;
}
#provider-table tr:nth-child(even) {
background-color: #989898;
}
#provider-table td{
border:1px solid #323252;
}
.provider-checkbox{
width: 10%;
text-align:center;
}
.provider-data{
width: 90%;
}
.name-entry{
font-size: 16px;
font-weight: bold;
float: left;
clear:left;
margin: 2px 0 0 5px;
}
.email-entry{
font-size: 10px;
float:left;
clear:left;
margin: 1px 5px 5px 5px
}
.practice-entry{
font-size: 10px;
float:right;
clear:right;
margin: 2px 5px 5px 0;
}
.specialty-entry{
font-size: 10px;
float: right;
clear:right;
margin: 1px 5px 0 0;
}
.buttons {
float:left;
border: 0;
border-radius: 0;
background: #323252;
width: 100px;
color: #FFF;
}
.error {
/*display: none;*/
color: #FF0000;
font-size: 16px;
font-weight: bold;
float:left;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
var data = {"[email protected]":{"last_name": "Harris", "first_name": "Mike", "email_address": "[email protected]", "specialty": "Pediatrics", "practice_name": "Harris Pediatrics"},"[email protected]":{"last_name": "Wijoyo", "first_name": "Bimo", "email_address": "[email protected]", "specialty": "Podiatry", "practice_name": "Wijoyo Podiatry"}, "[email protected]":{"last_name": "Rose", "first_name": "Nate", "email_address": "[email protected]", "specialty": "Surgery", "practice_name": "Rose Cutters"},"[email protected]":{"last_name": "Carlson", "first_name": "Mike", "email_address": "[email protected]", "specialty": "Orthopedics", "practice_name": "Carlson Orthopedics"}, "[email protected]":{"last_name": "Witting", "first_name": "Mike", "email_address": "[email protected]", "specialty": "Pediatrics", "practice_name": "Witting’s Well Kids Pediatrics"}, "[email protected]":{"last_name": "Juday", "first_name": "Tobin", "email_address": "[email protected]", "specialty":"General Medicine", "practice_name": "Juday Family Practice"}};
var updateTable = function(){
$("#provider-table").empty();
$("#provider-table").html(buildTable());
}
var buildTable = function(){
console.log(data);
var rows = "";
for(var entry in data){
rows += "<tr><td class=\"provider-checkbox\"><input type=\"checkbox\" id=\""+data[entry]["email_address"]+"-check\"/></td>";
rows += "<td class=\"provider-data\"><span class=\"name-entry\">"+data[entry]["last_name"]+", "+data[entry]["first_name"]+"</span>";
rows += "<span class=\"specialty-entry\">"+data[entry]["specialty"]+"</span>";
rows += "<span class=\"email-entry\">"+data[entry]["email_address"]+"</span>";
rows += "<span class=\"practice-entry\">"+data[entry]["practice"]+"</span>";
rows += "</td></tr>";
}
return rows;
}
var validate = function(){
if ($("#lastname").text().length > 2 &&
$("#firstname").text().length > 2 &&
testEmail($( "#email" ).text())){
if(!data.hasOwnProperty($( "#email" ).text())){
add();
}
} else {
console.log("else");
$("#lastname").trigger("blur");
$("#firstname").trigger("blur");
$("email").trigger("blur");
}
}
var isEmpty = function( el ){
return !$.trim(el.html())
}
var email_not_valid_html = "<span class=\"error\" class=\"email-not-valid-error\">Enter in a valid email address</span>";
var email_already_in_use_html = "<span class=\"error\" class=\"email-already-in-use-error\">Email already in use</span>";
var lastname_not_valid_html = "<span class=\"error\" class=\"lname-not-valid-error\">Last name must be more than 2 characters</span>";
var firstname_not_valid_html = "<span class=\"error\" class=\"fname-not-valid-error\">First name must be more than 2 characterss</span>"
var testEmail = function(email){
var regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return regex.test(email);
}
var add = function(){
var fname = $("#firstname").val();
var lname = $("#lastname").val();
var email = $("#email").val();
var special = $("#specialty").val();
var practice = $("#practice").val();
data[email] = {};
data[email].first_name = fname;
data[email].last_name = lname;
data[email].email = email;
data[email].special = special;
data[email].practice = practice;
updateTable();
}
$(document).ready(function () {
updateTable();
$("#lastname").focusout(function(){
if($("#lastname").val() < 3 && $(".lname-not-valid-error").length === 0){
$("#validation-message").show();
$("#validation-message").append(lastname_not_valid_html);
$("#submit_btn").attr('disabled','disabled');
} else {
$(".lname-not-valid-error").remove();
if(isEmpty($("#validation-message"))){
$("#validation-message").hide();
$("input[type=submit]").removeAttr('disabled');
}
}
});
$("#firstname").focusout(function(){
if($("#firstname").val() < 3 && $(".fname-not-valid-error").length === 0){
$("#validation-message").show();
$("#validation-message").append(firstname_not_valid_html);
$("#submit_btn").attr('disabled','disabled');
} else {
$(".fname-not-valid-error").remove();
if(isEmpty($("#validation-message"))){
$("#validation-message").hide();
$("input[type=submit]").removeAttr('disabled');
}
}
});
$("#email").focusout(function(){
if(!testEmail($( "#email" ).val()) && $(".email-not-valid-error").length === 0){
$("#validation-message").show();
$("#validation-message").append(email_not_valid_html);
$("#submit_btn").attr('disabled','disabled');
} else {
if(data.hasOwnProperty($( "#email" ).val())){
$("#validation-message").show();
$("#validation-message").append(email_already_in_use_html);
$("#submit_btn").attr('disabled','disabled');
} else {
$(".email-not-valid-error").remove();
$(".email-already-in-use-error").remove();
if(isEmpty($("#validation-message"))){
$("#validation-message").hide();
$("input[type=submit]").removeAttr('disabled');
}
}
}
});
});
</script>
</head>
<body>
<div id="content">
<div id="create-provider-form">
<span>Create Provider </span>
<form action="#" onsubmit="validate()" id="search_form" >
<input type="text" id="lastname" name="l_name" placeholder="Last Name"/>
<input type="text" id="firstname" name="f_name" placeholder="First Name"/>
<input type="text" id="email" name="email" placeholder="Email"/>
<input type="text" id="specialty" name="specialty" placeholder="Specialty"/>
<input type="text" id="practice" name="practice" placeholder="Practice"/>
<input type="submit" id="submit_btn" class="buttons" value="Create"/>
</form>
</div>
<div id="validation-message">
</div>
<div id="provider-list">
<table id="provider-table">
<tr>
<td class="provider-checkbox">
<input type="checkbox" id="[email protected]"/>
</td>
<td class="provider-data">
<span class="name-entry">Last Name, First Name</span>
<span class="specialty-entry">Specialty</span>
<span class="email-entry">Email Address</span>
<span class="practice-entry">Practice</span>
</td>
</tr>
<tr>
<td class="provider-checkbox">
<input type="checkbox" id="[email protected]"/>
</td>
<td class="provider-data">
<span class="name-entry">Last Name, First Name</span>
<span class="specialty-entry">Specialty</span>
<span class="email-entry">Email Address</span>
<span class="practice-entry">Practice</span>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>