-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
175 lines (159 loc) · 5.97 KB
/
Copy pathscripts.js
File metadata and controls
175 lines (159 loc) · 5.97 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
$(document).ready(function () {
// ✅ Search Users
$("#searchUser").on("keyup", function () {
let value = $(this).val().toLowerCase();
$("#userTableBody tr").filter(function () {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
});
});
// ✅ Open Edit User Modal & Populate Fields
$(document).on("click", ".edit-user-btn", function () {
let userId = $(this).data("id");
let userName = $(this).data("name");
let userEmail = $(this).data("email");
let userRole = $(this).data("role");
$("#userId").val(userId);
$("#userName").val(userName);
$("#userEmail").val(userEmail);
$("#userRole").val(userRole);
$("#passwordField").hide(); // Hide password field when editing
$("#userModal").modal("show");
});
// ✅ Open Add New User Modal
$("#addUserBtn").click(function () {
$("#userForm")[0].reset(); // Clear form
$("#userId").val(""); // No user ID (new user)
$("#passwordField").show(); // Show password field for new users
$("#userModal").modal("show");
});
// ✅ Save User (Create/Edit)
$("#userForm").submit(function (e) {
e.preventDefault();
$.ajax({
url: "save_user.php",
type: "POST",
data: $("#userForm").serialize(),
success: function (response) {
alert(response.trim());
location.reload();
},
error: function () {
alert("Error processing request.");
}
});
});
// ✅ Delete User
$(document).on("click", ".delete-user-btn", function () {
let userId = $(this).data("id");
if (confirm("Are you sure you want to delete this user?")) {
$.post("delete_user.php", { id: userId }, function (response) {
alert(response.trim());
location.reload();
});
}
});
// ✅ Change Password
$(document).on("click", ".change-password-btn", function () {
let userId = $(this).data("id");
$("#changeUserId").val(userId);
$("#changePasswordModal").modal("show");
});
// ✅ Submit Change Password Form
$("#changePasswordForm").submit(function (e) {
e.preventDefault();
$.ajax({
url: "user_change_password.php",
type: "POST",
data: $(this).serialize(),
success: function (response) {
alert(response.trim());
$("#changePasswordModal").modal("hide");
$("#changePasswordForm")[0].reset();
},
error: function (xhr) {
console.error("AJAX Error:", xhr.responseText);
alert("Error processing request.");
}
});
});
// ✅ Redeem Points
$(document).on("click", ".redeem-points-btn", function () {
let userId = $(this).data("id");
if (confirm("Are you sure you want to redeem points?")) {
$.post("redeem_points.php", { id: userId }, function (response) {
alert(response.trim());
location.reload();
});
}
});
// ✅ Update Project Status (AJAX)
$(document).on("click", ".update-status-btn", function () {
let projectId = $(this).data("id");
let projectName = $(this).data("name");
let status = $(this).data("status");
$("#project_id").val(projectId);
$("#project_name").val(projectName);
$("#new_status").val(status);
$("#updateStatusModal").modal("show");
});
// ✅ Submit Update Status Form
$("#updateStatusForm").submit(function (e) {
e.preventDefault();
$.ajax({
url: "update_status.php",
type: "POST",
data: $(this).serialize(),
dataType: "json",
success: function (response) {
if (response.success) {
alert(response.message);
$("#updateStatusModal").modal("hide");
location.reload();
} else {
alert("Error: " + response.message);
}
},
error: function () {
alert("AJAX request failed.");
}
});
});
// ✅ Mark Project as Complete
$(document).on("click", ".mark-complete-btn", function () {
let projectId = $(this).data("id");
$.ajax({
url: "complete_project.php",
type: "POST",
data: { project_id: projectId },
dataType: "json",
success: function (response) {
if (response.success) {
alert(response.message);
location.reload();
} else {
alert("Error: " + response.message);
}
},
error: function () {
alert("AJAX request failed.");
}
});
});
// ✅ Open Edit Project Modal & Populate Fields
$(document).on("click", ".edit-project-btn", function () {
let projectId = $(this).data("id");
let projectName = $(this).data("name") || '';
let status = $(this).data("status") || 'Project Started';
let points = $(this).data("points") || 0;
let assignedUserId = $(this).data("assigned-user");
$("#editProjectId").val(projectId);
$("#editProjectName").val(projectName);
$("#editStatus").val(status);
$("#editPoints").val(points);
// Ensure Assigned User is selected properly
$("#editAssignedUser option").each(function () {
$(this).prop("selected", $(this).val() == assignedUserId);
});
$("#editProjectModal").modal("show");
});
});