Skip to content

Commit

Permalink
Add notification verification and cancel booking confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
Pancham1603 committed Dec 8, 2023
1 parent e7fb325 commit 09ed4af
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
73 changes: 46 additions & 27 deletions apps/nightpass/templates/lmao.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ <h2 id="modal-resource-name"></h2>
</div>
</div>

<script>
function verifyNotification(notif_text) {
let text = notif_text;
if (confirm(text) == true) {
return true;
} else {
return false;
}
}
</script>

<script>
toastr.options = {
"closeButton": false,
Expand All @@ -138,6 +149,11 @@ <h2 id="modal-resource-name"></h2>
"hideMethod": "fadeOut"
}

function closeModal() {
var modal = document.getElementById("myModal");
modal.style.display = "none";
}

function openModal(name, description, picture, book) {
var modal = document.getElementById("myModal");
modal.style.display = "block";
Expand All @@ -148,42 +164,45 @@ <h2 id="modal-resource-name"></h2>
if (book) {
document.getElementById('modal-resource-book').innerHTML = 'Book';
var urls = "book/" + name;
var notif_text = "Make sure you you use your slot else cancel before 8:00 PM. Not showing up at the location will lead to a defaulter record.";
} else {
document.getElementById('modal-resource-book').innerHTML = 'Cancel Booking'
var urls = "cancel/";
var notif_text = "Are you sure you want to cancel your booking?";
}

document.getElementById('modal-resource-book').onclick = function() {
$.ajax({
method: "POST",
url: urls,
timeout: 120000,
success: function (response) {
let res = JSON.parse(response).status;
if (res) {
console.log(JSON.parse(response))
let qr = JSON.parse(response).pass_qr
document.getElementById('modal-resource-picture').src = qr
document.getElementById('modal-resource-book').classList.add("modal-resource-booked");
toastr.success(JSON.parse(response).message);
setTimeout(function(){ location.reload(); }, 3000);
//location.reload();
}
else {
toastr.error(JSON.parse(response).message);
}
},
error: function (xhr, textStatus, errorThrown) {
toastr.error("Something went wrong, please try again later");
document.getElementById('modal-resource-book').onclick = function() {

if (!verifyNotification(notif_text)) {
closeModal();
} else {
$.ajax({
method: "POST",
url: urls,
timeout: 120000,
success: function (response) {
let res = JSON.parse(response).status;
if (res) {
console.log(JSON.parse(response))
let qr = JSON.parse(response).pass_qr
document.getElementById('modal-resource-picture').src = qr
document.getElementById('modal-resource-book').classList.add("modal-resource-booked");
toastr.success(JSON.parse(response).message);
setTimeout(function(){ location.reload(); }, 3000);
//location.reload();
}
else {
toastr.error(JSON.parse(response).message);
}
},
error: function (xhr, textStatus, errorThrown) {
toastr.error("Something went wrong, please try again later");
}
});
}
});
}
}

function closeModal() {
var modal = document.getElementById("myModal");
modal.style.display = "none";
}

</script>

Expand Down
1 change: 1 addition & 0 deletions apps/users/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class StudentAdmin(ImportExportModelAdmin):
autocomplete_fields = ('user',)
resource_class = StudentResource
readonly_fields = ('hostel_checkin_time', 'hostel_checkout_time', 'last_checkout_time',)
list_filter = ('hostel', 'has_booked', 'violation_flags')

class SecurityAdmin(admin.ModelAdmin):
list_display = ('name', 'admin_incharge', 'user')
Expand Down

0 comments on commit 09ed4af

Please sign in to comment.