Skip to content

Commit

Permalink
fixed update button's error
Browse files Browse the repository at this point in the history
  • Loading branch information
nati-m-afw committed Mar 4, 2021
1 parent c774369 commit 070e1b0
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 51 deletions.
6 changes: 3 additions & 3 deletions assets/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ onload = function (){
// Admin can add new staff here
let newRecord = {

'firstName' : 'Keke',
'lastName' : 'B',
'firstName' : 'Sports GUY',
'lastName' : '101',
// studentId must be unique
'studentId' : 'TT/00/01',
'studentId' : 'TT/00/11',
'password' : 'add',
'phone' : 0911445566,
};
Expand Down
95 changes: 51 additions & 44 deletions assets/js/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,73 @@ function displayClearanceRequests(){
if(cursor.value.deptId == currentDept){
emptyCheck = false
requestingStudents[cursor.value.studentId] = cursor.value.status
let transactionStudentOS = db.transaction(['studentOS'], 'readwrite');
let studentOS = transactionStudentOS.objectStore('studentOS');

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

request.onerror = function(e){
console.log('Cannot access data of student ' + requestingStudentId);
}

request.onsuccess = function(e){
const tableRow = document.createElement('tr');
// const idColumn = document.createElement('th');
const studentIdColumn = document.createElement('td');
const firstNameColumn = document.createElement('td');
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');

// 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);
studentIdColumn.textContent = request.result.studentId;
firstNameColumn.textContent = request.result.firstName;
lastNameColumn.textContent = request.result.lastName;
// deptColumn.textContent = cursor.value.department;
phoneColumn.textContent = request.result.phone;
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()
}
// when the cursor finishes
else if(!emptyCheck){
editBtn = document.querySelector('.fa-edit')
editBtn.addEventListener('click', getClearanceModal)


let transactionStudentOS = db.transaction(['studentOS'], 'readwrite');
let studentOS = transactionStudentOS.objectStore('studentOS');

console.log(requestingStudents);
for (const requestingStudentId in requestingStudents){
let request = studentOS.get(requestingStudentId)

request.onerror = function(e){
console.log('Cannot access data of student ' + requestingStudentId);
}

request.onsuccess = function(e){
const tableRow = document.createElement('tr');
// const idColumn = document.createElement('th');
const studentIdColumn = document.createElement('td');
const firstNameColumn = document.createElement('td');
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');

// 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);

studentIdColumn.textContent = request.result.studentId;
firstNameColumn.textContent = request.result.firstName;
lastNameColumn.textContent = request.result.lastName;
// deptColumn.textContent = cursor.value.department;
phoneColumn.textContent = request.result.phone;
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>`;

// ATTACH event listner for latest update button
editBtnNodeList = document.querySelectorAll('.fa-edit')
editBtn = editBtnNodeList[editBtnNodeList.length - 1]
editBtn.addEventListener('click', getClearanceModal)
}
}
}
}

}

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

function updateClearanceStatus(){
console.log('uuuu');
const clearedRadioBtn = document.querySelector('.form-check-input-cleared')
const rejectedRadioBtn = document.querySelector('.form-check-input-rejected')
const descriptionTextArea = document.querySelector('.form-control-description')
Expand Down
63 changes: 61 additions & 2 deletions assets/js/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const libStatusIcon = document.querySelector('#libStatusIcon')
const spsStatusIcon = document.querySelector('#spsStatusIcon')
const dptStatusIcon = document.querySelector('#dptStatusIcon')
const drmStatusIcon = document.querySelector('#drmStatusIcon')
const clsStatusIcon = document.querySelector('#clsStatusIcon')

try {
newLoanButton. addEventListener('click', getForm);
Expand Down Expand Up @@ -406,12 +407,19 @@ objectStore.openCursor().onsuccess= function(e){

// ADD CLEARANCE REQUEST
for (const btn of clearanceRequestBtn) {
btn.addEventListener('click', addClearanceRequest)
if(btn.id != 'cls'){
btn.addEventListener('click', addClearanceRequest)
}
else{
btn.addEventListener('click', addClearanceRequestCleareanceDept)
}
}
function addClearanceRequest(e){
let newRecord = {
studentId : urlSearchParams.get('id'),
deptId : e.target.id
deptId : e.target.id,
status : "",
description : ""
}

let transaction = db.transaction(['clearanceOS'], 'readwrite');
Expand All @@ -436,6 +444,39 @@ function addClearanceRequest(e){

}

function addClearanceRequestCleareanceDept(e){
let newRecord = {
studentId : urlSearchParams.get('id'),
deptId : e.target.id
}


if (e.target.id == 'cls'){
let allCleared = []

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

objectStore.openCursor().onsuccess = e => {
let cursor = e.target.result;
if(cursor){
if (cursor.value.studentId == urlSearchParams.get('id')){
allCleared = true
}
cursor.continue()
}
else if(allCleared.length != 4 || allCleared.includes('rejected')){
alert('You will have to get a successful clearance notice from all the other departments first!')
}
else{
console.log('successfully added to clear');
}
}
}


}

function displayClearanceStatus(){
let transaction = db.transaction(['clearanceOS'], 'readwrite');
let objectStore = transaction.objectStore('clearanceOS');
Expand Down Expand Up @@ -519,6 +560,24 @@ function displayClearanceStatus(){
document.getElementById('drm').className = 'btn btn-secondary mb-2 disabled'
break;

// Dorm Display
case 'cls':
if (cursor.value.status == 'cleared'){
clsStatusIcon.className = 'fas fa-check-circle fa-5x text-success'
}
else if (cursor.value.status == 'rejected'){
clsStatusIcon.className = 'fas fa-times-circle fa-5x text-danger'
clsStatusIcon.parentElement.parentElement.firstElementChild.children[3].hidden = false
clsStatusIcon.parentElement.parentElement.firstElementChild.children[3].textContent += ` "${cursor.value.description}"`
clsStatusIcon.parentElement.parentElement.firstElementChild.children[4].hidden = false
}
else {
clsStatusIcon.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;

default:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions students.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ <h3 class="heading my-5">AAIT Clearance System</h3>
<div class="card-body">
<div class="row">
<div class="col-md-6 mb-2">
<button class="btn btn-primary mb-2 disabled" id="drm">Request Clearance</button>
<button class="btn btn-primary mb-2 disabled" id="cls">Request Clearance</button>
<p class="card-text">Request Date: </p>
<p class="card-text">Response Date: </p>
<p class="card-text" hidden>Description: </p>
<p class="card-text text-danger" hidden>Report to department office!</p>
</div>
<div class="col-md-6 text-center align-self-center">
<i class="fas fa-exclamation-triangle fa-5x text-danger" id="drmStatusIcon"></i>
<i class="fas fa-exclamation-triangle fa-5x text-danger" id="clsStatusIcon"></i>
</div>
</div>
</div>
Expand Down

0 comments on commit 070e1b0

Please sign in to comment.