contact.js
13 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
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
$(function () {
function checkall(clickchk, relChkbox) {
var checker = $("#" + clickchk);
var multichk = $("." + relChkbox);
checker.click(function () {
multichk.prop("checked", $(this).prop("checked"));
$(".show-btn").toggle();
});
}
checkall("contact-check-all", "contact-chkbox");
$("#input-search").on("keyup", function () {
var rex = new RegExp($(this).val(), "i");
$(".search-table .search-items:not(.header-item)").hide();
$(".search-table .search-items:not(.header-item)")
.filter(function () {
return rex.test($(this).text());
})
.show();
});
$("#btn-add-contact").on("click", function (event) {
$("#addContactModal #btn-add").show();
$("#addContactModal #btn-edit").hide();
});
function deleteContact() {
$(".delete").on("click", function (event) {
event.preventDefault();
/* Act on the event */
$(this).parents(".search-items").remove();
});
}
function addContact() {
$("#btn-add").click(function () {
var getParent = $(this).parents(".modal-content");
var $_name = getParent.find("#c-name");
var $_email = getParent.find("#c-email");
var $_occupation = getParent.find("#c-occupation");
var $_phone = getParent.find("#c-phone");
var $_location = getParent.find("#c-location");
var $_getValidationField =
document.getElementsByClassName("validation-text");
var reg = /^.+@[^\.].*\.[a-z]{2,}$/;
var phoneReg = /^\d*\.?\d*$/;
var $_nameValue = $_name.val();
var $_emailValue = $_email.val();
var $_occupationValue = $_occupation.val();
var $_phoneValue = $_phone.val();
var $_locationValue = $_location.val();
if ($_nameValue == "") {
$_getValidationField[0].innerHTML = "Name must be filled out";
$_getValidationField[0].style.display = "block";
} else {
$_getValidationField[0].style.display = "none";
}
if ($_emailValue == "") {
$_getValidationField[1].innerHTML = "Email Id must be filled out";
$_getValidationField[1].style.display = "block";
} else if (reg.test($_emailValue) == false) {
$_getValidationField[1].innerHTML = "Invalid Email";
$_getValidationField[1].style.display = "block";
} else {
$_getValidationField[1].style.display = "none";
}
if ($_phoneValue == "") {
$_getValidationField[2].innerHTML = "Invalid (Enter 10 Digits)";
$_getValidationField[2].style.display = "block";
} else if (phoneReg.test($_phoneValue) == false) {
$_getValidationField[2].innerHTML = "Please Enter A numeric value";
$_getValidationField[2].style.display = "block";
} else {
$_getValidationField[2].style.display = "none";
}
if (
$_nameValue == "" ||
$_emailValue == "" ||
reg.test($_emailValue) == false ||
$_phoneValue == "" ||
phoneReg.test($_phoneValue) == false
) {
return false;
}
var today = new Date();
var dd = String(today.getDate()).padStart(2, "0");
var mm = String(today.getMonth()); //January is 0!
var time = String(today.getTime());
var yyyy = today.getFullYear();
var monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
today = dd + " " + monthNames[mm] + " " + yyyy;
var cdate = dd + mm + time;
$html =
'<tr class="search-items">' +
'<td class="p-4 ps-0 whitespace-nowrap">' +
'<div class="n-chk align-self text-center">' +
'<div class="form-check">' +
'<input type="checkbox" class="form-check-input rounded-sm contact-chkbox" id="' +
cdate +
'">' +
'<label class="form-check-label" for="' +
cdate +
'"></label>' +
"</div>" +
"</div>" +
"</td>" +
'<td class="p-4 ps-0 whitespace-nowrap">' +
'<div class="flex items-center">' +
'<img src="../assets/images/profile/user-1.jpg" alt="avatar" class="rounded-circle h-9 w-9 rounded-full">' +
'<div class="ms-3">' +
'<div class="user-meta-info">' +
'<h6 class="font-semibold text-sm text-dark dark:text-white user-name" data-name=' +
$_nameValue +
">" +
$_nameValue +
"</h6>" +
'<span class="text-xs text-bodytext dark:text-darklink user-work" data-occupation=' +
$_occupationValue +
">" +
$_occupationValue +
"</span>" +
"</div>" +
"</div>" +
"</div>" +
"</td>" +
'<td class="text-sm whitespace-nowrap text-bodytext dark:text-darklink p-4">' +
'<span class="usr-email-addr" data-email=' +
$_emailValue +
">" +
$_emailValue +
"</span>" +
"</td>" +
'<td class="text-sm whitespace-nowrap text-bodytext dark:text-darklink p-4">' +
'<span class="usr-location" data-location=' +
$_locationValue +
">" +
$_locationValue +
"</span>" +
"</td>" +
'<td class="text-sm whitespace-nowrap text-bodytext dark:text-darklink p-4">' +
'<span class="usr-ph-no" data-phone=' +
$_phoneValue +
">" +
$_phoneValue +
"</span>" +
"</td>" +
'<td class="text-sm whitespace-nowrap text-bodytext dark:text-darklink p-4">' +
'<div class="action-btn flex gap-3">' +
'<a href="javascript:void(0)" class="text-info edit"><i class="ti ti-eye text-lg"></i></a>' +
'<a href="javascript:void(0)" class="text-dark delete"><i class="ti ti-trash text-lg text-bodytext dark:text-darklink"></i></a>' +
"</div>" +
"</td>" +
"</tr>";
$(".search-table > tbody >tr:first").before($html);
HSOverlay.close("#addContactModal");
var $_setNameValueEmpty = $_name.val("");
var $_setEmailValueEmpty = $_email.val("");
var $_setOccupationValueEmpty = $_occupation.val("");
var $_setPhoneValueEmpty = $_phone.val("");
var $_setLocationValueEmpty = $_location.val("");
deleteContact();
editContact();
checkall("contact-check-all", "contact-chkbox");
});
}
function editContact() {
$(".edit").on("click", function (event) {
$("#c #btn-add").hide();
$("#addContactModal #btn-edit").show();
// Get Parents
var getParentItem = $(this).parents(".search-items");
var getModal = $("#addContactModal");
// Get List Item Fields
var $_name = getParentItem.find(".user-name");
var $_email = getParentItem.find(".usr-email-addr");
var $_occupation = getParentItem.find(".user-work");
var $_phone = getParentItem.find(".usr-ph-no");
var $_location = getParentItem.find(".usr-location");
// Get Attributes
var $_nameAttrValue = $_name.attr("data-name");
var $_emailAttrValue = $_email.attr("data-email");
var $_occupationAttrValue = $_occupation.attr("data-occupation");
var $_phoneAttrValue = $_phone.attr("data-phone");
var $_locationAttrValue = $_location.attr("data-location");
// Get Modal Attributes
var $_getModalNameInput = getModal.find("#c-name");
var $_getModalEmailInput = getModal.find("#c-email");
var $_getModalOccupationInput = getModal.find("#c-occupation");
var $_getModalPhoneInput = getModal.find("#c-phone");
var $_getModalLocationInput = getModal.find("#c-location");
// Set Modal Field's Value
var $_setModalNameValue = $_getModalNameInput.val($_nameAttrValue);
var $_setModalEmailValue = $_getModalEmailInput.val($_emailAttrValue);
var $_setModalOccupationValue = $_getModalOccupationInput.val(
$_occupationAttrValue
);
var $_setModalPhoneValue = $_getModalPhoneInput.val($_phoneAttrValue);
var $_setModalLocationValue =
$_getModalLocationInput.val($_locationAttrValue);
HSOverlay.open("#addContactModal");
$("#btn-edit").click(function () {
var getParent = $(this).parents(".modal-content");
var $_getInputName = getParent.find("#c-name");
var $_getInputNmail = getParent.find("#c-email");
var $_getInputNccupation = getParent.find("#c-occupation");
var $_getInputNhone = getParent.find("#c-phone");
var $_getInputNocation = getParent.find("#c-location");
var $_nameValue = $_getInputName.val();
var $_emailValue = $_getInputNmail.val();
var $_occupationValue = $_getInputNccupation.val();
var $_phoneValue = $_getInputNhone.val();
var $_locationValue = $_getInputNocation.val();
var setUpdatedNameValue = $_name.text($_nameValue);
var setUpdatedEmailValue = $_email.text($_emailValue);
var setUpdatedOccupationValue = $_occupation.text($_occupationValue);
var setUpdatedPhoneValue = $_phone.text($_phoneValue);
var setUpdatedLocationValue = $_location.text($_locationValue);
var setUpdatedAttrNameValue = $_name.attr("data-name", $_nameValue);
var setUpdatedAttrEmailValue = $_email.attr("data-email", $_emailValue);
var setUpdatedAttrOccupationValue = $_occupation.attr(
"data-occupation",
$_occupationValue
);
var setUpdatedAttrPhoneValue = $_phone.attr("data-phone", $_phoneValue);
var setUpdatedAttrLocationValue = $_location.attr(
"data-location",
$_locationValue
);
HSOverlay.close("#addContactModal");
});
});
}
$(".delete-multiple").on("click", function () {
var inboxCheckboxParents = $(".contact-chkbox:checked").parents(
".search-items"
);
inboxCheckboxParents.remove();
});
deleteContact();
addContact();
editContact();
});
// Validation Process
var $_getValidationField = document.getElementsByClassName("validation-text");
var reg = /^.+@[^\.].*\.[a-z]{2,}$/;
var phoneReg = /^\d{10}$/;
getNameInput = document.getElementById("c-name");
getNameInput.addEventListener("input", function () {
getNameInputValue = this.value;
if (getNameInputValue == "") {
$_getValidationField[0].innerHTML = "Name Required";
$_getValidationField[0].style.display = "block";
} else {
$_getValidationField[0].style.display = "none";
}
});
getEmailInput = document.getElementById("c-email");
getEmailInput.addEventListener("input", function () {
getEmailInputValue = this.value;
if (getEmailInputValue == "") {
$_getValidationField[1].innerHTML = "Email Required";
$_getValidationField[1].style.display = "block";
} else if (reg.test(getEmailInputValue) == false) {
$_getValidationField[1].innerHTML = "Invalid Email";
$_getValidationField[1].style.display = "block";
} else {
$_getValidationField[1].style.display = "none";
}
});
getPhoneInput = document.getElementById("c-phone");
getPhoneInput.addEventListener("input", function () {
getPhoneInputValue = this.value;
if (getPhoneInputValue == "") {
$_getValidationField[2].innerHTML = "Phone Number Required";
$_getValidationField[2].style.display = "block";
} else if (phoneReg.test(getPhoneInputValue) == false) {
$_getValidationField[2].innerHTML = "Invalid (Enter 10 Digits)";
$_getValidationField[2].style.display = "block";
} else {
$_getValidationField[2].style.display = "none";
}
});