Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
1.8 kB
2
Indexable
Never
function openSubjectModal(subject, teacher_id, class_id) {
            var modal = document.getElementById('subject-grades-modal');
            modal.style.opacity = "0";
            modal.classList.remove('hidden');
            document.getElementById('subjectTitle_Modal').innerText = subject;
            document.getElementById('subjectTeacher_Modal').value = teacher_id;

            // Fetch grades for the subject and student
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function() {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    if (xhr.status === 200) {
                        var grades = JSON.parse(xhr.responseText);
                        document.getElementById('subjectGrade_Modal').value = grades.grade_value;
                        document.getElementById('subjectPercentage_Modal').value = grades.grade_percentage;
                        document.getElementById('subject-gradedAt_Modal').value = grades.grade_date;
                    } else {
                        // Handle the error case
                        console.error(xhr.status);
                    }
                }
            };
            xhr.open('GET', 'get_grades.php?subject=' + subject + '&student_id=' + <?php echo $_SESSION['id']; ?>, true);
            xhr.send();

            var fadeEffect = setInterval(function() {
                if (!modal.style.opacity) {
                    modal.style.opacity = 0;
                }
                if (modal.style.opacity < 1) {
                    modal.style.opacity = parseFloat(modal.style.opacity) + 0.1;
                } else {
                    clearInterval(fadeEffect);
                }
            }, 20);
        }