Commit 37d6a4b1 authored by Deep Dey's avatar Deep Dey

feat: polish the ui-functionality and api integration for export features

parent 90614abe
......@@ -54,7 +54,7 @@
</div>
<div class="book-appointment-box">
<button id="bookAppointmentBtn" class="btn btn-primary btn-sm">Schedule Appointment</button>
<button class="btn btn-success btn-sm">Download Admission Data</button>
<button id="download-admission-data-btn" class="btn btn-success btn-sm">Download Admission Data</button>
</div>
</div>
......@@ -100,13 +100,33 @@
<label for="appointmentTime">Time</label>
<input type="time" class="form-control" id="appointmentTime" required />
</div>
<button type="submit" class="btn btn-primary">Book</button>
<div class="modal-footer p-0 pt-2 border-top-0">
<button type="submit" class="btn btn-primary submit-btn">Schedule</button>
<button class="btn btn-primary loading-btn" type="button" disabled>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
Loading...
</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal" tabindex="-1" role="dialog" id="messageModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body"></div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="js/constant.js"></script>
......
......@@ -20,7 +20,12 @@ $(document).ready(function () {
student.id +
'"></td>';
outputHtml += '<td>' + student.fullName + '</td>';
outputHtml += '<td>' + (student.interactionDate || '')+ ' ' + (student.interactionTime || '') + '</td>';
outputHtml +=
'<td>' +
(student.interactionDate || '') +
' ' +
(student.interactionTime || '') +
'</td>';
outputHtml += '<td>' + student.fatherName + '</td>';
outputHtml += '<td>' + student.motherName + '</td>';
outputHtml += '</tr>';
......@@ -82,6 +87,17 @@ $(document).ready(function () {
});
}
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
// Apply filters button click event
$('#applyFilters').click(function () {
var schoolFilter = $('#schoolFilter').val();
......@@ -98,14 +114,14 @@ $(document).ready(function () {
getAdmissionData(null, null, null, null);
});
// Select all checkbox click event
$('#selectAll').click(function () {
if ($(this).is(':checked')) {
$('.student-checkbox').prop('checked', true);
} else {
$('.student-checkbox').prop('checked', false);
}
});
// Select all checkbox click event
$('#selectAll').click(function () {
if ($(this).is(':checked')) {
$('.student-checkbox').prop('checked', true);
} else {
$('.student-checkbox').prop('checked', false);
}
});
// Book appointment button click event
$('#bookAppointmentBtn').click(function () {
......@@ -113,23 +129,86 @@ $(document).ready(function () {
$('.student-checkbox:checked').each(function () {
checkedValues.push($(this).data('id'));
});
console.log(checkedValues);
$('#studentIdForAppointment').val(checkedValues.toString());
$('#appointmentModal').modal('show');
$('.loading-btn').hide();
});
// Appointment form submission event
$('#appointmentForm').submit(function (event) {
event.preventDefault();
var studentId = $('#studentIdForAppointment').val();
var formIds = $('#studentIdForAppointment').val();
var appointmentDate = $('#appointmentDate').val();
var appointmentTime = $('#appointmentTime').val();
console.log('Booking Appointment for Student ID:', studentId);
console.log('Appointment Date:', appointmentDate);
console.log('Appointment Time:', appointmentTime);
// Perform further actions here like sending data to the backend
$('#appointmentModal').modal('hide');
alert('Appointment booked successfully for Student ID: ' + studentId);
var selectedDateTime = new Date(
appointmentDate + 'T' + appointmentTime
);
if (!formIds) {
$('#appointmentModal').modal('hide');
$('#messageModal .modal-title').text('Error');
$('#messageModal .modal-body').text(
'Please select at least one form to schedule an appointment.'
);
$('#messageModal').modal('show');
return;
}
$('.submit-btn').hide();
$('.loading-btn').show();
$.ajax({
url: BASE_URL_LAMARTIN + '/admission-form/set-interview',
type: 'GET',
contentType: 'application/json',
dataType: 'json',
headers: {
apikey: loginData.apiKey,
},
data: {
formIds: formIds,
interactionDate: appointmentDate,
interactionTime: formatAMPM(selectedDateTime),
},
success: function (response) {
window.location.reload();
},
error: function (error) {
if (error.responseJSON && error.responseJSON.message) {
$('#messageModal .modal-body').text(
error.responseJSON.message
);
} else {
$('#messageModal .modal-body').text(
'An unexpected error occurred. Please try again.'
);
}
$('#appointmentModal').modal('hide');
$('#messageModal .modal-title').text('Error');
$('#messageModal').modal('show');
},
});
});
$('#download-admission-data-btn').click(function () {
var checkedValues = [];
$('.student-checkbox:checked').each(function () {
checkedValues.push($(this).data('id'));
});
window
.open(
BASE_URL_LAMARTIN +
`/admission-form/download-form?apikey=${
loginData.apiKey
}&formIds=${checkedValues.toString()}`,
'_blank'
)
.focus();
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Datetime Picker</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<input type="date" id="datePicker">
<input type="time" id="timePicker">
<button id="logDatetime">Log Datetime</button>
<div id="result"></div>
<script>
function formatAMPM(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var ampm = hours >= 12 ? 'PM' : 'AM';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
return strTime;
}
$(document).ready(function() {
$('#logDatetime').click(function() {
var date = $('#datePicker').val();
var time = $('#timePicker').val();
if (!date || !time) {
alert('Please select both date and time.');
return;
}
var selectedDateTime = new Date(date + 'T' + time);
var formattedDateTime = date + 'T' + formatAMPM(selectedDateTime);
//TODO: send date and formatAMPM(selectedDateTime) to the backend
$('#result').text(formatAMPM(selectedDateTime));
console.log(formattedDateTime);
});
});
</script>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment