-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
97 lines (85 loc) · 3.05 KB
/
script.js
File metadata and controls
97 lines (85 loc) · 3.05 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
$(document).ready(function() {
// Load the employees from the JSON file
$.getJSON("employees.json", function(employees) {
// Display the employees on the page
$("#employees").html("");
for (var i = 0; i < employees.length; i++) {
var employee = employees[i];
var html = "<p>" + employee.qid + " - " + employee.expiry_date + "</p>";
$("#employees").append(html);
}
});
// Add an employee to the JSON file
$("#add-employee-form").submit(function(event) {
event.preventDefault();
var qid = $("#add-employee-form input[name='qid']").val();
var expiry_date = $("#add-employee-form input[name='expiry_date']").val();
// Add the employee to the JSON file
$.ajax({
url: "employees.json",
type: "POST",
data: JSON.stringify({
qid: qid,
expiry_date: expiry_date
}),
contentType: "application/json",
success: function() {
// Reload the employees from the JSON file
$.getJSON("employees.json", function(employees) {
// Display the employees on the page
$("#employees").html("");
for (var i = 0; i < employees.length; i++) {
var employee = employees[i];
var html = "<p>" + employee.qid + " - " + employee.expiry_date + "</p>";
$("#employees").append(html);
}
});
}
});
});
// Edit an employee's expiry date
$("#employees p").click(function() {
var qid = $(this).text().split(" - ")[0];
// Open a modal dialog to edit the expiry date
$("#edit-employee-modal").modal("show");
// Set the QID of the employee to edit
$("#edit-employee-modal input[name='qid']").val(qid);
// Load the current expiry date of the employee
$.getJSON("employees.json", function(employees) {
var employee = employees.find(function(employee) {
return employee.qid === qid;
});
$("#edit-employee-modal input[name='expiry_date']").val(employee.expiry_date);
});
});
// Save the employee's expiry date
$("#edit-employee-modal form").submit(function(event) {
event.preventDefault();
var qid = $("#edit-employee-modal input[name='qid']").val();
var expiry_date = $("#edit-employee-modal input[name='expiry_date']").val();
// Update the employee's expiry date in the JSON file
$.ajax({
url: "employees.json",
type: "PUT",
data: JSON.stringify({
qid: qid,
expiry_date: expiry_date
}),
contentType: "application/json",
success: function() {
// Reload the employees from the JSON file
$.getJSON("employees.json", function(employees) {
// Display the employees on the page
$("#employees").html("");
for (var i = 0; i < employees.length; i++) {
var employee = employees[i];
var html = "<p>" + employee.qid + " - " + employee.expiry_date + "</p>";
$("#employees").append(html);
}
});
// Close the modal dialog
$("#edit-employee-modal").modal("hide");
}
});
});
});