Skip to content

Commit

Permalink
Admin PIREP Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
velocity23 committed Aug 9, 2021
1 parent 5f55f2c commit fc3835f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
77 changes: 74 additions & 3 deletions themes/default/views/admin/pireps.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@

<!-- Edit PIREP Modal -->
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" id="editpirep-modal">
<div class="modal-dialog modal-lg">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit PIREP</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form action="/admin/pireps" method="post">
<div class="text-left modal-body row">
<form action="/admin/pireps" method="post" class="mb-4 col-xl mb-xl-0">
<h4>PIREP Details</h4>
<input hidden name="action" value="editpirep">
<input hidden name="id" id="editpirep-id">
<div class="form-group">
Expand Down Expand Up @@ -252,6 +253,22 @@ function reverseFormatFlightTime() {
</div>
<input type="submit" class="btn bg-custom" value="Save">
</form>
<div class="col-xl">
<h4>PIREP Comments</h4>
<div id="editpirep-comments" class="mb-3">
<div class="text-center">
<div class="spinner-border spinner-border-sm spinner-custom" style="height: 30px; width: 30px;"></div>
</div>
</div>
<form id="editpirep-comments-form" class="form-inline d-flex">
<div style="flex: 1 1 0%;" class="pr-1">
<label class="sr-only" for="editpirep-comments-form-input">Name</label>
<input type="text" class="mb-2 form-control mr-sm-2 w-100" id="editpirep-comments-form-input" placeholder="Add Comment...">
</div>

<button type="submit" class="mb-2 btn bg-custom" style="flex: none;">Send</button>
</form>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -281,7 +298,10 @@ function reverseFormatFlightTime() {
$("#editpirep-ftime-mins").val(mins);
formatFlightTime();
$("#editpirep-modal").modal('show');

fetchComments(pirep.id);
});

$(".delpirepbtn").click(function() {
var conf = confirm('Are you sure you want to PERMANETLY delete this PIREP?');
if (!conf) return;
Expand All @@ -290,6 +310,57 @@ function reverseFormatFlightTime() {
$("#delpirep-id").val(id);
$("#delpirep").submit();
});

$("#editpirep-comments-form").submit(function(e) {
e.preventDefault();

var id = $("#editpirep-id").val();
if (!id) return;

$.post(`/api.php/pireps/${encodeURIComponent(id)}/comments`, {
content: $("#editpirep-comments-form-input").val(),
}, function(_, status) {
if (status != 'success') {
alert('Failed to add comment');
return;
}

$("#editpirep-comments-form-input").val('');
$("#editpirep-comments").html(`
<div class="text-center">
<div class="spinner-border spinner-border-sm spinner-custom" style="height: 30px; width: 30px;"></div>
</div>
`);
fetchComments(id);
});
});

$("#editpirep-modal").on('hidden.bs.modal', function() {
$("#editpirep-comments").html(`
<div class="text-center">
<div class="spinner-border spinner-border-sm spinner-custom" style="height: 30px; width: 30px;"></div>
</div>
`);
});

function fetchComments(pirepid) {
$.getJSON(`/api.php/pireps/${encodeURIComponent(pirepid)}/comments`, function(result) {
result = result.result;
$("#editpirep-comments").html('');
for (const c of result) {
$("#editpirep-comments").append(`
<div id="pirepmodal-comment-${c.id}" class="mb-1 d-flex">
<span style="flex: 1 1 0%;">
<b>${c.userName}:</b> ${c.content}
</span>
<span class="text-sm text-muted" style="flex: none;">
<small>${new Date(`${c.dateposted}Z`).toLocaleString()}</small>
</span>
</div>
`);
}
});
}
</script>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,8 @@
"assets/js/tailwind.js",
"assets/tailwind.index.css",
"themes/tailwind/views/pireps_view.php",
"classes/data/Notifications.php"
"classes/data/Notifications.php",
"themes/default/views/admin/pireps.php"
],
"queries": [
"CREATE TABLE `awards` ( `id` INT NOT NULL AUTO_INCREMENT , `name` TEXT NOT NULL , `description` TEXT NOT NULL , `imageurl` TEXT NOT NULL , PRIMARY KEY (`id`));",
Expand Down

0 comments on commit fc3835f

Please sign in to comment.