-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.js
176 lines (152 loc) · 5.49 KB
/
Queue.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
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
class Queue
{
constructor(id, chkDefault, name, chkOutOrderAcc, chkWorkQueue,
chkAmendReq, chkBalMode, desc, permits, envelopes, statuses)
{
this.id = id;
this.chkDefault = chkDefault;
this.name = name;
this.chkOutOrderAcc = chkOutOrderAcc;
this.chkWorkQueue = chkWorkQueue;
this.chkAmendReq = chkAmendReq;
this.chkBalMode = chkBalMode;
this.desc = desc;
this.permits = permits;
this.envelopes = envelopes;
this.statuses = statuses;
}
}
class QueueManager
{
static queueCount = 0;
static buttonPathLen = 3;
static displayQueues()
{
QueueManager.clearQueues();
const queues = Store.getQueues();
QueueManager.queueCount = 0;
queues.forEach((queue) => QueueManager.addQueueToList(queue));
}
static clearQueues()
{
document.querySelector('#queue-list').innerHTML = '';
}
static addQueueToList(queue)
{
QueueManager.queueCount++;
const list = document.querySelector('#queue-list');
const row = document.createElement('tr');
row.innerHTML = `
<td>${queue.chkDefault ? checkSvg : ''}</td>
<td class="w-75">${queue.name}</td>
<td>${queue.permits.length > 0 ? checkSvg : ''}</td>
<td>${queue.envelopes.length > 0 ? checkSvg : ''}</td>
<td>${queue.statuses.length > 0 ? checkSvg : ''}</td>
<td>${queue.chkAmendReq ? checkSvg : ''}</td>
<td>
<a class="btn btn-secondary btn-sm edit" data-bs-toggle="modal" data-bs-target="#addEditModal">
${editButtonSvg}
</a>
</td>
<td><a class="btn btn-danger btn-sm delete">${deleteButtonSvg}</a></td>
<td>
<ul class="proc-order-ul ">
<li class="btn btn-primary btn-sm arrow-btn down-arrow">${downButtonSvg}</li>
<li class="btn btn-primary btn-sm arrow-btn up-arrow">${upButtonSvg}</li>
<li class="q-n">${QueueManager.queueCount}</li>
</ul
</td>
`;
row.dataset['id'] = queue.id;
list.appendChild(row);
}
// This will populate the edit queue modal
// the HTML will take care of actually opening the modal
static populateEditQueue(el)
{
// we come here from an event handler placed on the queue list
// so, we first verify that the edit button was clicked
let id = QueueManager.searchForRowId(el, 'edit');
if (id === null)
{
return false; // queue-list was clicked, but edit was not
}
const queue = Store.getQueue(id);
// Populate elements in edit queue modal
const queueForm = document.querySelector("#queue-form");
queueForm.querySelector('#qId').value = queue.id;
queueForm.querySelector('#chkDefault').checked = queue.chkDefault;
queueForm.querySelector('#qName').value = queue.name;
queueForm.querySelector('#chkOutOrderAcc').checked = queue.chkOutOrderAcc;
queueForm.querySelector('#chkWorkQueue').checked = queue.chkWorkQueue;
queueForm.querySelector('#chkAmendReq').checked = queue.chkAmendReq;
queueForm.querySelector('#chkBalMode').checked = queue.chkBalMode;
queueForm.querySelector('#qDesc').value = queue.desc;
// Populate Permits table
PermitManager.populatePermits(queue.permits);
// Populate Envelopes table
EnvelopeManager.populateEnvelopes(queue.envelopes);
// Populate Statuses table
StatusManager.populateStatuses(queue.statuses);
return true;
}
static deleteQueue(el)
{
let id = QueueManager.searchForRowId(el, 'delete');
if (id !== null) // null id, means we didn't hit delete
{
Store.removeQueue(id);
QueueManager.displayQueues();
return true;
}
return false;
}
static moveUpDownQueue(el)
{
let id = QueueManager.searchForRowId(el, 'up-arrow');
if (id !== null) // null id, means we didn't hit up arrow
{
// move current queue up
Store.moveQueue(id, -1);
QueueManager.displayQueues();
return true;
}
id = QueueManager.searchForRowId(el, 'down-arrow');
if (id !== null) // null id, means we didn't hit down arrow
{
Store.moveQueue(id, 1);
QueueManager.displayQueues();
return true;
}
return false;
}
static searchForRowId(el, searchClass)
{
// walk up parents to find the row and get the id
let elem = el;
for (let i = 0; i < QueueManager.buttonPathLen; ++i)
{
if (elem.classList.contains(searchClass))
{
// we found what we were looking for
// now click up until reaching the row
while (true)
{
if (elem.tagName === 'TR')
{
return elem.dataset['id'];
}
else
{
elem = elem.parentElement;
}
}
}
else
{
elem = elem.parentElement;
}
}
return null;
}
}