Skip to content

Commit

Permalink
added update clearance status for staff
Browse files Browse the repository at this point in the history
  • Loading branch information
nati-m-afw committed Feb 28, 2021
1 parent 4caf6d5 commit 8c40173
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 49 deletions.
94 changes: 86 additions & 8 deletions assets/js/requests.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
var editBtn


function displayClearanceRequests(){
console.log(tableBody.firstElementChild);
while (tableBody.firstElementChild){
tableBody.removeChild(tableBody.firstChild);
}

let transaction = db.transaction(['clearanceOS'], 'readwrite');
let objectStore = transaction.objectStore('clearanceOS');
let requestingStudents = []

let requestingStudents = {}
let emptyCheck = true

objectStore.openCursor().onsuccess = e => {
let cursor = e.target.result;

if(cursor){
if(cursor.value.deptId == currentDept){
requestingStudents.push(cursor.value.studentId)
emptyCheck = false
requestingStudents[cursor.value.studentId] = cursor.value.status
let transactionStudentOS = db.transaction(['studentOS'], 'readwrite');
let studentOS = transactionStudentOS.objectStore('studentOS');

for (const requestingStudentId of requestingStudents){
for (const requestingStudentId in requestingStudents){
let request = studentOS.get(requestingStudentId)

request.onerror = function(e){
Expand All @@ -32,15 +36,16 @@ function displayClearanceRequests(){
const lastNameColumn = document.createElement('td');
const deptColumn = document.createElement('td');
const phoneColumn = document.createElement('td');
const statusColumn = document.createElement('td');
const editColumn = document.createElement('td');
// const dateLoanedColumn = document.createElement('td');

// tableRow.appendChild(idColumn);
tableRow.appendChild(studentIdColumn);
tableRow.appendChild(firstNameColumn);
tableRow.appendChild(lastNameColumn);
tableRow.appendChild(deptColumn);
tableRow.appendChild(phoneColumn);
tableRow.appendChild(statusColumn);
tableRow.appendChild(editColumn);

tableBody.appendChild(tableRow);
Expand All @@ -49,14 +54,87 @@ function displayClearanceRequests(){
lastNameColumn.textContent = request.result.lastName;
// deptColumn.textContent = cursor.value.department;
phoneColumn.textContent = request.result.phone;
// editColumn.i
statusColumn.innerHTML = requestingStudents[requestingStudentId] == 'cleared' ? '<i class="fas fa-check-circle" style="color:green"></i>' : '<i class="fas fa-times-circle" style="color:red"></i>';
editColumn.innerHTML = `<i class="fas fa-edit" style="cursor:pointer" data-toggle="modal" data-target="#exampleModal"></i>`;



}
}
}
cursor.continue()
}
else if(!emptyCheck){
editBtn = document.querySelector('.fa-edit')
editBtn.addEventListener('click', getClearanceModal)
}
}

}

function getClearanceModal(){
const updateBtn = document.querySelector('#updateClearanceStatusButton')
updateBtn.addEventListener('click', updateClearanceStatus)
document.querySelector('#modalId').textContent = editBtn.parentElement.parentElement.firstElementChild.textContent
}

function updateClearanceStatus(){
const clearedRadioBtn = document.querySelector('.form-check-input-cleared')
const rejectedRadioBtn = document.querySelector('.form-check-input-rejected')
const descriptionTextArea = document.querySelector('.form-control-description')
const studentId = editBtn.parentElement.parentElement.firstElementChild.textContent

let transaction = db.transaction(['clearanceOS'], 'readwrite');
let objectStore = transaction.objectStore('clearanceOS');
let clearanceRequestId

objectStore.openCursor().onsuccess = e => {
let cursor = e.target.result;

if(cursor){
if(cursor.value.studentId == studentId && cursor.value.deptId == currentDept){
clearanceRequestId = cursor.value.requestId

// Get the to-do list object that has this title as it's title
const objectStoreTitleRequest = objectStore.get(clearanceRequestId);

if (clearedRadioBtn.checked){
console.log('cleared');
objectStoreTitleRequest.onsuccess = () => {
const data = objectStoreTitleRequest.result;
data.status = "cleared";
data.description = '';
const updateTitleRequest = objectStore.put(data);

updateTitleRequest.onsuccess = () => {
console.log('Successfully updated clearance request');
displayClearanceRequests();
};
};
}
else if(rejectedRadioBtn.checked){
console.log('rejected');
objectStoreTitleRequest.onsuccess = () => {
const data = objectStoreTitleRequest.result;
data.status = "rejected";
data.description = descriptionTextArea.value;
const updateTitleRequest = objectStore.put(data);

updateTitleRequest.onsuccess = () => {
console.log('Successfully updated clearance request');
displayClearanceRequests();
};
};
}
}
cursor.continue()
}
}
}

function toggleDescription(){
if (document.getElementById('inlineRadio2').checked)
document.getElementById('rejDesc').style.display = 'block'
else if (document.getElementById('inlineRadio1').checked)
document.getElementById('rejDesc').style.display = 'none'

}
8 changes: 4 additions & 4 deletions assets/js/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,22 +441,22 @@ function displayClearanceStatus(){
switch (cursor.value.deptId) {
case 'lib':
// add show description for failed clearances
cursor.value.status ? libStatusIcon.className = 'fas fa-user-clock fa-5x text-success' : libStatusIcon.className = 'fas fa-user-clock fa-5x text-secondary'
cursor.value.status == 'cleared' ? libStatusIcon.className = 'fas fa-user-clock fa-5x text-success' : libStatusIcon.className = 'fas fa-user-clock fa-5x text-secondary'
document.getElementById('lib').disabled = true
document.getElementById('lib').className = 'btn btn-secondary mb-2 disabled'
break;
case 'sps':
cursor.value.status ? spsStatusIcon.className = 'fas fa-user-clock fa-5x text-success' : spsStatusIcon.className = 'fas fa-user-clock fa-5x text-secondary'
cursor.value.status == 'cleared' ? spsStatusIcon.className = 'fas fa-user-clock fa-5x text-success' : spsStatusIcon.className = 'fas fa-user-clock fa-5x text-secondary'
document.getElementById('sps').disabled = true
document.getElementById('sps').className = 'btn btn-secondary mb-2 disabled'
break;
case 'dep':
cursor.value.status ? dptStatusIcon.className = 'fas fa-user-clock fa-5x text-success' : dptStatusIcon.className = 'fas fa-user-clock fa-5x text-secondary'
cursor.value.status == 'cleared' ? dptStatusIcon.className = 'fas fa-user-clock fa-5x text-success' : dptStatusIcon.className = 'fas fa-user-clock fa-5x text-secondary'
document.getElementById('dep').disabled = true
document.getElementById('dep').className = 'btn btn-secondary mb-2 disabled'
break;
case 'drm':
cursor.value.status ? drmStatusIcon.className = 'fas fa-user-clock fa-5x text-success' : drmStatusIcon.className = 'fas fa-user-clock fa-5x text-secondary'
cursor.value.status == 'cleared' ? drmStatusIcon.className = 'fas fa-user-clock fa-5x text-success' : drmStatusIcon.className = 'fas fa-user-clock fa-5x text-secondary'
document.getElementById('drm').disabled = true
document.getElementById('drm').className = 'btn btn-secondary mb-2 disabled'
break;
Expand Down
53 changes: 16 additions & 37 deletions requests.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ <h3 class="heading my-5">AAIT Clearance System</h3>
<th scope="col">Last</th>
<th scope="col">Department</th>
<th scope="col">Phone Number</th>
<th scope="col">Status</th>
<th scope="col"></th>
</tr>
</thead>
Expand All @@ -116,52 +117,30 @@ <h3 class="heading my-5">AAIT Clearance System</h3>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header mx-3">
<h5 class="modal-title" id="exampleModalLabel">Record a Loan</h5>
<h5 class="modal-title" id="exampleModalLabel">Update Clearance Status</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body mx-3">
<div class="modal-body mx-3">
<form class="add-record-form">
<div class="form-group">
<input type="text" class="form-control" id="firstName" placeholder="First Name"
required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="lastName" placeholder="Last Name" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="studentId" placeholder="ID" required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="phone" placeholder="Phone No." required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="department" placeholder="Department"
required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="bookTitle" placeholder="Book Title"
required>
</div>
<div class="form-group">
<label for="start" id="bd">Loan date:</label>
<input type="date" id="dateLoaned" name="trip-start" value="2021-02-03" min="2018-01-01"
max="2021-12-31" required>
</div>


<!-- <div class="form-group">
<label for="start" id="rd">Return date:</label>
<input type="date" id="start" name="trip-start" value="2021-02-03" min="2018-01-01"
max="2021-12-31" required>
</div> -->
</form>
<h5 class="mb-4" id="modalId"></h5>
<div class="form-check form-check-inline">
<input class="form-check-input form-check-input-cleared" onchange="toggleDescription()" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="cleared">
<label class="form-check-label" for="inlineRadio1">Cleared</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input form-check-input-rejected" onchange="toggleDescription()" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="rejected">
<label class="form-check-label" for="inlineRadio2">Rejected</label>
</div>
<div class="form-group mt-4" id="rejDesc" style="display: none;">
<label for="exampleFormControlTextarea1">Description</label>
<textarea class="form-control form-control-description" id="exampleFormControlTextarea1" rows="3"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="addRecordButton"> Loan</button>
<button type="submit" class="btn btn-primary" id="updateClearanceStatusButton"> Update</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 8c40173

Please sign in to comment.