-
Notifications
You must be signed in to change notification settings - Fork 0
/
assign_task.js
103 lines (74 loc) · 3 KB
/
assign_task.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
document.addEventListener("DOMContentLoaded", function() {
var sidebarLinks = document.querySelectorAll('.sidebar a');
var contentContainers = document.querySelectorAll('.content-container');
sidebarLinks.forEach(function(link) {
link.addEventListener('click', function(event) {
event.preventDefault();
var targetId = this.getAttribute('data-target');
contentContainers.forEach(function(container) {
container.classList.remove('active');
});
document.getElementById(targetId).classList.add('active');
});
});
});
document.addEventListener("DOMContentLoaded", function() {
function populateDropdowns(users) {
var assigneeDropdown = document.getElementById('assignee');
users.forEach(user => {
var option = document.createElement('option');
option.value = user.email;
option.textContent = user.name;
var cloneOption = option.cloneNode(true);
assigneeDropdown.appendChild(cloneOption);
});
}
fetch('assign_task.php')
.then(response => response.json())
.then(data => populateDropdowns(data))
.catch(error => console.error('Error fetching users:', error));
});
//group
window.onload = function() {
fetch('fetch_assignees.php')
.then(response => response.json())
.then(data => {
const assigneesDropdown = document.getElementById('assignees');
data.forEach(user => {
const option = document.createElement('option');
option.value = user.email;
option.text = user.name;
assigneesDropdown.appendChild(option);
});
});
}
let addedAssignees = [];
function addAssignee() {
const assigneesContainer = document.getElementById('assigneesContainer');
const assigneesDropdown = document.createElement('select');
assigneesDropdown.name = 'assignees[]';
assigneesDropdown.required = true;
fetch('fetch_assignees.php')
.then(response => response.json())
.then(data => {
let addedAssignees = [];
const existingAssignees = assigneesContainer.querySelectorAll('select');
existingAssignees.forEach(select => {
addedAssignees.push(select.value);
});
data.forEach(user => {
if (!addedAssignees.includes(user.email)) {
const option = document.createElement('option');
option.value = user.email;
option.text = user.name;
assigneesDropdown.appendChild(option);
}
});
if (assigneesDropdown.childElementCount > 0) {
assigneesContainer.appendChild(assigneesDropdown);
assigneesContainer.appendChild(document.createElement('br'));
} else {
alert('No new assignees to add.');
}
});
}